PDA

View Full Version : conversion of variant



fadib
11-09-2007, 12:30 PM
This is the code that i have.

Private Sub CommandButton1_Click()
If CheckBox1.Value = False And CheckBox2.Value = False Then
TextBox3.Text = 0
End If
If CheckBox1.Value = True Then
TextBox3.Text = TextBox1.Text
Else
If CheckBox2.Value = True Then
TextBox3.Text = TextBox2.Text
End If
End If
If CheckBox1.Value = True And CheckBox2.Value = True Then
TextBox3.Text = CVar(TextBox1.Text) + CVar(TextBox2.Text)
End If
End Sub

The problem that I have is the values are not being added. it seems they are kept as strings.
how can I add the values together, and not just display the values next to each other?:banghead:

Zack Barresse
11-09-2007, 12:31 PM
Are they numbers? Why CVar()? Why not CDbl() and covert as numbers?

Bob Phillips
11-09-2007, 12:36 PM
Val(TextBox1.Text)

Norie
11-09-2007, 12:39 PM
Try this.

Private Sub CommandButton1_Click()
TextBox3.Text = -CheckBox1.Value * Val(TextBox1.Text) - CheckBox2.Value * Val(TextBox2.Text)
End Sub

fadib
11-09-2007, 02:05 PM
Sweet!!!! thank you guys and thanks XLD. the val method worked out very well and that was easy.
:thumb