Date: 02-16-2022
Return to Index
created by gbSnippets
'The built-in PowerBASIC Line Input # statement can be used to
'read a specified number of lines from a text file into an array
'Primary Code:
Line Input #1, MyArray() RECORDS nLines& TO count& 'Get nLines& in one gulp, count& gives # lines read
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10 1st 4 lines of a file
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg As Dword
Function PBMain() As Long
CreateTestFile
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
Sub CreateTestFile
Open "myfile.txt" For Output As #1
Print #1, "One" : Print #1, "Two" : Print #1, "Three"
Print #1, "Four" : Print #1, "Five" : Print #1, "Six"
Close #1
End Sub
CallBack Function DlgProc() As Long
If CB.Msg = %WM_Command AND CB.Ctl = 100 AND CB.Ctlmsg = %BN_Clicked Then
Dim count&, nLines&
nLines& = 4
Open "myfile.txt" For Input As #1
Dim MyArray(nLines&) As String 'Dim 0 to count-1
Line Input #1, MyArray() Records nLines& To count& 'Get nLines& in one gulp, count& gives # lines read
Close #1
MsgBox Join$(MyArray(), $CrLf) + $crlf + Str$(Count&) + " lines read."
End If
End Function
'gbs_00161
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm