Date: 02-16-2022
Return to Index
created by gbSnippets
'Many applications have a need to read text files one line at a time,
'processing the information as it is read. The PowerBASIC Line Input#
'statement is used for that purpose.
'Primary Code:
Open "myfile.txt" For Input AS #1
While IsFalse Eof(1) 'Note: NOT Eof(1) will not work
Line Input #1, x$
'...do something with the line read
Wend
Close #1
'Note: in other languages such as VB6, "While NOT EOF(1)" is used to
' control the loop. In PowerBASIC, NOT is a bitwise operator so
' NOT EOF(1) will is not suitable to control the loop.
'Compilable Example: (Jose Includes)
'this examples simply displays each Line in a MsgBox as it is read
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Push", 50,10,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If CB.Msg = %WM_Command AND CB.Ctl = 100 AND CB.Ctlmsg = %BN_Clicked Then
Local x$
Open "myfile.txt" For Input As #1
While IsFalse Eof(1)
Line Input #1, x$
MsgBox x$
Wend
Close #1
End If
End Function
'gbs_00162
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm