Custom VB Dialog with Textbox and Dropdown

Post Reply
User avatar
CrashN8
Site Admin
Site Admin
Posts: 337
Joined: Thu Feb 09, 2017 4:07 pm

Custom VB Dialog with Textbox and Dropdown

Post by CrashN8 » Fri Nov 02, 2018 3:11 pm

Here is an updated post describing how to create custom VB Dialog Box starting in CMM-M version 3.8.

In this case we want to create a dialog with drop-down box and input / text box for numerical input. The values from dialog controls are stored in variables var1 & var2, thus allowing math operations, flow control, etc. from the response of user. See the VB Script Function Reference in this thread for additional details on custom dialog creation - https://cmmmanager.com/forum/viewtopic.php?f=63&t=2974

shrink_custom_dialog.jpg

Code: Select all

Dim MyList (2)  'Initialize a static array
MyList (0) = "0.000001"
MyList (1) = "0.000005"
MyList (2) = "0.0000001"
'Create dialog object
Set dlg1 = CreateDialog(16,35,256,89,"Part Material and Temperature")
'Add system buttons
dlg1.Add_OKButton 204,24,40,14
dlg1.Add_CancelButton 204,44,40,14
'Declare variables to get the listbox selection
Dim var1, var2
var1 = 20
var2 = 0 'to select first item by default

dlg1.Add_TextBox 24, 24, 72, 12, var1  'Add a Text Box

dlg1.Add_DropListBox 124,24,72,40,mylist,var2  'Add a drop list box
'Add some static text boxes
dlg1.Add_Text 24,12,75,8,"Part Temperature: (C)"
dlg1.Add_Text 124,12,75,8,"Part CTE: (mm/mm/C)"

Button = ShowDialog ( Dlg1 )  'Show dialog
'Verify drop listbox selections
MsgBox("Temperature = " & var1 &vbCRLF & "DropListbox = " & var2)
Set Dlg1 = Nothing  'Destroy the dialog object after use
You do not have the required permissions to view the files attached to this post.

mcasey
Frequent User
Frequent User
Posts: 33
Joined: Sat Jan 18, 2014 3:16 am

Re: Custom VB Dialog with Textbox and Dropdown

Post by mcasey » Sat Jun 22, 2019 1:13 pm

I'm using the example code as a guide for making a dialog for entering nominal dimensions off of a print into a textbox except it keeps rounding decimals to the nearest whole number. How would I go about modifying the code to treat decimals as decimals?

Thank You

Code: Select all

Dim MyList (9)  'Initialize a static array
MyList (0) = ""
MyList (1) = "9"
MyList (2) = "11"
MyList (3) = "13"
MyList (4) = "15"
MyList (5) = "17"
MyList (6) = "19"
MyList (7) = "21"
MyList (8) = "23"
MyList (9) = "25"
Dim MyList2 (6)
MyList2 (0) = ""
MyList2 (1) = "N"
MyList2 (2) = "A"
MyList2 (3) = "B"
MyList2 (4) = "C"
MyList2 (5) = "D"
MyList2 (6) = "E"
'Create dialog object
Set dlg = CreateDialog(350,75,175,315,"Part Parameters")


'Declare variables to get the listbox selection

Size = 0
Clocking = 0
Front_Outer_Dia = 0
Flange_Width = 0
Flange_Dia = 0
Flange_Z = 0
Hole_Spacing = 0
Hole_Dia = 0
Rear_Ins_Dia_1 = 0
Rear_Ins_Dia_1_Z = 0
Rear_Ins_Dia_2 = 0
Rear_Ins_Dia_2_Z = 0

'Size Drop List
dlg.Add_Text 24,12,75,8,"Size"
dlg.Add_DropListBox 24,24,32,12,mylist,Size

'Clocking Drop List
dlg.Add_Text 74,12,105,8,"Clocking"
dlg.Add_DropListBox 74,24,32,12,mylist2,Clocking  

dlg.Add_Text 24,50,105,12,"Front Outer Diameter:"
dlg.Add_TextBox 130,48, 32, 12,Front_Outer_Dia

dlg.Add_Text 24,74,105,12,"Flange Width:"
dlg.Add_TextBox 130,72,32,12,Flange_Width

dlg.Add_Text 24,98,105,12,"Flange Diameter:"
dlg.Add_TextBox 130,96,32,12,Flange_Dia

dlg.Add_Text 24,120,105,24,"Flange Depth:"
dlg.Add_TextBox 130,120,32,12,Flange_Z

dlg.Add_Text 24,146,105,24,"Hole Spacing:"
dlg.Add_TextBox 130,144,32,12,Hole_Spacing

dlg.Add_Text 24,170,105,24,"Hole Diameter:"
dlg.Add_TextBox 130,168,32,12,Hole_Dia

dlg.Add_Text 24,194,105,24,"Rear Diameter 1:"
dlg.Add_TextBox 130,192,32,12,Rear_Ins_Dia_1

dlg.Add_Text 24,218,105,24,"Depth of Rear Diameter 1:"
dlg.Add_TextBox 130,216,32,12,Rear_Ins_Dia_1_Z

dlg.Add_Text 24,242,105,24,"Rear Diameter 2:"
dlg.Add_TextBox 130,240,32,12,Rear_Ins_Dia_2

dlg.Add_Text 24,266,105,24,"Depth of Rear Diameter 2:"
dlg.Add_TextBox 130,264,32,12,Rear_Ins_Dia_2_Z



dlg.Add_OKButton 110,289,40,14 'on clicked will close dialog with (-1)

Do
result = ShowDialog(dlg) 

Select Case True
Case Size = 0
Case Clocking = 0
Case Front_Outer_Dia = 0
Case Flange_Width = 0
Case Flange_Dia = 0
Case Flange_Z = 0
Case Hole_Spacing = 0
Case Hole_Dia = 0
Case Rear_Ins_Dia_1 = 0
Case Rear_Ins_Dia_1_Z = 0
Case Rear_Ins_Dia_2 = 0
Case Rear_Ins_Dia_2_Z = 0
Case Else Exit Do
'Button = ShowDialog ( Dlg ) 
End Select
Loop


Set dlg = Nothing


mcasey
Frequent User
Frequent User
Posts: 33
Joined: Sat Jan 18, 2014 3:16 am

Re: Custom VB Dialog with Textbox and Dropdown

Post by mcasey » Sun Jun 23, 2019 2:53 pm

Update:

I figured it out.

This section of code:

Code: Select all


'Declare variables to get the listbox selection

Size = 0
Clocking = 0
Front_Outer_Dia = 0
Flange_Width = 0
Flange_Dia = 0
Flange_Z = 0
Hole_Spacing = 0
Hole_Dia = 0
Rear_Ins_Dia_1 = 0
Rear_Ins_Dia_1_Z = 0
Rear_Ins_Dia_2 = 0
Rear_Ins_Dia_2_Z = 0
Needed to be changed to:

Code: Select all




'Declare variables to get the listbox selection
Size = 0
Clocking = 0 
Front_Outer_Dia = 0.0000
Flange_Width = 0.0000
Flange_Dia = 0.0000
Flange_Z = 0.0000
Hole_Spacing = 0.0000
Hole_Dia = 0.0000
Rear_Ins_Dia_1 = 0.0000
Rear_Ins_Dia_1_Z = 0.0000
Rear_Ins_Dia_2 = 0.0000
Rear_Ins_Dia_2_Z = 0.0000
I am assuming that you need to include enough zeros to indicate how far out it should round to (i.e. least significant digit). Perhaps someone can confirm or deny this assumption?

Post Reply