Defining a variable

  • Thread starter Thread starter Adam
  • Start date Start date
A

Adam

I'm trying to assign a variable "s1" to whatever value is
entered into the text box side1.text with;

s1 = CDbl(side1.Text)

This works if there is a value in side1.text but it errors
if there isn't, how can I make it so it will ignore it
until side1.text gets a value
I was thinking

if side1.text=<>"" then
s1 = Cdbl(side1.text)
end if

would work but in this program side1.text will be filled
later when the other data is computed, so I need to figure
out a way for it to just ignore it until that happens, any
help would be appreciated. Thanks.
-Adam
 
Try

s1 = Val(side1.Text)

this will return 0 if text is not numeric.

You may need to make a reference to the VB6 compatibility lib.

You can test "side1.Text" if Val is 0
 
yes, but this would then falsely give a numeric value from a non numeric
input. I would suggest.

1.) Trap the keydown event and only allow numerics and decimal points (
make sure only one decimal point exists )

2.) Test as suggested for the box being empty before assigning the value


OHM





Michael said:
Try

s1 = Val(side1.Text)

this will return 0 if text is not numeric.

You may need to make a reference to the VB6 compatibility lib.

You can test "side1.Text" if Val is 0

Regards - OHM# OneHandedMan{at}BTInternet{dot}com
 
* "Adam said:
I'm trying to assign a variable "s1" to whatever value is
entered into the text box side1.text with;

s1 = CDbl(side1.Text)

How is 's1' defined?
This works if there is a value in side1.text but it errors
if there isn't, how can I make it so it will ignore it
until side1.text gets a value
I was thinking

if side1.text=<>"" then
s1 = Cdbl(side1.text)
end if

\\\
Dim s1 As Double
If Double.TryParse(side1.Text, Nothing, s1) Then
MsgBox(s1.ToString())
Else
MsgBox("No number!")
End If
///
 
Back
Top