Hi,

I am having a problem with the below,basically what I'm trying to do is allow the user to enter upper case,lower case ,or alternating text ..like Cw888 or cW888 for example using or ...

it works fine for one command button,that is it displays the error message if the user enters an invalid course and then clears the textbox and sets focus on that textbox allowing the user to re enter the correct course,but for some reason after it clears the textbox..and i reenter a valid course it just keeps diplaying an invalid course error....

Could I use a loop on the below? ,after an invalid course is entered the message box pops up..the textbox clears,and then the setfocus kicks in..but then it should go back to to the true statements if a valid course is enter?

Private Sub cmdprocess_averageresult_Click()
 
 
    If txtvalidateaverage.Text = "cw888" Or txtvalidateaverage.Text = "CW888" Or txtvalidateaverage.Text = "cW888" Or txtvalidateaverage.Text = "Cw888" Then
        'true values
        lblaverageresultoncourse.Visible = True
        lblprocesseddatadisplayed.Caption = Math.Round(intAveragecw888 / intCountcw888)
        lblaverageresultoncourse.Caption = "Average Mark on course " & strCoursecw888
 
    ElseIf txtvalidateaverage.Text = "cw019" Or txtvalidateaverage.Text = "CW019" Or txtvalidateaverage.Text = "Cw019" Or txtvalidateaverage.Text = "cW019" Then
        'true values
        lblaverageresultoncourse.Visible = True
        lblprocesseddatadisplayed.Caption = Math.Round(intAveragecw019 / intCountcw019)
        lblaverageresultoncourse.Caption = "Average Mark on course " & strCoursecw019
 
 
    ElseIf txtvalidateaverage.Text = "cw046" Or txtvalidateaverage.Text = "CW046" Or txtvalidateaverage.Text = "Cw046" Or txtvalidateaverage.Text = "cW046" Then
        'true values
        lblaverageresultoncourse.Visible = True
        lblprocesseddatadisplayed.Caption = Math.Round(intAveragecw046 / intCountcw046)
        lblaverageresultoncourse.Caption = "Average Mark on course " & strCoursecw046
 
 
      ElseIf txtvalidatenumber.Text <> "CW888" Or txtvalidatenumber.Text <> "CW019" Or txtvalidatenumber.Text <> "CW046" Then
        'false value
        MsgBox "Course Does not exist"
        lblnumberofstudentsoncourse.Visible = False
        lblprocesseddatadisplayed.Caption = " "
        lblprocesseddatadisplayed.Visible = False
        txtvalidatenumber.setfocus
        txtvalidatenumber.Text = " "
 
 
End If
End Sub
 
Private Sub cmdprocess_numberofstudents_Click()
 
    If txtvalidatenumber.Text = "cw888" Or txtvalidatenumber.Text = "CW888" Or txtvalidatenumber.Text = "cW888" Or txtvalidatenumber.Text = "Cw888" Then
 
        lblnumberofstudentsoncourse.Visible = True
        lblprocesseddatadisplayed.Caption = intcw888studentcount
        lblnumberofstudentsoncourse.Caption = "Number of students on  course " & strCoursecw888
 
    ElseIf txtvalidatenumber.Text = "cw019" Or txtvalidatenumber.Text = "CW019" Or txtvalidatenumber.Text = "Cw019" Or txtvalidatenumber.Text = "cW019" Then
 
        lblnumberofstudentsoncourse.Visible = True
        lblnumberofstudentsoncourse.Caption = "Number of students on  course " & strCoursecw019
        lblprocesseddatadisplayed.Caption = intcw019studentcount
 
    ElseIf txtvalidatenumber.Text = "cw046" Or txtvalidatenumber.Text = "CW046" Or txtvalidatenumber.Text = "Cw046" Or txtvalidatenumber.Text = "cW046" Then
 
        lblnumberofstudentsoncourse.Visible = True
        lblnumberofstudentsoncourse.Caption = "Number of students on  course " & strCoursecw046
        lblprocesseddatadisplayed.Caption = intcw046studentcount
 
    ElseIf txtvalidatenumber.Text <> "CW888" Or txtvalidatenumber.Text <> "CW019" Or txtvalidatenumber.Text <> "CW046" Then
 
        MsgBox "Course Does not exist"
        lblnumberofstudentsoncourse.Visible = False
        lblprocesseddatadisplayed.Caption = " "
        lblprocesseddatadisplayed.Visible = False
        txtvalidatenumber.setfocus
        txtvalidatenumber.Text = " "
 
 
End If
End Sub
Private Sub cmdprocess_studentsoncourse_Click()
 
 
        strcw888namegroup = lststudentname.List(0) & vbCrLf & lststudentname.List(2) & vbCrLf & lststudentname.List(3) & vbCrLf & lststudentname.List(7) & vbCrLf & lststudentname.List(8) & vbCrLf & lststudentname.List(11)
        strcw046namegroup = lststudentname.List(9) & vbCrLf & lststudentname.List(12) & vbCrLf & lststudentname.List(17)
        strcw019namegroup = lststudentname.List(1) & vbCrLf & lststudentname.List(4) & vbCrLf & lststudentname.List(5) & vbCrLf & lststudentname.List(6) & vbCrLf & lststudentname.List(10) & vbCrLf & lststudentname.List(13) & vbCrLf & lststudentname.List(15)
 
 
    If txtvalidatenames.Text = "cw888" Or txtvalidatenames.Text = "CW888" Or txtvalidatenames.Text = "cW888" Or txtvalidatenames.Text = "Cw888" Then
 
        lblprocesseddatadisplayed.Caption = strcw888namegroup
        lblnamesoncoursetitle.Caption = "Names of students on course " & strCoursecw888
        lblnamesoncoursetitle.Visible = True
 
    ElseIf txtvalidatenames.Text = "cw019" Or txtvalidatenames.Text = "CW019" Or txtvalidatenames.Text = "Cw019" Or txtvalidatenames.Text = "cW019" Then
 
        lblnamesoncoursetitle.Caption = "Names of students on course " & strCoursecw019
        lblprocesseddatadisplayed.Caption = strcw019namegroup
        lblnamesoncoursetitle.Visible = True
 
    ElseIf txtvalidatenames.Text = "cw046" Or txtvalidatenames.Text = "CW046" Or txtvalidatenames.Text = "Cw046" Or txtvalidatenames.Text = "cW046" Then
 
        lblnamesoncoursetitle.Caption = "Names of students on course " & strCoursecw046
        lblprocesseddatadisplayed.Caption = strcw046namegroup
        lblnamesoncoursetitle.Visible = True
 
    ElseIf txtvalidatenames.Text <> "CW888" Or txtvalidatenames.Text <> "CW019" Or txtvalidatenames.Text <> "CW046" Then
 
         MsgBox "Course Does not exist"
         lblnamesoncoursetitle.Visible = False
         lblprocesseddatadisplayed.Caption = " "
         lblprocesseddatadisplayed.Visible = False
         txtvalidatenames.SetFocus
         txtvalidatenames.Text = ""
 
 
End If
End Sub

It would be really better if you posted the design of your relevant form along with the form elements name so that it would be easier for us to copy paste your code and try it out. Something like this :

[lbl_average]   [txt_average]
[lbl_total]        [txt_total]

[btn_calculate] [btn_exit]

BTW your code is so confusing and jumpled, that it is difficult to point out errors as such.

Be a bit more descriptive while describing your program and the errors you are facing along with the function which causes the error. What was the expected result etc etc...

Hi,

Why dont u allow user to enter in Uppercase.

Just Set Form's Key Preview Property =True And

Give this code in Form KeyPress Event.

Private Sub Form_KeyPress(KeyAscii As Integer)
    KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub

And Use Validate Event of TextBox to check Valid Entry, Instead of using SetFocus.

Regards
Veena

I agree the above code is very sloppy,and anyway its not acceptable according to my lecturer..

I'm using this instead :

Dim intIdx As Integer, intCount As Integer
Dim blnFound As Boolean
    'Capture the ListCount
    intCount = List1.ListCount - 1
    'Iterate the ListBox looking for a match
    For intIdx = 0 To intCount
        If LCase(Text1.Text) = LCase(List1.List(intIdx)) Then blnFound = True
    Next
    'Display the appropriate message
    If blnFound = True Then
        MsgBox "Item " & Text1.Text & " was found!", vbOKOnly + vbInformation
    Else
        MsgBox "Item " & Text1.Text & " was not found!", vbOKOnly + vbInformation
    End If

which basically compares the text entered in a textbox to the items in the listbox,and if an item is found then a message box says its found,if not it returns a not found message...


However I can't seem to count the number of times a particular item is found using the above method,once the blnFound = true I need to count using a variable...but my attempts have been unsuccessful...

Also I need a way to group student names to a particular course,so if cw888 is entered for example in a textbox,it loops throught the listbox and displays names related to cw888,but I'm no good on arrays.

thanks

Hi,

Why dont u allow user to enter in Uppercase.

Regards
Veena

Because the items in the listbox are in lowercase(take from a sequential text file),so I figured it'd be easier to carry out the true statement on a command button this way..

As far as keeping the count on the number of times the match is found, just declare your variable as static and it should work out to be fine. (The static quantifier helps the variable in maintaining its state, in the scope in which the variable is declared)

What is the part which you don't understand about arrays ? Can you give a short eg on how you plan on using the arrays and what would they be storing ?

thanks for your reply

this is probably not a great way of explaining it,,but lets says
my arrays are based on the following(taken from a sequential text file

Paul,cw888,46
Simon,cw019,65
Dorothy,cw888,89
Helena,cw888,56
Harry,cw019,34
Jane,cw019,43
Liam,cw019,76

so if they type in a textbox cw888 ,,,and hit a command button to process/display data,it shoud display ,paul,Dorothy,Helena (just for cw888)in a label or something

I havent actually coded anything array wise,because I've spent most of my time researching them,but havent gotten very far.

bare in mind i'm using three listboxes,one listbox for names,a listbox for coursecode and a listbox for exam results,all stored in three variables.

(edit) the sequential file will be altered when its been tested by my lecturer,I'm guessing if its possible to just say,,any names related to cw888,then group those names,regardless of locations.

Hi,

To Print the List of all the Matched Names, use this code:
Add One More ListBox on the Form Say lstMatch

Dim intIdx As Integer, intCount As Integer
Dim iPos Integer
Dim blnFound As Boolean
Dim sSQL As String
intCount = List1.ListCount - 1
[B]lstMatch[/B].Clear
For intIdx = 0 To intCount
    If LCase(Text1.Text) = LCase(List1.List(intIdx)) Then 
         blnFound = True
         sSQL =List1.List(intIdx)
         iPos = InStr(sSQL,",")
         If iPos>0 Then
              sSQL = Left(sSQL,(i-1))
          End If
         [B]lstMatch[/B].AddItem sSQL
    End If
Next
If blnFound = True Then
     MsgBox "Item " & Text1.Text & " was found!", vbOKOnly + vbInformation
 Else
     MsgBox "Item " & Text1.Text & " was not found!", vbOKOnly + vbInformation
 End If

In the Above Code, U need not Keep A Boolean Variable also, u can just check the ListCount of lstMatch.
If u r very particular to show in a Label, then u can build a String and then display that string in Label.

I hope it is clear,

Regards
Veena

Hi,

I noticed this after posting the code.
Sorry that was :

If iPos>0 Then
              sSQL = Left(sSQL,(iPos-1))
          End If

Veena

Hi,

To Print the List of all the Matched Names, use this code:
Add One More ListBox on the Form Say lstMatch

Dim intIdx As Integer, intCount As Integer
Dim iPos Integer
Dim blnFound As Boolean
Dim sSQL As String
intCount = List1.ListCount - 1
[B]lstMatch[/B].Clear
For intIdx = 0 To intCount
    If LCase(Text1.Text) = LCase(List1.List(intIdx)) Then 
         blnFound = True
         sSQL =List1.List(intIdx)
         iPos = InStr(sSQL,",")
         If iPos>0 Then
              sSQL = Left(sSQL,(i-1))
          End If
         [B]lstMatch[/B].AddItem sSQL
    End If
Next
If blnFound = True Then
     MsgBox "Item " & Text1.Text & " was found!", vbOKOnly + vbInformation
 Else
     MsgBox "Item " & Text1.Text & " was not found!", vbOKOnly + vbInformation
 End If

In the Above Code, U need not Keep A Boolean Variable also, u can just check the ListCount of lstMatch.
If u r very particular to show in a Label, then u can build a String and then display that string in Label.

I hope it is clear,

Regards
Veena

Hi QVeen72

I googled the parts I didnt understand,and yes it makes sence,I can't believe it's such a small adjustment,I spent so much time re writting code ,trying out new things,its not even funny..

Either way you've definitely saved me a lot of headaches and I really can't thank you enough.

Thanks again.:cheesy:

(edit)additem if the string is found,is such an easier way of doing it...so again thanks for your time,I've def learned a lot in the last few days.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.