Shafeer
Offline
Last seen: 10 years 3 weeks ago
Joined: 04/01/2014 - 03:18
Hi Brian,
to share with the community:
I've figured it out :)
1. deklare Variables
dim Name as string
dim dlg as newdialog
...
2. read out the field names of the current database
(its a part of the script you already posted in this thread)
Set source=client.Currentdatabase()
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
button = Dialog(dlg)
if button = -1 then
3. fill in drop down selection
if dlg.checkVariable1 then
Name = fieldlist$(dlg.DropListName+1)
else
Name = ""
end if
else
set task = nothing
end if
With the "+1" I can read out the Field names instead of their number - as far a I observed.
The Checkbox helps to set the variable empty because a dropdown always fills in a field name.
Greeting
Norbert
Another thing you can do is in step 2 you can decide what field types to show. So if you only wanted date fields in the drop-down you could do something like this:
ReDim fieldlist$(fields)
j=1
For i=1 To fields
Set field=table.getfieldat(i)
if field.isDate then
fieldlist$(i)=field.name
end if
Next i
This way only date fields would appear in the drop down.
Your choices are IsCharacter, IsDate, IsNumeric, IsTime.
In part 3 you need the +1 to get the field name. The problem is that arrays start with 0 but when you added the information to the drop-down your first item was probably a 1 for the first field, but when it returns the item number in the drop-down it actually starts at 0 so you need the +1 to get the item from the original array, hope that makes sense.
thank you for your input.
So I create a list for each data type and connect them to the drop downs, right?
OK now I get it with the arrays ;)
That is correct, is this way your drop down will only contain the field types that you want.
Hi Brian,
is this correct?
Because when I read out the dropdowns the behavior is diffrent than if I had only the "fieldlist$()"
I use 10 dropdowns in one dialog, one with only date fields, two with all fields and the others with numeric fields.
The only Date field was manipulated in IDEA from character to date with the mask (DD.MM.YYYY)
My Problem ist that when I chose the date field in the dropdown, it selects nothing - the variable stays empty.
But if I change the source of the dropdowns from fieldlist_date$() to fieldlist$() everything works
Thanks
Norbert
Set source=client.Currentdatabase()
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
ReDim fieldlist_date$(fields)
a=1
For b=1 To fields
Set field=table.getfieldat(b)
If field.isDate Then
fieldlist_date$(b)=field.name
End If
Next b
ReDim fieldlist_number$(fields)
c=1
For d=1 To fields
Set field=table.getfieldat(d)
If field.isNumeric Then
fieldlist_number$(d)=field.name
End If
Next d
Hi Norbert, not sure but you might want to try this:
ReDim fieldlist_date$(fields)
a = 1
for b = 1 to fields
Set field = table.getFieldAt(b)
if field.isDate then
fieldlist_date$(a) = field.name
a= a+ 1
end if
next b
By using a instead of b in the array you are making sure there are no blanks, this might be what is causing the problem depending on the location of the date field.
Unfortunately I don't have time to test this out as I am leaving for the weekend in a few minutes and will be away from IDEA. So try this out and let me know if it makes a difference.
Brian
Hi Brian,
yes, it worked! :)
Thanks
Norbert
That is great, thanks for letting me know.
Is there a way to assign a default value (other than index 0 of array) to a dropdown box? I know how to populate the arrays, but I am trying to read in settings from a config file.
DlgText allows me to populate TextBox values, DlgValue allows me to populate CheckBox values, DlgListBoxArray allows me to assign an array to a DropListBox, but I cannot find a way to declare that the value of a specific DropListBox = Array(2)
TIA!
Hi Kris,
How you go about doing it is before you call the dialog you set-up your array of items. In my instance I have a drop list called DropListBox1 using an array listbox1$(). I define 4 items and then I use the dlg.DropListBox1 = 2 to have the drop list defaut to the green item. As far as I can tell you can't change it from within the dialog function but must set it before calling the dialog.
Pages