Dim scoreArray() As String
Dim nameArray() As String
Dim NewScore As String
'loads the table
Private Sub Form_Load()
Dim nf As Integer
Dim nFile As String
Dim sf As Integer
Dim sFile As String
Dim scoreFile As String
Dim nameWholeFile As String
Dim scoreWholeFile As String
Dim count As Integer
nf = FreeFile
nFile = "e:\name.txt"
Open nFile For Input As #nf 'open file
nameWholeFile = Input(LOF(nf), nf) 'save the whole file
Close #nf
sf = FreeFile
sFile = "e:\score.txt"
Open sFile For Input As #sf 'open file
scoreWholeFile = Input(LOF(sf), sf) 'save the whole file
Close #nf
scoreFile = "e:\dupa"
Open scoreFile For Input As #1 'Read file
NewScore = Input$(LOF(1), 1) 'Length of file
Close #1
nameArray = Split(nameWholeFile, "-") 'Split the contents of the file separated by space and saved each word to aString array
scoreArray = Split(scoreWholeFile, "-") 'Split the contents of the file separated by space and saved each word to aString array
For count = 0 To UBound(scoreArray)
Debug.Print scoreArray(count)
Next count
Call HScore(200)
End Sub
'searches if the score is already in the array
Public Sub HScore(ByVal score)
NewScore = score
Call compare
End Sub
'looks if the score is big enough to be in the high score table
Private Sub compare()
Dim notEnough As String
Dim score As Integer
If NewScore > scoreArray(0) Then
scoreArray(9) = NewScore
nameArray(9) = InputBox("please enter your name playa!")
Call sort
Else
notEnough = MsgBox("There are others better than you! Try again", 0, "Fail!")
End If
End Sub
' sorts the array in order
Private Sub sort()
Dim outerScore As Integer
Dim innerScore As Integer
Dim outerName As String
Dim innerName As String
Dim tempName As String
Dim tempScore As Integer
For outerScore = 8 To 0 Step -1
For innerScore = 0 To outerScore - 1
If scoreArray(innerScore) > scoreArray(innerScore + 1) Then
tempScore = scoreArray(innerScore) 'Swap array contents
scoreArray(innerScore) = scoreArray(innerScore + 1)
scoreArray(innerScore + 1) = tempScore
tempName = nameArray(innerScore) 'Swap array contents
nameArray(innerScore) = nameArray(innerScore + 1)
nameArray(innerScore + 1) = tempName
End If
Next innerScore
Next outerScore
Call printScore
End Sub
Private Sub printScore()
Dim counter As Integer
For scoreArray(counter) = 0 To 9
picScore.Print scoreArray(counter)
counter = counter + 1
Next scoreArray(counter)
End Sub
SO ok this is my code so far. It doesnt work ,
the basic idea of this code is that file gets loaded into the array and is separated by the "-" sign. There is array for Players name and Players score
the score that has been saved from a game that i have made before is loaded also.
In compare function, last number in the array is compared to the new score.
if new score is bigger than last position, last position is substituted with the new score.
I cant check if my program is working because the arrays are not printing into the picture boxes at all.
and i have no clue how to save the array back into the file with a "-" sign.
Please help
Thank you!