Results 1 to 15 of 15

Thread: enable and disabled buttons

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2012
    Location
    California
    Posts
    44

    enable and disabled buttons

    When I start my program, a button is disabled because i wrote if my text box is empty its disabled. But if the value of the text box is filled then the button will automatically enable. When i delete the value completely in the text box, the button is still enabled. How do i keep it so as long as the value of the text box is empty the button is disabled, even after i have deleted the value? Thank You. Here is my code.

    Private Sub Form_Load()
    Command1.Enabled = False
    Command2.Visible = False
    End Sub

    Private Sub Text1_Change()
    If Text1.Text > "" Then
    Command1.Enabled = True
    End If
    End Sub

  2. #2

    Thread Starter
    Member
    Join Date
    Feb 2012
    Location
    California
    Posts
    44

    Re: enable and disabled buttons

    Never mind I figured it out. Thank you

  3. #3
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: enable and disabled buttons

    The simplest solution
    vb Code:
    1. Private Sub Text1_Change()
    2.     Command1.Enabled = Not (Text1.Text = vbNullString)
    3. End Sub



  4. #4
    Lively Member
    Join Date
    Nov 2011
    Posts
    74

    Re: enable and disabled buttons

    if there are more controls on form like text boxes, check boxes then how to enable and disable the button in the same manner.

  5. #5
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: enable and disabled buttons

    for check box use
    vb Code:
    1. Private Sub Check1_Click()
    2.     Command1.Enabled = Not (Check1.Value = 0)
    3. End Sub



  6. #6

    Thread Starter
    Member
    Join Date
    Feb 2012
    Location
    California
    Posts
    44

    Re: enable and disabled buttons

    I am making a translation program. When the user types in a word in the first text box, then clicks translate the translated word appears in the second text box. But I don't want it to be case sensitive.

    Here is my code:

    Private Sub Command3_Click()
    If Text1.Text = "Hello" Then
    Text2.Text = "Hola"
    End If

  7. #7
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: enable and disabled buttons

    Quote Originally Posted by mcampos0809 View Post
    I am making a translation program. When the user types in a word in the first text box, then clicks translate the translated word appears in the second text box. But I don't want it to be case sensitive
    You can use LCase function
    vb Code:
    1. Private Sub Command3_Click()
    2.     If LCase$(Text1.Text) = "hello" Then
    3.         Text2.Text = "Hola"
    4.     End If
    5. End Sub

    You can also add Option Compare Text at the top of your form code, by adding that line, all string comparation will not be case sensitive, so you can use your code as it is
    vb Code:
    1. Option Compare Text
    2.  
    3. Private Sub Command3_Click()
    4.     If Text1.Text = "Hello" Then
    5.         Text2.Text = "Hola"
    6.     End If
    7. End Sub



  8. #8

    Thread Starter
    Member
    Join Date
    Feb 2012
    Location
    California
    Posts
    44

    Re: enable and disabled buttons

    Thank you 4x2y, I greatly appreciate it. It works perfectly

  9. #9
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,470

    Re: enable and disabled buttons

    is this more games for learning stuff?

  10. #10

    Thread Starter
    Member
    Join Date
    Feb 2012
    Location
    California
    Posts
    44

    Re: enable and disabled buttons

    Quote Originally Posted by incidentals View Post
    is this more games for learning stuff?
    I'm writing a translation program. simply type in the first text box a word in English, click translate, and the translated word will appear in the second text box.

  11. #11
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,470

    Re: enable and disabled buttons

    for what purpose a limited set of words like flash cards or any word that the user chooses?

  12. #12

    Thread Starter
    Member
    Join Date
    Feb 2012
    Location
    California
    Posts
    44

    Re: enable and disabled buttons

    right now just vocabulary words. like if the user types "walk" in the first text box, and clicks translate "caminar" appears on the second text box. But if you type "I walk to the park", and click translate
    nothing happeneds

  13. #13
    Lively Member
    Join Date
    Nov 2011
    Posts
    74

    Re: enable and disabled buttons

    if there are lot of more controls on form like text boxes, check boxes then
    how to enable and disable the button in the same manner. note that that should not perform one by one. any function.

  14. #14
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: enable and disabled buttons

    It would have to perform one by one (or at least in groups) because different controls have different syntax for determining use.

    Textboxs have a text property that can be checked....checkboxs have no text property...they use a Value property

    How many controls do you have on this form?

  15. #15
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: enable and disabled buttons

    Quote Originally Posted by yasrab View Post
    if there are lot of more controls on form like text boxes, check boxes then
    how to enable and disable the button in the same manner. note that that should not perform one by one. any function.
    The best solution for this is creating a control array, by this way you can use
    vb Code:
    1. Private Sub Check1_Click(Index As Integer)
    2.     Command1.Enabled = Not (Check1.Item(Index).Value = 0)
    3. End Sub
    If you have 100 checkbox, above line is what you need to enable/disable command1 when any value of them changed.



Posting Permissions

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



Click Here to Expand Forum to Full Width