Skip to main content

put the puzzels together

hi folks,
i will show you how to put the iss puzzels together..well most of you will already done this, but for the new ideascripting folks it
is maybe a inspiration...

if you work each time with the same datastructure i show you how to import csv files automatically into idea and how to organize
some of your scripts in a comfortable way...

in this example i have one masterfile and two detailfiles. the file are from type csv. of course you need for every datafile
a record definition file (rdf).

this example was made with the german version of idea 8.5 - maybe there are differences in the english version!

how to configure your computer for this example:
---------------------------------------
a)
make on your hard drive a file folder named "example_a"
d:\example_a

b)
in this file folder make two subfolders "iscripts" and "definitions"
d:\example_a\iscripts
d:\example_a\definitions

c)
the folder iscripts will contain your idea scripts
the folder definitions will contain the rdf files
the folder example_a will contain the two subfolders and the csv-datafiles

so here are the steps you could make to put the puzzel together:

1. build yourself a starter script which is placed on a fixed point on your hard drive
------------------------------------------------------------------

the place to put the script:
c:\programs\idea\

script name:
- example_starter.iss

the script should looks like this:


Sub Main()

Dim a As Integer
a = 0

s = Dir(Client.WorkingDirectory + "iScripts\" + "*.iss")

While s <> ""
s = Dir
If s = example_startGui.iss" Then
a = 1
Client.RunIDEAScript Client.WorkingDirectory + "iScripts\example_startGui.iss"
Exit Sub
End If
Wend

If a = 0 Then
MsgBox "There is no startGui.iss.", 0, "Error"
Exit Sub
End If

End Sub

after you saved the script you could connect the script to the idea menĂ¼ (extras).. then you will have a really quick start
to your dataimport and scripts..

2. build a script that will automatically import CSV files with their rdf file
--------------------------------------------------------------------------------

the place to put the script:
d:\example_a\iscripts\

script_name:
example_importCSV.iss

the script:


'global declaration
Dim sImportFile, sImportRdf, sTargetFile, sFileName As String

Sub Main

sImportFile = ""
sImportRdf = ""
sTargetFile = ""
sFileName = ""

'you could also use a loop to import all the files in your workingDirectory.
'but this is the direct (uncomplicated) way to show you how it works...
'you are free to make this more powerful...

'ImportMaster
'-------------------
sImportFile = Dir(Client.WorkingDirectory + "master.csv")
sImportRdf = Dir(Client.WorkingDirectory & "\Definitions\" + "master.rdf")

If iIsBlank(sImportFile) = 1 Or iIsBlank(sImportRdf) = 1 Then
'If CSV file has no corresponding RDF file the CSV file will not be imported
Exit Sub
Else
sTargetFile = iReplace(sImportFile, ".csv", ".imd")
eqn = ""
Client.ImportDelimFile Client.WorkingDirectory + sImportFile, _
Client.WorkingDirectory + sTargetFile, _
TRUE, _
eqn, _
Client.WorkingDirectory + "definitions\" + sImportRdf, _
TRUE
sFileName = Dir(Client.WorkingDirectory + "master.IMD")
Set db = Client.OpenDatabase (sFileName)
db.Close

sImportFile = ""
sImportRdf = ""
sTargetFile = ""
sFileName = ""
End If

'ImportDetail_01
'be sure that you have create a rdf-file for this file
'----------------------------------------
sImportFile = Dir(Client.WorkingDirectory + "detail_01.csv")
sImportRdf = Dir(Client.WorkingDirectory & "\Definitions\" + "detail_01.rdf")

If iIsBlank(sImportFile) = 1 Or iIsBlank(sImportRdf) = 1 Then
'If CSV file has no corresponding RDF file the CSV file will not be imported
If iIsBlank(sImportRdf) = 1 then
MsgBox "no corresponding rdf-file or csv-file was found", 0, "report"
End If
Exit Sub
Else
sTargetFile = iReplace(sImportFile, ".csv", ".imd")
eqn = ""
Client.ImportDelimFile Client.WorkingDirectory + sImportFile, _
Client.WorkingDirectory + sTargetFile, _
TRUE, _
eqn, _
Client.WorkingDirectory + "definitions\" + sImportRdf, _
TRUE
sFileName = Dir(Client.WorkingDirectory + "detail_01.IMD")
Set db = Client.OpenDatabase (sFileName)
db.Close

sImportFile = ""
sImportRdf = ""
sTargetFile = ""
sFileName = ""
End If

'ImportDetail_02
'be sure that you have create a rdf-file for this file
'----------------------------------------
sImportFile = Dir(Client.WorkingDirectory + "detail_02.csv")
sImportRdf = Dir(Client.WorkingDirectory & "\Definitions\" + "detail_02.rdf")

If iIsBlank(sImportFile) = 1 Or iIsBlank(sImportRdf) = 1 Then
'If CSV file has no corresponding RDF file the CSV file will not be imported
If iIsBlank(sImportRdf) = 1 then
MsgBox "no corresponding rdf-file or csv-file was found", 0, "report"
End If
Exit Sub
Else
sTargetFile = iReplace(sImportFile, ".csv", ".imd")
eqn = ""
Client.ImportDelimFile Client.WorkingDirectory + sImportFile, _
Client.WorkingDirectory + sTargetFile, _
TRUE, _
eqn, _
Client.WorkingDirectory + "definitions\" + sImportRdf, _
TRUE
sFileName = Dir(Client.WorkingDirectory + "detail_02.IMD")
Set db = Client.OpenDatabase (sFileName)
db.Close

sImportFile = ""
sImportRdf = ""
sTargetFile = ""
sFileName = ""
End If

'refresh
Client.WorkingDirectory = Client.WorkingDirectory

End Sub

3. build example scripts to test your code
-------------------------------------------
the place to put the script:
d:\example_a\iscripts\

script name(s):
- script_01.iss
- script_02.iss
- script_03.iss

make it easy and short:

'script_01.iss:

Sub Main
MsgBox "Script_01", 0, "..."
End Sub

'script_02.iss:

Sub Main
MsgBox "Script_02", 0, "..."
End Sub

'script_03.iss:

Sub Main
MsgBox "Script_03", 0, "..."
End Sub

4. preparing the test data
---------------------------

4.1. copy the csv file to this place:
d:\example_a\

4.2. copy the rdf files to this place:
d:\example_a\definitions\

after all is done.....

5. build a grafical user interface. that will put the iss puzzle together
-------------------------------------------------------

the place to put the script:
d:\example_a\iscripts\

script name:
- example_startGui.iss

the script should look like this:


Dim sPath() AS string
Dim ImportStatus() AS string

Begin Dialog startGui 108,35,444,190,"Example_startGui cb", .Enable
Text 12,8,80,10, "Your current WorkingDirectory:"
ListBox 12,20,420,12, sPath(), .path
GroupBox 12,40,420,33, "1. Import CSV Data to Idea"
ListBox 15,55,212,12, ImportStatus(), .ImpStatus
PushButton 230,50,68,20, "start import", .Import 'PB1
GroupBox 12,80,420,61, "2. IDEA Scripts"
CheckBox 15,90,200,12, "01 - Script One", .CheckBox_1
CheckBox 15,100,200,12, "02 - Script Two", .CheckBox_2
CheckBox 15,110,200,12, "03 - Script Three", .CheckBox_3
PushButton 100,150,84,20, "Start Scripts", .Start 'PB2
PushButton 250,150,84,20, "Abort", .Break 'PB3
End Dialog

Sub Main

Dim iImdCnt As Integer
iImdCnt = 0

Do
j = 0
ReDim sPath(1)
ReDim ImportStatus(1)

sPath(1) = Client.WorkingDirectory

s = Dir(Client.WorkingDirectory + "*.imd")
While iIsBlank(s) = 0
iImdCnt = iImdCnt + 1
s = Dir
Wend

If iImdCnt = 0 Then
ImportStatus(1) = "Please Import your Data"
ElseIf iImdCnt > 0 Then
ImportStatus(1) = "No import possible. Your current WorkingDirectory contains already data."
End If

' initialize startGu
Dim dlg As startGui
Button = Dialog (dlg)

Select Case Button
'.. cancel pressed:
Case 0
j = 1
End Select

'start CSV dataimport
If button = 1 And iImdCnt = 0 Then
Client.RunIDEAScript Client.WorkingDirectory + "iScripts\example_importCSV.iss"
ElseIf button = 1 And iImdCnt > 0 Then
MsgBox "Import is not possible. Your current WorkingDirectory contains already data.", 0,"Report"
End If

'start scripts
If button = 2 Then

'01
If dlg.CheckBox_1 = 1 And iImdCnt > 0 Then
Client.RunIDEAScript Client.WorkingDirectory + "iScripts\script_01.iss"
ElseIf dlg.CheckBox_1 = 1 And iImdCnt = 0 Then
MsgBox "No data in your WorkingDirectory. Script is terminated.","","Report"
End If

'02
If dlg.CheckBox_2 = 1 And iImdCnt > 0 Then
Client.RunIDEAScript Client.WorkingDirectory + "iScripts\script_02.iss"
ElseIf dlg.CheckBox_2 = 1 And iImdCnt = 0 Then
MsgBox "No data in your WorkingDirectory. Script is terminated.","","Report"
End If
'03
If dlg.CheckBox_3 = 1 And iImdCnt > 0 Then
Client.RunIDEAScript Client.WorkingDirectory + "iScripts\script_03.iss"
ElseIf dlg.CheckBox_3 = 1 And iImdCnt = 0 Then
MsgBox "No data in your WorkingDirectory. Script is terminated.","","Report"
End If

End If

Loop Until j = 1 Or button = 3

End Sub

' startGui function
Function Enable(ControlID$, Action%, SuppValue%)
Select Case Action%
Case 1
'deactivate checkBoxes after loop
DlgValue "CheckBox_1",0
DlgValue "CheckBox_2",0
DlgValue "CheckBox_3",0
DlgValue "CheckBox_4",0
End Select
End Function

cheers and happy coding,
chris

CB Mon, 10/29/2012 - 07:19

.. the rdf files for detail_01.csv and detail_02.csv...

so you have now everything you need to test the example...

cheers,
chris

Brian Element Mon, 10/29/2012 - 07:24

Thanks Chris, I will have to try it out tonight.  This looks like a great way to control multiple scripts!!!

CB Mon, 10/29/2012 - 07:36

hi brian,
thats a really short demo to build a useful scriptpool...
for our users i have made such a dialog and the dialog is connected to the idea menue extras...
our users handle with fixed 20 - 30 scripts to get a fast data overview... for digging deeper they use idea (or excel) by their own..

but the advantage of such a home screen is that every user could work with it easy.. even if they are not interested in ideascripting...
so our normal users only get the ise-files.. so they should be sure that my scripts really work..

BUT!!! for building the scripts and automate the import prozess it is good to have every time the same record definition... if your datafile are not appointed or fixed..it could be different to progam it all high dynamic...

cheers,
chris