PSU_Justin Posted February 25, 2003 Posted February 25, 2003 I'm 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 doesn't quite work. 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. I'm 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.) Quote
stustarz Posted February 25, 2003 Posted February 25, 2003 Try 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 Quote Visit: VBSourceSeek - The VB.NET sourcecode library "A mere friend will agree with you, but a real friend will argue."
Heiko Posted February 25, 2003 Posted February 25, 2003 "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 If dTxtBx.Text = "" Then .... Quote .nerd
stustarz Posted February 25, 2003 Posted February 25, 2003 Fancy that - you get two identical answers posted at exactly the same time!!! Quote Visit: VBSourceSeek - The VB.NET sourcecode library "A mere friend will agree with you, but a real friend will argue."
*Gurus* divil Posted February 25, 2003 *Gurus* Posted February 25, 2003 Not identical - yours won't work :) The best way would be comparing Textbox1.Text.Length to 0. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
stustarz Posted February 25, 2003 Posted February 25, 2003 But 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! Quote Visit: VBSourceSeek - The VB.NET sourcecode library "A mere friend will agree with you, but a real friend will argue."
PSU_Justin Posted February 25, 2003 Author Posted February 25, 2003 Both ways appear to be working well. Quote
*Gurus* Derek Stone Posted February 25, 2003 *Gurus* Posted February 25, 2003 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. Quote Posting Guidelines
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.