Date: 02-16-2022
Return to Index
created by gbSnippets
'Tests a line of text to see if it is the start of a
'PowerBASIC procedure
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
Global hDlg As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Procedure Locator",300,300,200,75, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Push", 30,10,100,20
Control Add TextBox, hDlg, 200,"Sub MySub", 30,35,150,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local temp$, pName$
If Cb.Msg = %WM_Command And Cb.Ctl = 100 And Cb.CtlMsg = %BN_Clicked Then
Control Get Text hDlg, 200 To temp$
If IsProcedure(temp$, pName$) Then ? pName$ Else ? "No procedure found!"
End If
End Function
Function IsProcedure(ByVal txt As String, pName As String) As Long
Local temp$, iPos, pFlag, iWord As Long
'Left trim spaces, remove double spaces from incoming txt
txt = Trim$(txt)
While InStr(txt, " ") : Replace " " With " " In txt : Wend
'Identify lines starting with procedure name
temp$ = LCase$(txt)
If Left$(temp$,4) = "sub " Then iWord = 2
If Left$(temp$,18) = "callback function " Then iWord = 3
If (Left$(temp$,9)= "function ") And (Left$(temp$,10) <> "function =") And (Left$(temp$,9) <> "function=")Then iWord = 2
If Left$(temp$,6) = "class " Then iWord = 2
If Left$(temp$,10)= "interface " Then iWord = 2
If Left$(temp$,7) = "method " Then iWord = 2
If Left$(temp$,9) = "property " Then iWord = 2
If iWord And ParseCount(txt, Any " (") >= iWord Then pName = Parse$(txt, Any " (", iWord) : Function = 1
End Function
'gbs_00828
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm