by kevinrandell » Wed Nov 02, 2011 2:24 am
KBasic seems to handle things a little differently. I could not put multiple input variables and the buffer seems to read up to the comma not the whole line so this is why I could not get my previous code to run. Making the file space delimited and using the mods below I got my original code to work.
Shouldn't "input" read in the whole line, not just up to a comma?
Hard-wiring the App path is not great either, when I make a binary this will fail on other machines or accounts.
Any ideas?
Regards,
Kev
Private Sub CommandButton1_OnEvent()
dim scores (1 to 10) as integer
dim names (1 to 10) as string
dim i as integer
Dim strBuff As String
Dim AppPath As String = "/Users/kevinrandell/Documents/Introduction to Programming/Labs/FilesV2.kbasic_project/"
dim delim as integer
Label1.Caption=""
i=1
Open AppPath & "Scores.txt" For Input As #1
Do Until EOF(1)
Input #1, strBuff
delim = InStr(strBuff, " ")
If delim > 0 Then
names(i) = Left(strBuff, delim - 1)
scores(i) = Integer(Right(strBuff, Len(strBuff) - delim))
endif
if names(i)<>"" then
Label1.Caption = Label1.Caption & names(i) & " : " & str(scores(i)) & KbCrLf
endif
i=i+1
Loop
Close #1
End Sub