Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using blank values

Status
Not open for further replies.

robman70

Technical User
Aug 6, 2002
90
I'm having problems with empty textboxes. Sometimes some of the textboxes are blank and I want the program to accept that but instead it either will tell me 'invalid use of null' or 'type mismatch'.
Code:
' This is the Invalid use of null:
Private Sub Command1_Click()
    Dim intNumber As Integer
    
    If Text1.Text = "" Then
        intNumber = Null
    Else
        intNumber = Text1.Text
    End If
End Sub

Code:
' This is the type mismatch
Private Sub Command1_Click()
    Dim intNumber As Integer
    
    If Text1.Text = "" Then
        intNumber = ""
    Else
        intNumber = Text1.Text ' or CInt(Text1.Text)
    End If
End Sub

In the beginning i wanted null, but at this point i dont care anymore just anything blank will work, i just need it to accept a blank value. any help is appreciated
 
You rporblem is you are trying ot set an integer variable to NULL (which is a valid value for variants only) or to a string literal (which is valid for a string)

So you need to redefine intNumber as a variant (1st section of code would work)

or
redefine intNumber to be a string (second code would work)

or maybe re formulate what you want to do!

Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top