Documentation Center

Example 3 - Creating a project

This examples demonstrates the use of macros that can be invoked by pressing a shortcut and the use of dialogs in macros.

Suppose you want to create a project which should contain all executable files of a specified directory. This can be done easily with a macro.

From line 2 to line 14 a dialog is defined. You can use the dialog editor in the SAX Basic editor to create dialogs. Open the dialog editor with the menu command Edit / UserDialog. For the user dialog a dialog handler function will be generated automatically, see line 46 to 89. By adding some code, we allow the user to select directories for the Passolo project and the source files.

The code for setting up the project and adding the source files is straight forward. In line 20 a new project is added to PassoloApp. From lines 30 to 35 files with the extension will be added to the project and in the lines 38 to 43 files with the extension dll will be added to the project.

How to use it

Select PslAutoProjectFromFolder and assign it to the shortcut <SHIFT>+<CTRL>+F5. If you press the shortcut the following dialog comes up.

Enter a name and a directory path for the project. Select the directory of the source files and press OK and let the macro create the project.

0001 Sub Main
0002   Begin Dialog UserDialog 540,161,"Bulk Project", _
0003       .BulkProject ' %GRID:10,7,1,1
0004     Text 10,14,130,14,"Name of the Project:",.Text1
0005     Text 10,42,200,14,"Directory for Project:",.Text2
0006     Text 10,70,170,14,"Directory with files:",.Text3
0007     TextBox 220,7,270,21,.Project
0008     TextBox 220,35,270,21,.PSLDir
0009     TextBox 220,63,270,21,.SourceDir
0010     PushButton 500,35,30,21,"...",.GetPSLDir
0011     PushButton 500,63,30,21,"...",.GetSourceDir
0012     OKButton 430,105,90,21
0013     CancelButton 430,133,90,21
0014   End Dialog
0015   Dim dlg As UserDialog
0016   If Dialog(dlg) = 0 Then Exit Sub
0017 
0018   ' Create PASSOLO project
0019   Dim prj As PslProject
0020   Set prj = PSL.Projects.Add(dlg.Project, dlg.PSLDir)
0021 
0022   If prj Is Nothing Then
0023     MsgBox ("Failed to add project")
0024     Exit Sub
0025   End If
0026 
0027   ' Go to source directory and scan all exes
0028   ChDir(dlg.SourceDir)
0029   Dim file As String
0030   file = Dir$("*.exe")
0031   While file <> ""
0032     prj.SourceLists.Add(dlg.SourceDir & "\" & file, _
0033             file, pslLangEnglishUSA)
0034     file = Dir$()
0035   Wend
0036 
0037   ' same for DLLs
0038   file = Dir$("*.dll")
0039   While file <> ""
0040     prj.SourceLists.Add(dlg.SourceDir & "\" & file, _
0041             file, pslLangEnglishUSA)
0042     file = Dir$()
0043   Wend
0044 End Sub
0045 
0046 Private Function BulkProject(DlgItem$,Action%,SuppValue&) _
0047      As Boolean                                                  
0048   Dim folder As String
0049 
0050   ' We only want to check button clicks
0051   If Action% <> 2 Then Exit Function
0052 
0053 ' Let user select project directory
0054   If DlgItem$ = "GetPSLDir" Then
0055     If PSL.SelectFolder(folder, _
0056               "Select Directory for Project") Then
0057       DlgText "PSLDir", folder
0058     End If
0059     BulkProject = True
0060   End If
0061 
0062   ' Let user select source directory
0063   If DlgItem$ = "GetSourceDir" Then
0064     If PSL.SelectFolder(folder, _
0065             "Select Directory of Files") Then
0066       DlgText "SourceDir", folder
0067     End If
0068     BulkProject = True
0069   End If
0070 
0071   ' Only OK if user has enter all data
0072   If DlgItem$ = "OK" Then
0073     If DlgText("SourceDir") = "" Then
0074       MsgBox("Please select directory of files")
0075       BulkProject = True
0076       Exit Function
0077     End If
0078     If DlgText("PSLDir") = "" Then
0079       MsgBox("Please select directory for project")
0080       BulkProject = True
0081       Exit Function
0082     End If
0083     If DlgText("SourceDir") = "" Then
0084       MsgBox("Please enter project name")
0085       BulkProject = True
0086       Exit Function
0087     End If
0088   End If
0089 End Function