|
-
Mar 13th, 2002, 04:31 PM
#1
Thread Starter
Hyperactive Member
There has to be a better way
In VB6, if I wanted to check that data had been entered into a field I would say something like If Textbox1.text = "", then I knew there was nothing entered.
In VB .Net, I ended up writing this:
If Instr(Ltrim(Textbox1.text), " ") = 0 then there was nothng there, but even that solution is half baked as if the box is filled completely, then it won't work, anyone got any better ideas???
The other alternative was to compare it exactly to the number of spaces between quotes but that seems very messy
-
Mar 13th, 2002, 04:49 PM
#2
hi Richard I just tried the following and it worked perfectly
If TextBox1.Text = "" Then MsgBox("textbox is empty")
-
Mar 13th, 2002, 07:28 PM
#3
Thread Starter
Hyperactive Member
my fault for not explaining the problem fully, if you set the text to spaces as in the load event say textbox1.text = " "
then if textbox1.text = "" doesn't work.
In the end I declared a string
dim blanks as string = " "
much longer than my biggest text box and then used
if instr(blanks, textbox1.text) <> 0 then
- error message
end if
I was trying to make sure that on input for a mandatory text field the use couldn't enter spaces and defeat my edit check, I still think it looks very clumsy but I can't think of a better way
Last edited by RichardAtherton; Mar 13th, 2002 at 07:31 PM.
-
Mar 13th, 2002, 08:22 PM
#4
PowerPoster
This is a little more pleasing to look at..
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sBuffer As String = " "
If sBuffer.Trim(sBuffer) = String.Empty Then
MessageBox.Show("I'm Empty!!")
End If
End Sub
-
Mar 15th, 2002, 01:32 PM
#5
Thread Starter
Hyperactive Member
totally agree thanks!!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|