New programmer problems

PSU_Justin

Member
Joined
Feb 24, 2003
Messages
19
Location
State College, PA
Im trying to implement a simple conversion utility into my VB program. I want the utility to check my text box to see if it is empty, if it is to leave it empty, if not to run the conversion.

This is the Code I have been working with that doesnt quite work.

Code:
Dim dConv As Single

        If dTxtBx Is "" Then
            dConv = 0
        Else
            dConv = dTxtBx.Text
            dConv = dConv / 3.28083
            dTxtBx.Text = dConv
        End If

I think my problem is related to the is "" statement. Im not getting a specific error, but it appears that if the text box is blank the loop is jumping to the else statement and failing at the dconv=dtxtbx.text statement. (this is the first time I tried to put code into a post, hope I did it right.)
 
Try

Code:
Dim dConv As Single

        If dTxtBx.text Is "" Then
            dConv = 0
        Else
            dConv = CInt(dTxtBx.Text)
            dConv = dConv / 3.28083
            dTxtBx.Text = dConv
        End If
 
"Is" is the operator for comparing objects. In your case you want to compare values. The dTXTBx.Text property I presume (not the whole object, as your code does) with a string "".

Try

Code:
If dTxtBx.Text = "" Then ....
 
Not identical - yours wont work :)

The best way would be comparing Textbox1.Text.Length to 0.
 
But

Code:
If textbox.text = "" Then
Do Something
End If

Would work. This would check to see if the text is null and return true if the textbox is empty.

I left the is in my original code, should have been = missed that one!
 
There are roughly a dozen ways in .NET to determine if a String object has no length. The more common ones include the Length property and the String.Empty field. Whichever one you choose, use it consistantly.
 
Back
Top