Skip to main content

How to add items to Combobox in Dialog

Hi,
Can anybody tell me the syntax to add items to a Combo box placed in Idea Scripting Dialog control?
 
Thanks,
Shafeer

Brian Element Tue, 04/01/2014 - 07:41

Hello and welcome to the site.

Below is a simple example of using a combobox.  You would first create a dialog with a combo box.  In the properties for the ComboBox you need to add a variable for the Attached List, you can add something like list1$(), the $ means that the variable is of type string and the () defines it as an array.  You don't have to Dim as the scripting editor will take care of it by placing Dim list1$() as the first line (this line is hidden unless you open it in an editor such as notepad).

You would then ReDim the list1$ variable to indicate how many items the array will include, you then add the items to your array and call the dialog, IDEA will automatically add this array to the dialog because of the name.  There is another way to do this which is a bit more complicated, let me know if this is good enough or if you wish to learn the more "complicated" way.  Also I have attached the script of this demo.

Dim list1$()

Begin Dialog NewDialog 32,29,150,150,"NewDialog", .NewDialog
  ComboBox 25,26,82,11, list1$(), .ComboBox1
  OKButton 30,69,40,14, "OK", .OKButton1
End Dialog
Option Explicit

Sub Main
	Dim dlg As NewDialog
	Dim button As Integer
	ReDim list1$(4)
	
	list1$(0) = "red"
	list1$(1) = "blue"	
	list1$(2) = "green"	
	list1$(3) = "yellow"	
	list1$(4) = "black"
	
	button = dialog(dlg)	
	msgbox "You selected: " & dlg.ComboBox1
End Sub

 

Shafeer Tue, 04/01/2014 - 10:54

Hi,
I don't want to create Dialog with code. I just inserted a new Dialog and added a Combo box. I need to fill Combo box with field names of the currently open database.  How can I add it to the Combo box?
 

Brian Element Tue, 04/01/2014 - 11:10

Hello Shafeer,

You can use this code to populate the field names into a Combo box. fieldlist$() is the array that holds the field names in the Combo box. This section first gets the IDEA file and then adds each field to the array.

Dim filebar As Object
Dim filename As String
Dim source As Object
Dim table As Object
Dim rst As Object
Dim field As Object
Dim fields As Integer

Set filebar=CreateObject("ideaex.fileexplorer")
filebar.displaydialog
filename=filebar.selectedfile   
              				               	
If filename <> "" Then
	               		
        Set source=client.opendatabase(filename)
	Set table=source.tabledef
	Set rst =source.recordset
	fields=table.count
			
	ReDim fieldlist$(fields)
		
	j=1
				
	For i=1 To fields 
	       
		Set field=table.getfieldat(i)
		fieldlist$(i)=field.name        
	Next i
	
End If

 

Shafeer Tue, 04/01/2014 - 11:28

Thanks Brian for quick response.
How can I add fieldlist$ into Combo box? Should I assign fieldlist to Attached List property of Combo box? If yes, how to do it.
Thanks,
Shafeer

Brian Element Tue, 04/01/2014 - 11:39

Yes, in the dialog, select the combo box and in the properties - Attached List enter fieldlist$().  You would need to populate the array before you call the Dialog() function.  Here is a screen capture.

Attach List array

Norbert_L Thu, 09/04/2014 - 07:10

Hi Brian, nice Page you have here :)
My problem fits into this topic at best, I think.
 
I've written a few larger scripts with variables, they are mostly working as they should.
Now I want to make them more user friendly by using dropdowns to fill in the variables.
Ist it possible that the dropdown selection is filled in to my variables automatically?
 
I have only basic knowlegde of Scripting, everything I have is a copy out of the history of IDEA extended with the variables...I give you a short example how my scripts are build:
 
'Global Variables
Dim VAmount as String
Sub Variable_define
VAmount = "" <-- there I fill in the field names manual
'Open Routines
Call entries_without_amount
call other routines...
end sub
 
Sub entries_without_amount
Set db = Client.CurrentDatabase()
Set task = db.Extraction
task.IncludeAllFields
dbName = "Entries without amount.IMD"
eqn = "" & VAmount & "=0"
task.AddExtraction dbName, "", eqn
task.PerformTask 1, db.Count
Set task = Nothing
Set db = Nothing
end Sub
 
Thanks for your help,
Norbert
Edit: insert paragraphs

Brian Element Thu, 09/04/2014 - 07:46

Hello Norbit and welcome to the site.

I am not sure what you mean by filling the drop-down automatically, you have to always have some code in the background that populates the drop-down but the information can change depending on the file you are using.  Drop-downs are great for selecting fields as you can populate the drop-down with the field names and you could filter out the fields to only display the character fields, numeric, etc.

Also you could populate the drop downs with any other type of text information that is generated in your script.

Now drop-downs have their limitations in that you can only select one item from them, unfortunately IDEAScript dosn't have a built in function to select multiple items, in those instance you can add some code to create a user created list box like in this example.

In your example it seems that you probably want to add multiple fields, in this case a drop down wouldn't be the best but using a list box as in the above example would be what you need.

Let me know if this is what you are looking for and I will put together an example script for you.

Brian

Norbert_L Thu, 09/04/2014 - 08:25

By "filling the drop-down automatically" I mean that in the dialog there are seperate drop-downs for every field that is needed by the script.
 
There is one drop-down for the amount, one for the entry date, one for user... and so on - every variable has its own drop-down and so you don't need to do select multiple Items at once.
Every drop-down should fill a variable within the script so that the user can use a dialoge instead of the script editor to fill in the fields.
 
I have further settings that are made inside the script, set dates in variables like the beginn of a fiscal year - but I think taht could be solved with a text field (the easiest way) where the user enter the date in a defined format (YYYYMMDD)
 
The script is unfortunately written with german term for the variables and comments, I could show you some parts if you want to.
 
There are 17 variables to filled in with field names from the database, other 10 variables for text search, 2 variables to control the parts of the script (one for routines and graphics, the other controls the special parts for the accounting system like SAP), 4 variables for numbers (like days between entry date and booking date) and 3 variables for dates (like begin and end of the fiscal year)
 
I used to save the script with the filled in variables if I need to rerun it with new data from the clients...
hopefully that is not too much information - to adress my problems in english is far more difficult than I thought to..
 
Thanks,
Norbert
 
 
 

Brian Element Thu, 09/04/2014 - 09:02

Norbert, thanks for the info.  I will put something together for you.  Maybe you could list the variables that you want to populate, if you expect the variable to be character, numeric, date, etc and if it will come from a drop-down or a text box.  That way I can try and relate the example directly with your variable.