Link to home
Create AccountLog in
Avatar of beef137
beef137

asked on

How can you set the value of a variable to Null?

How can you set the value of a variable to Null?

Dim WORKORDERNUM
WORKORDERNUM = Nothing

This doesn't seem to be making the value null. I'm using Visual Studio 2008. = Null isn't doing it either.
Avatar of silemone
silemone
Flag of United States of America image

If its a built in class, then use intellisense and get the null value.
Otherwise
DIM x = NULL
If its a string,
Dim x = string.empty
Avatar of CSLEEDS
CSLEEDS

try:
WORKORDERNUM =vbnullchar or
WORKORDERNUM =vbnullstring
hi, try this

WORKORDERNUM = DBNull.Value
I use it in Vb2008...how do you know its not working?  are you still getting information after settting it?  if so is the logic correct, i.e. is that point in code being hit.  maybe you should post your code.
Avatar of Guy Hengel [angelIII / a3]
what kind of "null"?

it might be DBNull.Value you are looking for...
What is the variable type?
Have you tried WORKORDERNUM = ""  ?
Avatar of beef137

ASKER

What if it is an integer?
Avatar of beef137

ASKER

It says DBNull.Value cannot be used for an integer
not for ints...have to use zero instead.
try

Dim WORKORDERNUM As Nullable(Of Integer)
WORKORDERNUM = Nothing
Avatar of beef137

ASKER


Public Class SearchForm
    Public PHONENUM
    Public WORKORDERNUMSEARCH
    Public SCSERVICENUM
 
    Private Sub SearchButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchButton.Click
        If Me.PhoneTextBox.Text <> "" Then
            PHONENUM = Me.PhoneTextBox.Text
        Else
            PHONENUM = 0
        End If
 
        If Me.WOTextBox.Text <> "" Then
            WORKORDERNUMSEARCH = Me.WOTextBox.Text
        Else
            WORKORDERNUMSEARCH = DBNull.Value
        End If
 
        If Me.SCServiceTextBox.Text <> "" Then
            SCSERVICENUM = Me.SCServiceTextBox.Text
        Else
            SCSERVICENUM = DBNull.Value
        End If
 
        Me.WOTableAdapter.FillBySEARCH(Me.SearchDataSet.WO, WORKORDERNUMSEARCH, SCSERVICENUM)
    End Sub
 
End Class

Open in new window

or use a negative number as a flag, like say -1...that way if you need zeros, you can move on with your project if you using unsigned values.  are you getting data from a DB?
why aren't you using these values as strings anyway (just for i can understand).  are you doing arithmetic on them in the program?
Avatar of beef137

ASKER

ee_rlee,

When I try

Dim WORKORDERNUM As Nullable(Of Integer)
WORKORDERNUM = Nothing

it says Nullable Object must have value
if you're not doing math with them, they should be strings or it can cause confusion in the future, say you someone tries to concatenate them and add them together instead...just a thought...just learned something new from er-lee cool
ASKER CERTIFIED SOLUTION
Avatar of silemone
silemone
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
so, the value assigned will going for further processing, then what process/ comparison u wanna do with these parameter?
Avatar of beef137

ASKER

silemone,

Here is my SQL:

SELECT WORKORDER_NUM, STATUS, LAST_NAME, FIRST_NAME, ADDRESS, CITY, STATE, ZIP
FROM   WO
WHERE ((@WORKORDERNUMSEARCH = 0 AND 1=1) OR (WORKORDER_NUM = @WORKORDERNUMSEARCH)) AND
      ((@SCSERVICENUM = 0 AND 1=1) OR (SERVICE_NUM = @SCSERVICENUM))

and my VB was:

If Me.WOTextBox.Text <> "" Then
            WORKORDERNUMSEARCH = Me.WOTextBox.Text
        Else
            WORKORDERNUMSEARCH = 0
        End If
 
        If Me.SCServiceTextBox.Text <> "" Then
            SCSERVICENUM = Me.SCServiceTextBox.Text
        Else
            SCSERVICENUM = 0
        End If

This is all for a Search Form. This was working fine... till you start putting in large numbers in the Textboxes to search. Then it was error "Integer Column Overflow"... the math was too large or something. So Now I am trying to set the variables null and change the SQL a little to see if it can handle the math better