marshallgrad
08-28-2008, 06:34 AM
I need some help from the board.
We use a terminal emulator that has Visual Basic for applications built into it. I am designing a form and am having some trouble with a calculation.
Form name: DILUTION_FACTOR
I have 3 labels and 3 corresponding text boxes, one combobox, and 3 commandbuttons
Label1 ==> textbox1
Label2 ==> textbox2
Label3 ==> textbox3
Combobox1
Commandbutton1 ? CALCULATE
Commandbutton2 ? CLEAR_ENTRY
Commandbutton3 ? CANCEL
The form is supposed to allow the user to enter a numerical value into textbox1 and textbox2 and then perform a calculation and display the result in textbox 3 when the CALCULATE commandbutton is pressed.
My problem that I have is in my calculation instead of performing a numerical calculation it is simply concatenating the two variables SAMPLEVOLUME + DILUENTVOLUME. Since I am relatively new to VB I was hoping someone could point out what I am doing wrong in my coding or variables?
Thanks.
Butch
My code looks like this.
Private Sub CALCULATE_Click()
'MAKE CALCULATIONS HERE
Dim SAMPLEVOLUME, DILUENTVOLUME, DILUTION As Variant
If DILUTION_FACTOR.ComboBox1.Value = "DILUTION" Then
'FIND THE DILUTION RATIO
SAMPLEVOLUME = DILUTION_FACTOR.TextBox1.Value
DILUENTVOLUME = DILUTION_FACTOR.TextBox2.Value
DILUTION = ((SAMPLEVOLUME + DILUENTVOLUME) / SAMPLEVOLUME)
msgbox DILUTION
'using msgbox for testing purposes only...
ElseIf DILUTION_FACTOR.ComboBox1.Value = "SAMPLE VOLUME" Then
'FIND THE SAMPLE VOLUME NEEDED
ElseIf DILUTION_FACTOR.ComboBox1.Value = "DILUENT VOLUME" Then
'FIND THE DILUENT VOLUME NEEDED
End If
End Sub
-----------------------------------------------------------------------------
Private Sub CLEAR_ENTRY_Click()
Unload DILUTION_FACTOR
DILUTION_FACTOR.Show
End Sub
-----------------------------------------------------------------------------
Private Sub CANCEL_Click()
Unload DILUTION_FACTOR
Call Login.STOPMACRO
End Sub
-----------------------------------------------------------------------------
Private Sub ComboBox1_Change()
If ComboBox1.Text = "DILUTION" Then
DILUTION_FACTOR.Label3.Visible = False
DILUTION_FACTOR.TextBox3.Visible = False
DILUTION_FACTOR.Label2.Visible = True
DILUTION_FACTOR.TextBox2.Visible = True
DILUTION_FACTOR.Label1.Visible = True
DILUTION_FACTOR.TextBox1.Visible = True
ElseIf ComboBox1.Text = "SAMPLE VOLUME" Then
DILUTION_FACTOR.Label2.Visible = False
DILUTION_FACTOR.TextBox2.Visible = False
DILUTION_FACTOR.Label1.Visible = True
DILUTION_FACTOR.TextBox1.Visible = True
DILUTION_FACTOR.Label3.Visible = True
DILUTION_FACTOR.TextBox3.Visible = True
ElseIf ComboBox1.Text = "DILUENT VOLUME" Then
DILUTION_FACTOR.Label1.Visible = False
DILUTION_FACTOR.TextBox1.Visible = False
DILUTION_FACTOR.Label2.Visible = True
DILUTION_FACTOR.TextBox2.Visible = True
DILUTION_FACTOR.Label3.Visible = True
DILUTION_FACTOR.TextBox3.Visible = True
End If
End Sub
-----------------------------------------------------------------------------
Private Sub USERFORM_INITIALIZE()
With DILUTION_FACTOR.ComboBox1
'USE THIS TO POPULATE THE ENTRIES IN THE COMBOBOX.
'SINCE YOU MOST LIKELY WILL BE LOOKING TO CALCULATE THE DILUTION WE CAN SET
'A DEFAULT.
ComboBox1.AddItem "DILUTION"
ComboBox1.AddItem "SAMPLE VOLUME"
ComboBox1.AddItem "DILUENT VOLUME"
'=================================
ComboBox1.Text = "DILUTION"
'=================================
End With
End Sub
We use a terminal emulator that has Visual Basic for applications built into it. I am designing a form and am having some trouble with a calculation.
Form name: DILUTION_FACTOR
I have 3 labels and 3 corresponding text boxes, one combobox, and 3 commandbuttons
Label1 ==> textbox1
Label2 ==> textbox2
Label3 ==> textbox3
Combobox1
Commandbutton1 ? CALCULATE
Commandbutton2 ? CLEAR_ENTRY
Commandbutton3 ? CANCEL
The form is supposed to allow the user to enter a numerical value into textbox1 and textbox2 and then perform a calculation and display the result in textbox 3 when the CALCULATE commandbutton is pressed.
My problem that I have is in my calculation instead of performing a numerical calculation it is simply concatenating the two variables SAMPLEVOLUME + DILUENTVOLUME. Since I am relatively new to VB I was hoping someone could point out what I am doing wrong in my coding or variables?
Thanks.
Butch
My code looks like this.
Private Sub CALCULATE_Click()
'MAKE CALCULATIONS HERE
Dim SAMPLEVOLUME, DILUENTVOLUME, DILUTION As Variant
If DILUTION_FACTOR.ComboBox1.Value = "DILUTION" Then
'FIND THE DILUTION RATIO
SAMPLEVOLUME = DILUTION_FACTOR.TextBox1.Value
DILUENTVOLUME = DILUTION_FACTOR.TextBox2.Value
DILUTION = ((SAMPLEVOLUME + DILUENTVOLUME) / SAMPLEVOLUME)
msgbox DILUTION
'using msgbox for testing purposes only...
ElseIf DILUTION_FACTOR.ComboBox1.Value = "SAMPLE VOLUME" Then
'FIND THE SAMPLE VOLUME NEEDED
ElseIf DILUTION_FACTOR.ComboBox1.Value = "DILUENT VOLUME" Then
'FIND THE DILUENT VOLUME NEEDED
End If
End Sub
-----------------------------------------------------------------------------
Private Sub CLEAR_ENTRY_Click()
Unload DILUTION_FACTOR
DILUTION_FACTOR.Show
End Sub
-----------------------------------------------------------------------------
Private Sub CANCEL_Click()
Unload DILUTION_FACTOR
Call Login.STOPMACRO
End Sub
-----------------------------------------------------------------------------
Private Sub ComboBox1_Change()
If ComboBox1.Text = "DILUTION" Then
DILUTION_FACTOR.Label3.Visible = False
DILUTION_FACTOR.TextBox3.Visible = False
DILUTION_FACTOR.Label2.Visible = True
DILUTION_FACTOR.TextBox2.Visible = True
DILUTION_FACTOR.Label1.Visible = True
DILUTION_FACTOR.TextBox1.Visible = True
ElseIf ComboBox1.Text = "SAMPLE VOLUME" Then
DILUTION_FACTOR.Label2.Visible = False
DILUTION_FACTOR.TextBox2.Visible = False
DILUTION_FACTOR.Label1.Visible = True
DILUTION_FACTOR.TextBox1.Visible = True
DILUTION_FACTOR.Label3.Visible = True
DILUTION_FACTOR.TextBox3.Visible = True
ElseIf ComboBox1.Text = "DILUENT VOLUME" Then
DILUTION_FACTOR.Label1.Visible = False
DILUTION_FACTOR.TextBox1.Visible = False
DILUTION_FACTOR.Label2.Visible = True
DILUTION_FACTOR.TextBox2.Visible = True
DILUTION_FACTOR.Label3.Visible = True
DILUTION_FACTOR.TextBox3.Visible = True
End If
End Sub
-----------------------------------------------------------------------------
Private Sub USERFORM_INITIALIZE()
With DILUTION_FACTOR.ComboBox1
'USE THIS TO POPULATE THE ENTRIES IN THE COMBOBOX.
'SINCE YOU MOST LIKELY WILL BE LOOKING TO CALCULATE THE DILUTION WE CAN SET
'A DEFAULT.
ComboBox1.AddItem "DILUTION"
ComboBox1.AddItem "SAMPLE VOLUME"
ComboBox1.AddItem "DILUENT VOLUME"
'=================================
ComboBox1.Text = "DILUTION"
'=================================
End With
End Sub