Hello everybody,
Probably shouldn't have closed my old thread (listbox help) but i forgot to ask.
I have the reading of 2 text files, 1 which includes names and details of a user, and 1 which includes the name, and scoring details.
I have correctly set it up (with doogle's expertise) so that name clicked in a listbox (loaded from 1st textfile) checks for the name in the other text file and if it finds it displays its corresponding data. If that makes sense.
Basically What I want to do now, is; if in the second text file there was a multiple number of entry under the one name(on different lines), with different scores. How would i go about displaying each of these for instance in sequence one underneath each other in a label on another form.
also here are the text files:
scores.txt
names.txt
Thanks in advance. (I know i should have not closed that other thread, ...rookie error...)
Probably shouldn't have closed my old thread (listbox help) but i forgot to ask.
I have the reading of 2 text files, 1 which includes names and details of a user, and 1 which includes the name, and scoring details.
I have correctly set it up (with doogle's expertise) so that name clicked in a listbox (loaded from 1st textfile) checks for the name in the other text file and if it finds it displays its corresponding data. If that makes sense.
Basically What I want to do now, is; if in the second text file there was a multiple number of entry under the one name(on different lines), with different scores. How would i go about displaying each of these for instance in sequence one underneath each other in a label on another form.
Code:
Option Explicit
Dim myNameArray() As String
Dim myUserArray() As String
Dim myPwdArray() As String
Dim myDifficultArray() As String
Dim myScoreArray() As String
Dim myViewScoreArray() As String
Dim myOutofArray() As String
Dim myName1Array() As String
Dim myStarsArray() As String
Private Sub cmdadd_Click()
frmnewuser.Show
frmnewuser.txtfullname.SetFocus
Me.Hide
Unload Me
End Sub
Private Sub cmdviewscores_Click()
frmviewscore.Show
Me.Hide
End Sub
Private Sub Form_Load()
Dim intFile As Integer, x As Integer
Dim myLine As String, displayData As String
'
' Dimension the Dynamic Arrays to hold 200 elements
'
ReDim myPwdArray(199)
ReDim myUserArray(199)
intFile = FreeFile()
Open "P:\IPT\project\vb prject2013\names.txt" For Input As intFile
Do While Not EOF(intFile)
Line Input #intFile, myLine
myLine = Replace(myLine, """", "")
If Len(Trim$(myLine)) > 0 Then
myNameArray = Split(myLine, ",")
lstusers.AddItem (myNameArray(0))
If x > UBound(myPwdArray) Then
'
' If we've run out of elements then add another 200
'
ReDim Preserve myPwdArray(UBound(myPwdArray) + 200)
ReDim Preserve myPwdArray(UBound(myUserArray) + 200)
End If
myPwdArray(x) = (myNameArray(2))
myUserArray(x) = (myNameArray(1))
x = x + 1
End If
Loop
'
'Resize the arrays to the actual number of elements used
'
ReDim Preserve myPwdArray(x - 1)
ReDim Preserve myPwdArray(x - 1)
Close intFile
x = 0
ReDim myName1Array(199)
ReDim myScoreArray(199)
ReDim myOutofArray(199)
ReDim myDifficultArray(199)
ReDim myStarsArray(199)
intFile = FreeFile
Open "P:\IPT\project\vb prject2013\scores.txt" For Input As intFile
Do While Not EOF(intFile)
Line Input #intFile, myLine
myLine = Replace(myLine, """", "")
If Len(Trim(myLine)) > 0 Then
If x > UBound(myNameArray) Then
ReDim Preserve myName1Array(UBound(myName1Array) + 200)
ReDim Preserve myScoreArray(UBound(myScoreArray) + 200)
ReDim Preserve myOutofArray(UBound(myOutofArray) + 200)
ReDim Preserve myDifficultArray(UBound(myDifficultArray) + 200)
ReDim Preserve myStarsArray(UBound(myStarsArray) + 200)
End If
myViewScoreArray = Split(myLine, ",")
myName1Array(x) = myViewScoreArray(0)
myScoreArray(x) = myViewScoreArray(1)
myOutofArray(x) = myViewScoreArray(2)
myStarsArray(x) = myViewScoreArray(4)
myDifficultArray(x) = myViewScoreArray(3)
x = x + 1
End If
Loop
ReDim Preserve myName1Array(x - 1)
ReDim Preserve myScoreArray(x - 1)
ReDim Preserve myOutofArray(x - 1)
ReDim Preserve myDifficultArray(x - 1)
ReDim Preserve myStarsArray(x - 1)
Close #intFile
End Sub
Private Sub lstusers_Click()
Dim I As Integer
frmviewuser.lblfullname.Caption = lstusers.List(lstusers.ListIndex)
frmviewuser.lblpassword.Caption = myPwdArray(lstusers.ListIndex)
frmviewuser.lblusername.Caption = myUserArray(lstusers.ListIndex)
frmviewscore.lblscore.Caption = vbNullString
Do
If Trim$(myName1Array(I)) = Trim$(frmviewuser.lblusername.Caption) Then
'
' (I) is the Index into the second set of arrays that match the name
' e.g. myscorearray(I) would be the score for this username
'
frmviewscore.lblstarsearned.Caption = myStarsArray(I)
frmviewscore.lblscore.Caption = myScoreArray(I)
Else
I = I + 1
End If
Loop Until frmviewscore.lblscore.Caption <> vbNullString Or I > UBound(myName1Array)
End Sub
scores.txt
names.txt
Thanks in advance. (I know i should have not closed that other thread, ...rookie error...)