I need some help

K

karim

I am trying to have a btn that calculates. I'm using if statment but for some
reason it's not working. it has a blue line under if and then. here is the
code...

If
rbg.Checked=True then
lbl2.Text = ((txt2.Text / 453.592) / lbl1.Text)
Else
End If

thanks for any help...
 
M

Michel Posseth [MCP]

If
rbg.Checked=True then
lbl2.Text = ((txt2.Text / 453.592) / lbl1.Text)
Else
End If

Should be

If rbg.Checked=True then
lbl2.Text = ((txt2.Text / 453.592) / lbl1.Text)
Else
'-- do alternate stuff here
End If


or

If rbg.Checked then
'-- do your stuff
Else
'-- do alternate stuff here
End If


it also might be a good idea to set option strict to ON , then you would see
that you should convert the datatypes first to numeric values for
calculations and then convert them back to a string for display purposes



HTH

Michel
 
T

Teme64

karim said:
I am trying to have a btn that calculates. I'm using if statment but for some
reason it's not working. it has a blue line under if and then. here is the
code...

If
rbg.Checked=True then
lbl2.Text = ((txt2.Text / 453.592) / lbl1.Text)
Else
End If

thanks for any help...
Set Option Strict On, it helps a lot.

You're mixing string and double data types, so you have to convert them to the correct data types:

lbl2.Text = ((CDbl(txt2.Text) / 453.592) / CDbl(lbl1.Text)).ToString
 
F

Family Tree Mike

karim said:
I am trying to have a btn that calculates. I'm using if statment but for
some
reason it's not working. it has a blue line under if and then. here is the
code...

If
rbg.Checked=True then
lbl2.Text = ((txt2.Text / 453.592) / lbl1.Text)
Else
End If

thanks for any help...


In addition to the advice the others gave, an option is to add a line
continuation character (underscore) after the if statement, as follows:

If _
rbg.Checked then
' corrected math code
Else
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top