Skip to main content

Pushbutton

Hi Brian,
I have created an extraction in IDEA. My task now is to automate it by creating a menu / dialog box for the user. How am I able to trigger a pushbutton and display the direct extraction result via IDEAScript. Example, I have a pushbutton called 'A'. If 'A' button is pushed, the extraction result will be displayed.  Same goes with button 'B', 'C' and so on. Should I also put a Do..Until / Select..Case loop in this situation. 
Any help with sample scripts would be great here.
Thanks.
William

Brian Element Mon, 06/30/2014 - 07:09

Hi William,

Here is some sample code for you (you can download it here if you want).  The script has three buttons, the buttons are numbered based on the order that they are created and 0 is the cancel button and -1 is the ok button.  In the example script the menu is displayed until you hit the ok or the cancel button.  When you hit a button the script will give you a message box saying which button was selected.  So let me know if this is what you are looking for or give me more info and I will try and help you out.

Option Explicit

Sub Main
	Call getMenu()
End Sub

Function getMenu()
	Dim dlg As NewDialog
	Dim button As Integer
	
	Do 		
		button = Dialog(dlg)
		Select Case button
			Case 1 'first button selected
				MsgBox "First Button Selected"
			Case 2 'second button selected
				MsgBox  "Second Button Selected"
			Case 3 'third button selected
				MsgBox "Third button selected"
			Case 0 'cancel button selected
				MsgBox "The cancel button was selected, the script will exit"
			Case -1 'cancel button selected
				MsgBox "The ok button was selected, the script will exit"	
		End Select
	Loop While button > 0

End Function

 

William Yong Mon, 07/07/2014 - 03:01

Hi Brian,
Thanks for sharing the codes. It works fine. However, I required an action and not just message box when the 1st button is clicked. In my case, I required the 1st button to help me generate the details from the database upon clicked. I included these below statements in after the 1st Select..Case message box. I received a 'syntax error' here. Any idea on how to rectify this error? 
DirectExtraction = TRUE
GoTo DirectExtraction
I also try put the Client.RunIDEAScript "C:\xxxx.iss" after each Select..Case messagebox. It also return an error message to me. 
Please help me solve the error message encountered.
Cheers,
William

Brian Element Mon, 07/07/2014 - 05:34

Hi William, you should be using a call and not a goto.

So change Goto DirectExtraction to Call DirectExtraction and it should work.  Goto allows you to jump to another point in your function and you need a Goto: - with the colon to work, so the GoTo function is looking for the Goto: to jump to, since it is not finding it it raises an error.

I am not sure on the Client.RunIDEAScript error, I will have to test it out and get back to you.

Brian Element Mon, 07/07/2014 - 14:36

William, for the Client.RunIDEAScript make sure that the link is good.  You will get an error if you have a spelling mistake or the link is not good.

William Yong Fri, 07/11/2014 - 04:04

Hi Brian,
Thanks for the advice. I try both Call function anClient.RunIDEAScript, and it works. However, in the end I still prefer the Call function as it uses less .iss script files. The task I'm currently working on is valid for only one particular day data. What if I would like to continue perform the extraction with another type of file/data from next day. How am I able to do that? I got a plan here. I would like user to:-
1. Browse the directory to refer the .jpm file (report reader file prepared & to be continuously use)
2. Allow user to create the IDEA database with the prepared .jpm file earlier
3. Back to the original script that allow user to click on the buttons and give different days of result.
How am I able to work out item 1 & 2 above. To assist better with the understanding, please refer to the attached screens for more info. 
Thanks.
 
 
 

Brian Element Tue, 07/15/2014 - 07:36

In reply to by William Yong

Hi William, here is some sample code. The menu I put together looks like this:

The script allows you to select the file to import, select the import definition and then select several audit steps to perform.  You can find the code below and I have attached it so that you can look at it.


'**********************************************************************************************
'* Script:		Audit Step Selection Demo.iss
'* Author:	Brian Element - brian.element@ideascripting.com
'* Purpose:	Demo script to example of obtaining files and then performing audit steps on them.
'* Date:		July 15, 2014
'* This script is provided without any warranty or guarantee.  Anybody using this script
'* is encouraged to validate the effectiveness and reliability on their own.
'**********************************************************************************************

Option Explicit

Dim sFilename As String
Dim sImportFilename As String
Dim sImportDefinition As String
Dim bAuditSteps(3) As Boolean
Dim dlg As NewDialog
Dim sIDEAVer As String 'holds the idea version number
Dim Opendlg As Object
Dim working_directory as string

Sub Main
	working_directory = Client.WorkingDirectory()
	sIDEAVer  = verIDEA() 
	Call menu()
	Call ImportFile()
	
	If bAuditSteps(0) Then Call doSomething1()
	If bAuditSteps(1) Then Call doSomething2()
	If bAuditSteps(2) Then Call doSomething3()
	If bAuditSteps(3) Then Call doSomething4()
End Sub

Function importFile()
	sFilename = client.UniqueFileName("Demo Test")
	Client.ImportPrintReport sImportDefinition, sImportFilename, sFilename, FALSE
End Function

Function doSomething1()

End Function

Function doSomething2()

End Function

Function doSomething3()

End Function

Function doSomething4()

End Function

Function menu()
	Dim button As Integer
	button = Dialog(dlg)
End Function

Function displayIt(ControlID$, Action%, SuppValue%)
	Dim bExitFun As Boolean
	
	Select Case Action%
		Case 1
		
		Case 2
			Select Case ControlId$
			
				Case "PushButton1"
					'********************************************************************
					'* The following 3 lines can be used for V8 of IDEA
					If sIDEAVer = "8" Then 
						Set Opendlg = CreateObject("Ideaex.SaveOpenDialog")
						Opendlg.DisplayDialog False'For V8.5
						sImportFilename = Opendlg.SelectedFile
					'* End of section for idea verion 8.5
					'***********************************************************************
					Else
					'**********************************************************************
					'* Start of dialogs for IDEA V9
						Set Opendlg = Client.CommonDialogs
						sImportFilename = Opendlg.FileOpen("", "", "*.* (*.*)|*.*")		
					'*End of section for V9
					'**********************************************************************
					End If
				Case "PushButton2"
					'********************************************************************
					'* The following 3 lines can be used for V8 of IDEA
					If sIDEAVer = "8" Then 
						Set Opendlg = CreateObject("Ideaex.SaveOpenDialog")
						Opendlg.DisplayDialog False'For V8.5
						sImportDefinition = Opendlg.SelectedFile
					'* End of section for idea verion 8.5
					'***********************************************************************
					Else
					'**********************************************************************
					'* Start of dialogs for IDEA V9
						Set Opendlg = Client.CommonDialogs
						sImportDefinition = Opendlg.FileOpen("", "", "JPM Files (*.JPM)|*.JPM")		
					'*End of section for V9
					'**********************************************************************
					End If
					
				Case "OKButton1"
					bAuditSteps(0) = dlg.CheckBox1
					bAuditSteps(1) = dlg.CheckBox2
					bAuditSteps(2) = dlg.CheckBox3
					bAuditSteps(3) = dlg.CheckBox4
					bExitFun = True
			End Select
	End Select
	
	If sImportFilename = "" Then
		DlgText "Text1", "Please Select a file to import"
	Else
		DlgText "Text1", sImportFilename
	End If
	
	If sImportDefinition = "" Then
		DlgText "Text2", "Please Select a definition for the file import"
	Else
		DlgText "Text2", sImportDefinition
	End If
	
	If bExitFun Then
		displayIt = 0
	Else 
		displayIt = 1
	End If
End Function

Function verIDEA() As String
	On Error GoTo errorHandler
	Dim openDlg As Object
	Set openDlg = Client.CommonDialogs
	
	verIDEA = "9"
	Set openDlg = Nothing
	Exit Function
errorHandler:
	verIDEA = "8"
	Set openDlg = Nothing
End Function

 

Brian Element Fri, 07/11/2014 - 07:14

Hi William,

Just a suggestion.  Could you not allow the user to select the daily file and then have the script import it?  Also instead of using buttons could you not use check boxes so that the user would select which extractions to perform?

So you would have a menu with a button which would open up a load button, the user selects the file and then ticks off the items they want to perform on the file and then selects ok.

The script then imports the file and runs all the tests selected.  Let me know if that would work for you and I will help you build the interface.

Brian

 

William Yong Sat, 07/12/2014 - 21:51

In reply to by Brian Element

Hi Brian, 
That sounds like a plan and workable too. Appreciate to share the code to me.
Have a nice day!
William
 
 
 
 
 

Brian Element Mon, 07/14/2014 - 18:54

In reply to by William Yong

Just one last question, which version of IDEA are you running, the reason I ask is that IDEA added some additional functions for getting files in V9 and higher that are not available in V8.  So if I create the demo using those items the script would crash in V8.

William Yong Mon, 07/21/2014 - 23:48

In reply to by Brian Element

Thanks Brian,
The script works fine for me. Very kind of you to code it in both version, v.8 & v.9. I'm actually in v.8. I'm trying to improve the script by putting some error validation check on the file extention and file definition that user exported. What's the code like if I would like to allow user to import file definition in .jpm format only. I try to put the code here, but it got crash! Kindly assist and share some code to me.
Thanks in advance. Cheers, William