Date: 02-16-2022
Return to Index
created by gbSnippets
'This simply reads a text *.gbs file, putting each snippet in an element of
'a string array.
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg As DWord
Global D() As String
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,400,400, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Push", 10,10,100,20
Control Add ListBox, hDlg, 200, , 10,40,380,370
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case CB.Msg
Case %WM_Command
If CB.Ctl = 100 AND CB.Ctlmsg = %BN_Clicked Then
LoadFile("test.gbs")
DisplayInListBox
End If
Case %WM_Size
Local w,h As Long
Dialog Get Client hDlg To w,h
Control Set Size hDlg, 200, w-20, h-40
End Select
End Function
Sub DisplayInListBox
Local i,j As Long, temp As String, s As String
For i = 0 To UBound(D)
j = Instr(D(i),"gbs" + "_")
If j Then
ListBox Add hDlg, 200, Mid$(D(i),j,9) + " " + Parse$(D(i),$CrLf,3)
Else
If Val(Parse$(D(i),$CrLf,2)) >= Val(Parse$(D(i+1),$CrLf,2)) Then 'check for children
ListBox Add hDlg, 200, "---" + Parse$(D(i),$CrLf,3)
End If
End If
Next i
End Sub
Sub LoadFile(fName$)
Local i As Long, temp As String
Open fName$ For Binary As #1
Get$ #1, Lof(1), temp
Close #1
ReDim D(ParseCount(temp$, "++-"+"-;;")-1)
Parse temp, D(), "++-"+"-;;"
Dialog Set Text hDlg, Str$(UBound(D))
End Sub
'gbs_00558
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm