Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21238

VB 6: Help with searching + displaying results.

$
0
0
Hi, I am a student wanting some help with my school project. Any help would be grately appreciated.
The project is a "afterschool register system". The post is pretty long so sorry for that.

So, my problem is; I cannot produce search resluts from searching through a .text file.

I have a "Register" form, which stores ;
- The students name (first and last name, 15 characters each)
- The name of the afterschool club they attended ( 20 characters)
- And the and the date on which the register was saved (10 characters)

This is stored from a list box, as a string in a text file (Register.text).

Here is the code:

Code:

Open App.Path & "\Register.txt" For Append As #1


Dim intX As Integer

With LstDragRegister    ' The listbox whihc I am saving from
   
    For intX = 0 To .ListCount - 1
   
        RegRec.Club = TxtClub.Text            ' getting the club name from an invisibe txtbox on the form
        RegRec.StudentName = Left(.List(intX), 30)        Getting the student name
        RegRec.TxtDate = TxtCurrentDate.Text                  ' getting the date from an invisibe txtbox on the form
       
            Print #1, RegRec.StudentName, RegRec.Club, RegRec.TxtDate
       
    Next
   
       
End With

    MsgBox "Register successfully saved"
   
Close #1

My problem appears when I want to filter which students attended the club on a particular date (this search is on a different form). It doesnt disply anything, and always resorts to the execution of my "Else If" statement, saying "the data I searched is not in the file".
I have a textbox in which user can input the date they want to check, and a combobox listing all the clubs. There is then a listbox which displays which students attended once a button is clicked.

I have ensured all names/dates/clubs in all textboxes etc have the correct amount of characters for what I am saving, eg, First name and last name are always 15 characters each, club name is always 20 characters, and the date is always 10 characters.

I am currently treating each line in the Register text file as a string, and using the Left(string, x) / Mid(string, x, y) functions to extract what data I need to compare with the data in the cbo / txt boxes.


Here is my code for searching the text file before I explain things further:

Code:

Dim Found As Boolean
Dim displaydata As String
Dim MyLine As String
Dim TempClub As String
Dim TempName As String
Dim TempDate As String

Me.LstStudents.Clear
'clear the listbox to stop duplication


Open App.Path & "\Register.txt" For Input As #1

Found = False

    Do While Not EOF(1)
   
        Line Input #1, MyLine
       
      TempClub = Mid(MyLine, 32, 52)
      TempDate = Mid(MyLine, 54, 64)
      TempName = Left(MyLine, 30)
       
      MsgBox MyLine    ' used for debugging purposes so I can see the variable values
      MsgBox TempName
      MsgBox TempClub
      MsgBox TempDate
       
            If TempDate = TxtDay.Text And TempClub = CboClub.Text Then
           
                Found = True
                   
                    displaydata = TempName & " " & TempClub & " " & TempDate
                   
                        LstStudents.AddItem displaydata
       
            Else
                    MsgBox ("Searched data is not in the register file")
                   
                    Exit Sub
                               
            End If
       
    Loop
   
Close #1

On problem seems to be that "TempClub" displays both the club name, and the date eg " Geek Club 06/02/2013 ", instead of the just the club name and the extra characters. TempStudent name and TempDate both display as desired.

Any help would be greatly appreciated, thanks. But please keep in mind I am only a student, and I only have limited coding knowledge.

Viewing all articles
Browse latest Browse all 21238

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>