Cint(null)

  • Thread starter Thread starter Wael
  • Start date Start date
W

Wael

Hi

I have code that stores integer data from the control to the database.
(I am using Option Strict). The problem is when I try to do the code
below, I get that the string is not properly formatted because there is
no value. Each page has a lot of variables. Is there a way to solve
that problem without having to have an IF block for each variable?

myNewRow("score1") = CInt(SCORE1.Text)

Thanks
W
 
Wael said:
Hi

I have code that stores integer data from the control to the database.
(I am using Option Strict). The problem is when I try to do the code
below, I get that the string is not properly formatted because there is
no value. Each page has a lot of variables. Is there a way to solve
that problem without having to have an IF block for each variable?

myNewRow("score1") = CInt(SCORE1.Text)

Thanks
W
Yes, you do need to evaluate the input in interface objects before
attempting conversions.
What you describe is an input failure where the user failed to enter
anything into the textbox, correct?
You need to add code to trap missing/inappropriate input and force the user
to enter the correct stuff *before* you attempt any conversions or storage
in your database.
 
Wael,
Do your db fields allow nulls? Or do you want to default to zero
( or int.Max or whatever) if the Score1.Text is null. If you want null
to become a default value then create a global function in a module or
a shared method of a utility class:

public function FixNull(str as string,int nullVal) as integer
If str is null then
FixNull = nullVal
Else
FixNull = Cint(str)
End if
End Function

Now your code can use FixNull in place of CInt.
You may also deal with if str is not numeric but chances are you want
the exception to escape.

Cecil Howell
MCT, MCSD, MCAD.NET, MCDFSWQZ
 
I did something similar to that. I have a global function that takes
the datarow and the value and sets it accordingly
 
Back
Top