Skip to main content

Dialog Box instead of array

Hi Brian,
I am evolving some of my scripts for better usage and I come up with something I am not sure I can do, therefore I am checking with you. I have this part of code, and instead of an array, I would like to insert a dialog box with check boxes as my audit period will expand from location to location and therefore the last 6 months will be always different. Do you know if it is possible? If so, would you mind providing me some guidance?
Thanks,
Giorgia

Set db = Client.OpenDatabase("Bills with no PO.IDM")
Set task = db.KeyValueExtraction
dim myArray(5,0)
myArray(0,0) = "Apr 2016"
myArray(1,0) = "Dec 2015"
myArray(2,0) = "Feb 2016"
myArray(3,0) = "Jan 2016"
myArray(4,0) = "Mar 2016"
myArray(5,0) = "Nov 2015"
task.IncludeAllFields
task.AddKey "PERIOD", "A"
task.DBPrefix = "transactions of the last 6 months"
task.CreateMultipleDatabases = FALSE
task.CreateVirtualDatabase = False
task.ValuesToExtract myArray
task.PerformTask
dbName = task.DBName
Set task = Nothing
Set db = Nothing
 
 

Brian Element Wed, 07/27/2016 - 08:00

Hi Girogia,

So for the dialog do you a limited number of options for the checkboxes?  Unfortunately with the dialogs you can hide add or disable dialog elements but you need to add them at the front end.  So for your example are you looking for 12 check boxes that the user selects for each month and based on their selection it would populate the Key Value Extraction?

Thanks

Brian

Brian Element Wed, 07/27/2016 - 19:57

Hi Giorgia

Here is an example for you, I have also attached the script so you have the dialog.  I use two variables, the sMonthArray holds the key values that are displayed in the dialog and used for the extraction.  The bArrayValues holds the items that have been selected from the dialog.  Let me know if there is anything that doesn't make sense.  I didn't run the script so hopefully it will work for you.

Option Explicit
Dim bArrayValues(11) As Boolean
Dim sMonthArray(11) As String

Sub Main
	'populate a month array with the key values that are included in the database
	Call populateMonthArray()
	Call menu()
	Call KeyValueExtraction()
End Sub

Function KeyValueExtraction()
	Dim db As database 
	Dim task As task
	Dim i As Integer
	Dim j As Integer
	Dim dbName As String
	Dim myArray(500, 0) 'dim to maximum as can't redim or use a variable to dim to proper number
	
	j = 0
	'populate the myArray with they key values and leave the remaining blank which should be ignored by IDEA.
	For i = 0 To 11
		If bArrayValues(i) Then 
			myArray(j, 0) = sMonthArray(i) 
			j = j + 1
		End If
	Next i
	
	Exit Function
	Set db = Client.OpenDatabase("Bills with no PO.IDM")
		Set task = db.KeyValueExtraction
			task.IncludeAllFields
			task.AddKey "PERIOD", "A"
			task.DBPrefix = "transactions of the last 6 months"
			task.CreateMultipleDatabases = FALSE
			task.CreateVirtualDatabase = False
			task.ValuesToExtract myArray
			task.PerformTask
			dbName = task.DBName
		Set task = Nothing
	Set db = Nothing
End Function

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

Function displayIt(ControlID$, Action%, SuppValue%)
	Dim bExitFunction As Boolean
	Dim i As Integer
	
	Select Case Action%
		Case 1
			'change the text in the checkbox for the key values
			For i = 0 To 11
				DlgText "CheckBox" & (i + 1), sMonthArray(i) 
			Next i
		Case 2
			Select Case ControlID$
				
				Case "OKButton1"
					'extract the checkboxes that were ticked
					bArrayValues(0) = NewDialog.CheckBox1
					bArrayValues(1) = NewDialog.CheckBox2
					bArrayValues(2) = NewDialog.CheckBox3
					bArrayValues(3) = NewDialog.CheckBox4
					bArrayValues(4) = NewDialog.CheckBox5
					bArrayValues(5) = NewDialog.CheckBox6
					bArrayValues(6) = NewDialog.CheckBox7
					bArrayValues(7) = NewDialog.CheckBox8
					bArrayValues(8) = NewDialog.CheckBox9
					bArrayValues(9) = NewDialog.CheckBox10
					bArrayValues(10) = NewDialog.CheckBox11
					bArrayValues(11) = NewDialog.CheckBox12
					bExitFunction = true
				Case "CancelButton1"
					bExitFunction = True
			End Select
	End Select
	
	If bExitFunction Then
		displayIt = 0
	Else 
		displayIt = 1
	End If
	
End Function

Function populateMonthArray()
	'these should be the key values contained in the database
	sMonthArray(0) = "Jan 2015" 
	sMonthArray(1) = "Feb 2015" 
	sMonthArray(2) = "Mar 2015" 
	sMonthArray(3) = "Apr 2015" 
	sMonthArray(4) = "May 2015" 
	sMonthArray(5) = "Jun 2015" 
	sMonthArray(6) = "Jul 2015" 
	sMonthArray(7) = "Aug 2015" 
	sMonthArray(8) = "Sep 2015" 
	sMonthArray(9) = "Oct 2015" 
	sMonthArray(10) = "Nov 2015" 
	sMonthArray(11) = "Dec 2015" 
End Function