Date: 02-16-2022
Return to Index
created by gbSnippets
'This snippet shows how to compile and run a *.bas file using the PowerBASIC
'compiler (PBWin)
'Compilable Example: (Jose Includes)
#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, "Compile & Run",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
CompileRun Exe.Path$ + "test.bas", Exe.Path$ + "test.exe"
Dialog End hdlg
End If
End Function
Sub CompileRun(tempBAS As String, tempEXE As String)
Local PathInclude, PathCompiler, CmdString As String, iReturn As DWord
PathInclude = "c:\PBWin90\winapi\"
PathCompiler = "c:\PBWin90\bin\pbwin.exe"
'create dummy file to compile
Open tempBAS For Output As #1
Print #1, "#Compile EXE" : Print #1, "#Include " + $Dq + "Win32API.inc" + $Dq : Print #1, "Function PBMain"
Print #1, "? " + $Dq + "The compile worked!" + $Dq : Print #1, "End Function"
Close #1
'compile the BAS into an EXE, then run the EXE
CmdString = PathCompiler + " /I" + $Dq + PathInclude + $Dq + " " + $Dq + tempBAS + $Dq + "/L /Q" 'L=log Q=quiet I=includepath
Shell CmdString, 1, Exit To iReturn
iReturn = Shell(tempEXE)
'ShellExecute(hDlg, "Open", tempEXE, $Nul, $Nul, %SW_ShowNormal)
End Sub
'gbs_00549
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm