I'm working on an API where i have 2 steps.
Step 1 has 4 radiobuttons representing 4 different properties. Idea is to create a property when a radiobutton is checked. Currenlty i'm using select case to create the property.
Step 2 copies an existing element and updates to property created in step 1. Step 2 is a "case" under
Function DialogFunc%(DlgItem$, Action%, SuppValue%)
whereas step 1 is under sub main()
I'm not able to create the property the moment radiobutton is checked. Property gets created only when i hit "ok" in the userform.
I'm looking for ideas on how to create properties immedietly after checking the radiobutton.
Appreciate any help.
Solved! Go to Solution.
Here's an example you can start from.
'public variable so as to access it from DialogFunc Dim App As femap.model Sub Main Set App = feFemap() Begin Dialog UserDialog 150,90,.DialogFunc OptionGroup .opt OptionButton 10,10,150,20,"Create a node" OptionButton 10,30,150,20,"Create a point" OKButton 50,60,60,20 End Dialog Dim dlg As UserDialog If Dialog(dlg) = 0 Then End End Sub Function DialogFunc(DlgItem$, Action%, SuppValue?) As Boolean Select Case Action% Case 1 ' Dialog box initialization Case 2 ' Value changing or button pressed If DlgItem = "opt" Then If DlgValue("opt") = 0 Then 'node Dim n As femap.Node Set n = App.feNode n.Put(n.NextEmptyID) App.feAppMessage(FCM_NORMAL,"New node created") ElseIf DlgValue("opt") = 1 Then 'point Dim p As femap.Point Set p = App.fePoint p.Put(p.NextEmptyID) App.feAppMessage(FCM_NORMAL,"New point created") End If App.feViewRegenerate(0) 'update view 'DialogFunc = True 'do not exit dialog End If Case 3 ' TextBox or ComboBox text changed Case 4 ' Focus changed Case 5 ' Idle Case 6 ' Function key End Select End Function
I want to create a UserDialog with a variable number of OptionButtons. The number of OptionButtons is dependant on the number of installed versions of Nastran, which is taken from a text file, which is subsequently read into the NastranCmds() array. I want the user to be able to select the Nastran version they want to use.
I have tried the following but to no avail.
Begin Dialog UserDialog 150,90,.DialogFunc OptionGroup .opt For CmdIndex = 0 To UBound(NastranCmds)-1 Position = 10 * CmdIndex +10 OptionButton 10,Position,150,20,NastranCmds(CmdIndex) Next CmdIndex OKButton 50,Position + 30,60,20 End Dialog Dim dlg As UserDialog If Dialog(dlg) = 0 Then End
Unfortunately, I am getting the following errors:
API Error (Line 238): Expecting a user dialog item definition. -->For CmdIndex = 0 To UBound(NastranCmds)-1 API Error (Line 239): Expecting a user dialog item definition. -->Position = 10 * CmdIndex +10 API Error (Line 241): Expecting a user dialog item definition. -->Next CmdIndex API Error (Line 242): Expecting at least two OptionButton definitions. OKButton 50,Position + 30,60,20--> API Error (Line 245): Expecting a user dialog var. If Dialog(dlg-->) = 0 Then End
I have tried several different ways to write this, without succes.
As far as I can see, I am not allowed to define anything but a user dialog item within Begin Dialog and End Dialog.
Is there a way to create achieve what I want either with a user dialog or a dropdown list or whatever?
Try this drop-down option. You'll need to dimension your NastranCmds() array outside of the dialog box definition. You should be able to use the For loop method you have before "Begin Dialog..." to create the names / entries you want in the list. Then, you'll see at the bottom I've printed which version the user selected to the messages window since dlg.list1 tells you which entry on the drop down list was choosen.
Sub Main() Dim App As femap.model Set App = feFemap Dim NastranCmds$(4) NastranCmds$(0) = "Nastran 11.0" NastranCmds$(1) = "Nastran 10.0" NastranCmds$(2) = "Nastran 9.0" NastranCmds$(3) = "Nastran 8.0" Begin Dialog UserDialog 200,105 ' %GRID:10,7,1,1 text 10,10,180,15,"Select Nastran Version" DropListBox 10,25,180,60,NastranCmds(),.list1 OKButton 50,70,90,21 End Dialog Dim dlg As UserDialog dlg.list1 = 0 ' list1 is a numeric field Dialog dlg ' show dialog (wait for ok) Debug.Print NastranCmds$(dlg.list1) NastranVersionSelected = NastranCmds$(dlg.list1) App.feAppMessage(FCM_NORMAL,"User Selected:"+ NastranVersionSelected) End Sub