Results 1 to 7 of 7

Thread: [RESOLVED]Text1.text + Enabled + True? [PART 2!]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    95

    Resolved [RESOLVED]Text1.text + Enabled + True? [PART 2!]

    Visual Basic 6

    Okay, I'm making a comment box on a program i'm coding, and I was wondering
    if it was possible to disable the send button until user has fill text1.text with 10 letters atleast before he can use the "Send" button to submit his comment.

    Thanks!
    Last edited by Lukeidiot; Aug 15th, 2007 at 08:01 AM.

  2. #2
    Frenzied Member
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,158

    Cool Re: Text1.text + Enabled + True?

    u can use

    one way
    Code:
    if len(text1.text)>=10 then
    'ur code...
    end if
    or

    Code:
    Private Sub text1_Change()
    'first disable ur send button
    if len(text1.text)>=10 then send.enabled=true
    End Sub

  3. #3
    Member garjanis's Avatar
    Join Date
    Jul 2007
    Posts
    42

    Re: Text1.text + Enabled + True?

    Maybe you need this:
    Code:
    Private Sub Form1_Load()
    Command1.Enabled = False
    End Sub
    
    Private Sub TextBox1_Change()
    If (Len(TextBox1.Text) >= 10) Then
    Command1.Enabled = True
    End if
    End Sub
    Dim MyBrains As Boolean
    MyBrains.Enabled = False

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

    Re: Text1.text + Enabled + True?

    I would add an Else, otherwise, all they need to do is type 10 letters which will enable the button, then backspace them all out.
    Code:
    Private Sub TextBox1_Change()
    If (Len(TextBox1.Text) >= 10) Then
        Command1.Enabled = True
    Else
        Command1.Enabled = False
    End if
    End Sub

  5. #5
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: Text1.text + Enabled + True?

    You can do it as a one-liner:
    Code:
    Private Sub TextBox1_Change()
        Command1.Enabled = (Len(TextBox1.Text) >= 10)
    End Sub
    Of course, I don't usually do it with only a single line. Anytime I set a control property in a procedure that can fire a bunch of times in quick succession, I tend to only set it if it has changed:
    Code:
    Private Sub TextBox1_Change()
        Dim blnEnabled As Boolean
        
        blnEnabled = (Len(TextBox1.Text) >= 10)
        With Command1
            If .Enabled <> blnEnabled Then .Enabled = blnEnabled 
        End With
    End Sub
    I do this because I'm irrationally averse to flicker.
    Last edited by Ellis Dee; Aug 14th, 2007 at 09:25 AM.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    95

    Re: Text1.text + Enabled + True?

    Cool, and thanks very much.

    But, how can i display a MsgBox if they try to use "cmdEmail"

    Heres an example of my code for "cmdEmail"

    Code:
    Private Sub cmdEmail_Click()
        Dim strResult As String
        Dim strURL As String
        
        If (Len(txtcomment.Text) <= 16) Then
        MsgBox "Please enter a comment of atleast 16 characters", vbExclamation
        
        'Enter URL to your PHP file.
        strURL = "http://www.lukeidiot.com/********.php"
        
        strResult = Inet1.OpenURL**************************
        
        If strResult = "Success" Then
            MsgBox "Successfully sent", vbInformation
        ElseIf strResult = "Failure" Then
            MsgBox "Error Sending", vbExclamation
        Else
            MsgBox "No/unknown response", vbQuestion
        End If
        Unload Me
    End Sub
    Note: The line of code that says
    Code:
    If (Len(txtcomment.Text) <= 16) Then
        MsgBox "Please enter a comment of atleast 16 characters", vbExclamation
    Was my theory, and doesnt work. How can i go about displaying the message box when the user doesnt have 16 letters?

  7. #7
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: Text1.text + Enabled + True?

    Code:
    Private Sub cmdEmail_Click()
        Dim strURL As String
        
        If Len(txtcomment.Text) <= 16 Then
            MsgBox "Please enter a comment of atleast 16 characters", vbExclamation
        Else
            'Enter URL to your PHP file.
            strURL = "http://www.lukeidiot.com/********.php"
            
            Select Case Inet1.OpenURL**************************
                Case "Success": MsgBox "Successfully sent", vbInformation
                Case "Failure": MsgBox "Error Sending", vbExclamation
                Case Else: MsgBox "No/unknown response", vbQuestion
            End Select
            Unload Me
        End If
    End Sub

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