Originally Posted by
KF4GHG
Thank you below is the code. i get a 400 error on line 68. The Out5.txt file is:
Hi KF4GHG
The debugging of your code was not obvious
Look at the line flagged by " 'add Yann ============================"
An instruction you should know and use "
" it shows the upper boud of an Array , often the size of the array
uses "UI"
uses "file"
USES "CONSOLE"
%red_text = 12 'add Yann ============================================
dim tmpStr AS STRING
dim tmpLong as long
dim ID_List01 as long
dim MaxItems as long
dim CurItem as long
dim Count as Integer
dim MaxElements as long = 15 ' = 100
dim vList(15) AS STRING
' *******
dim InFileToLoad as string
dim InFileChannel as long
Dim i As Integer
Dim iTm (15) As String
dim sBuffer (15) as string
InFileToLoad = app_sourcepath & "Out5.txt"
' ******
Begin ControlID
%Text01
%List01
%Butt01
End ControlID
function TBMain()
DIM hDlg AS LONG
'---Create a new dialog
DIALOG NEW 0, "ListBox example", -1, -1, 275, 120, _
%WS_DLGFRAME OR %DS_CENTER OR %WS_CAPTION OR %WS_SYSMENU, _
0 TO hDlg
randomize
'*******
printl ubound(itm) in %red_text 'add Yann ================================================ should be 15 as defined in line 22
InFileChannel = file_open(InFileToLoad , "INPUT" )
i = 1
while not file_eof(InFileChannel)
iTm (i) = file_lineinput(InFileChannel)
print iTm(i)
i=i+1
wend
String iTm() ' Notice you don't have to specify size ahead!
printl ubound(itm) in %red_text 'add Yann =================================== ahah now = 0 the preceding line sets size of iTm array to zero
'add Yann =================================== in fact it redefines iTm array without a real size so this line should be suppressed
'add Yann ==================================================
printl PARSE(FILE InFileToLoad, iTm(), $CRLF) in %red_text
'add Yann =======================================curiously the count is one and the array is empty
'add Yann ======================================= the reason is not obvious
'add Yann ======================================= I then tryed to load the file in a buffer and print len and content of the buffer
'add Yann ======================================= The len was 0 zero and effectively nothing in the buffer
'add Yann ======================================= Then I reread the code .... line 47 File_Open (InFileToLoad , "INPUT" ) ...OK
'add Yann ======================================= But nowhere File_Close
'add Yann ======================================= The parsefile uses the opend file who reached EOF and load nothing
'add Yann =======================================
'add Yann ======================================= So add : file_close(infilechannel) after Wend and Parse will do better
i = 1
FOR count = 1 TO 15 ' MaxElements
vList(Count) = iTm(i) 'sBuffer(i) ' "Ronnie Item " & FORMAT$(RND(1, 100000), "000000")
i = i+1
NEXT
' ******
.
.
.
.
.
.
end function
I simplified the code lines 50 -- 54 by loading the file data in a buffer and parsing that buffer.
The code fails now : because PARSE redimension iTm array to the number of elements parsed
The loop in lines 63 to 66 have to be modified to agree with the element count which could be obtained
For example by using for count = 1 to maxelements
and maxelements = PARSE(data_buffer, iTm(), $CRLF)
and as you open a Console, I suggest you to use many Printl lines, to follow the way your script follows
Enjoy.
Yann
element_count = PARSE(data_buffer.......
'---Script created on 2024-07-10 21:00:49.595 by
uses "UI"
uses "file"
USES "CONSOLE"
%red_text = 12
dim parse_count_file as long
dim data_buffer as string
dim tmpStr AS STRING
dim tmpLong as long
dim ID_List01 as long
dim MaxItems as long
dim CurItem as long
dim Count as Integer
dim MaxElements as long = 15 ' = 100
dim vList(15) AS STRING
' *******
dim InFileToLoad as string
dim InFileChannel as long
Dim i As Integer
Dim iTm (15) As String
dim sBuffer (15) as string
itm(12) = "xxxx"
InFileToLoad = app_sourcepath & "Out5.txt"
' ******
Begin ControlID
%Text01
%List01
%Butt01
End ControlID
function TBMain()
DIM hDlg AS LONG
'---Create a new dialog
DIALOG NEW 0, "ListBox example", -1, -1, 275, 120, _
%WS_DLGFRAME OR %DS_CENTER OR %WS_CAPTION OR %WS_SYSMENU, _
0 TO hDlg
randomize
'*******
data_buffer = file_load(InFileToLoad)
maxelements = PARSE(data_buffer, iTm(), $CRLF) ' see note
i = 1
FOR count = 1 TO MaxElements 'see note
vList(Count) = iTm(i) 'sBuffer(i) ' "Ronnie Item " & FORMAT$(RND(1, 100000), "000000")
i = i+1
NEXT
' ******
'---.
.
.
.
.
..
Bookmarks