With your format as this:
Code: Select all
STRING 1,STRING 2,
STRING 3,STRING 4
You could do it by changing the = to an + operator
As it follows:
Code: Select all
If OpenWindow(0,0,0,400,200,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"TEST")
CreateGadgetList(WindowID(0))
If ReadFile(0,"c:\TEST.txt")
Repeat
TEXT$+ReadString()
Until Eof(0)
CloseFile(0)
EndIf
Dim TEXT$ (4):x=8
For I=1 To 4
TEXT$ (I)=StringField(TEXT$,I, ",")
StringGadget(I,8,x,306,20,TEXT$(I),#PB_String_UpperCase)
x=x+20
Next
Repeat:Until WaitWindowEvent()=#pb_event_closewindow
EndIf
Now, If you want to use the format you did show up in here, then this would do:
Code: Select all
If OpenWindow(0,0,0,400,200,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"TEST")
CreateGadgetList(WindowID(0))
If ReadFile(0,"c:\TEST.txt")
Repeat
TEXT$+ReadString()+"," ; we add our , by code
Until Eof(0)
CloseFile(0)
EndIf
Dim TEXT$ (4):x=8
For I=1 To 4
TEXT$ (I)=StringField(TEXT$,I, ",")
StringGadget(I,8,x,306,20,TEXT$(I),#PB_String_UpperCase)
x=x+20
Next
Repeat:Until WaitWindowEvent()=#pb_event_closewindow
EndIf
The method you're using is not the best at all, but if it works for you now, and you're quite new in programming, I suggest you to keep it until you're a little more confident to try new things.
Another thing: As you're using version 3.x, keep in mind that the string buffer size is fixed (to 64000 bytes). In 4.x the size is not fixed, so you wont find the limitation.
Could someone please correct the code below or explain why this is happening
You were asigning a new string on each pass of your loop! thats the explaination, you should use the + operator, which will ADD to your existant string.
Since you had multiple lines, only the last one was being shown up because it was the last one read from the file.
Now.. since you're using an array (you size it as 4 but it should be 3 as 0 counts as 1 though) you should read into the string array instead and then use it to display the data. Using a string here is no help, better is to have a string array.
Code: Select all
If OpenWindow(0,0,0,400,200,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"TEST")
If ReadFile(0,"c:\test1.txt")
ArraySize.l = 3;
Dim TEXT.s (ArraySize)
Repeat
tempStr.s =ReadString()+","
I+1
Count = CountString(tempStr,",")-1
For c=0 To Count
TEXT(CountOffset) = StringField(tempStr,c+1,",")
CountOffset+1
Next
Until Eof(0)
CloseFile(0)
CreateGadgetList(WindowID(0))
x.l =8
For I=0 To ArraySize;
tempStr.s =TEXT(I)
StringGadget(I,8,x,306,20,tempStr,#PB_String_UpperCase)
x=x+20
Next
Else
MessageRequester("error","Could not Read the file",#MB_OK|#MB_ICONERROR);
EndIf
Repeat:Until WaitWindowEvent()=#pb_event_closewindow
EndIf
But I wouldnt be using ReadString() in the first place..
Have fun.