dcsimg
Results 1 to 6 of 6

Thread: Textbox value

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2015
    Posts
    1

    Post Textbox value

    Hello Guys, I'm pretty new to the programming business and just do it in my free time.

    To the point:

    I want to read out of a textbox if it's value is zero or is empty. If its empty or it's value zero then button1 should disappear and the
    Key.Enter shouldn't be allowed anymore in this Textbox.

    I don't care how its programmed, it should just work.

    thats my actual code, but doesn't work
    Code:
    If (Not String.IsNullOrEmpty(TextBox1.Text)) Then
                Button1.Visible = False
            End If
            If (not string.IsNullOrWhiteSpace(TextBox1.Text)) Then
                Button1.Visible = False
            End If
    
        End Sub

  2. #2
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Music city, U.S.A.
    Posts
    1,248

    Re: Textbox value

    How is it that this code is executing right now? That is, how is it being called?
    I always add to the reputation of those whose post are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

  3. #3
    New Member
    Join Date
    Nov 2014
    Posts
    1

    Re: Textbox value

    Quote Originally Posted by enii View Post
    Hello Guys, I'm pretty new to the programming business and just do it in my free time.

    To the point:

    I want to read out of a textbox if it's value is zero or is empty. If its empty or it's value zero then button1 should disappear and the
    Key.Enter shouldn't be allowed anymore in this Textbox.

    I don't care how its programmed, it should just work.

    thats my actual code, but doesn't work
    Code:
    If (Not String.IsNullOrEmpty(TextBox1.Text)) Then
                Button1.Visible = False
            End If
            If (not string.IsNullOrWhiteSpace(TextBox1.Text)) Then
                Button1.Visible = False
            End If
    
        End Sub
    there to way to do that

    1:

    If TextBox5.Text = "" or TextBox5 = " " Then
    Button1.Visible = true
    else
    Button1.Visible = False
    end if

    2:


    If Not TextBox5.Text = "" Then
    ' your code here
    Button1.Visible = False
    Else
    MsgBox("The text box is emty")
    End If

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,795

    Re: Textbox value

    Quote Originally Posted by enii View Post
    Hello Guys, I'm pretty new to the programming business and just do it in my free time.

    To the point:

    I want to read out of a textbox if it's value is zero or is empty. If its empty or it's value zero then button1 should disappear and the
    Key.Enter shouldn't be allowed anymore in this Textbox.

    I don't care how its programmed, it should just work.

    thats my actual code, but doesn't work
    Code:
    If (Not String.IsNullOrEmpty(TextBox1.Text)) Then
                Button1.Visible = False
            End If
            If (not string.IsNullOrWhiteSpace(TextBox1.Text)) Then
                Button1.Visible = False
            End If
    
        End Sub
    Saying it doesn't work is like walking into the doctor's office and saying "it hurts" and expecting him to know what you're talking about... no one does that (as far as I know)...
    We're not psychic, we can't read your mind. We're also not sitting in your lap, so we don't see what you're seeing.

    Do you get an error? Does something happen that shouldn't? Is there something that should happen that isn't? Did your fingers fly off? Can happen, I've seen it on TV. More than once too! I'd dare say that your fingers flying off is an exception...

    Have you set a breakpoint and stepped through the code to see why it isn't working? Could be the logic... could be that something isn't the value you assume it to be. Where is this code? Is it in an event, a sub - is the sub even being called?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5
    Frenzied Member Gruff's Avatar
    Join Date
    Jan 2014
    Location
    Scappoose Oregon USA
    Posts
    1,293

    Re: Textbox value

    And before you ask. BreakPoint Video
    Burn the land and boil the sea
    You can't take the sky from me


    ~T

  6. #6
    Hyperactive Member
    Join Date
    Mar 2012
    Posts
    311

    Re: Textbox value

    Quote Originally Posted by enii View Post
    If its empty or it's value zero then button1 should disappear
    Code:
    If (Not String.IsNullOrEmpty(TextBox1.Text)) Then
                Button1.Visible = False
            End If
            If (not string.IsNullOrWhiteSpace(TextBox1.Text)) Then
                Button1.Visible = False
            End If
    
        End Sub
    You say you want the button to disappear if the TextBox is empty, but your code does the exact opposite. The Function IsNullOrEmpty returns true if the String parameter is null or empty. So "If String.IsNullOrEmpty(TextBox1.Text) Then Button1.Visible = False" will do what you want; remove the Not at the beginning of your condition. You could also shorten it to "Button1.Visible = Not (String.IsNullOrEmpty(TextBox1.Text))" and get rid of the If-statement. BTW, IsNullOrEmpty is essentially the same as IsNullOrWhiteSpace except that the latter function also considers Strings of nothing but whitespace as being "empty" as well. So you'd only really need to use the one function (probably the IsNullOrWhiteSpace).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width