Results 1 to 6 of 6

Thread: if (not) command?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Posts
    91

    if (not) command?

    Hi i got a tiny question about those basic stuff.

    There are "If textbox1.text ="" then
    msgbox ="correct" " commands

    But is there any "force" command like

    "If text1.text ="122" then
    msgbox ="It must be 123" ?

  2. #2
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: if (not) command?

    Your question is not clear...
    Code:
    If text1.text="122" then 
    msgbox "it has to be 123 like this"
    text1.text="123"
    end if
    or
    Code:
    If text1.text="122" then 
    msgbox "it has to be 123 , plase do type it!!!"
    text1.selstart=0
    text1.sellength=len(text1.text)
    text1.setfocus
    exit sub   'exit the sub (means not executing anyother code below here in that sub"
    end if

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: if (not) command?

    Or perhaps this which won't allow the user to leave Text1 until it's correct.

    Code:
    Private Sub Text1_Validate(Cancel As Boolean)
    
        If Text1.Text <> "123" Then
            MsgBox "Text1 Must be 123"
            Cancel = True
        End If
        
    End Sub

  4. #4
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: if (not) command?

    If you want to "force" a user to input "123" and nothing else is accepted then why even have the user enter anything at all? Just put "123" in the Textbox and lock it so user can't change it.

  5. #5
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: if (not) command?

    Quote Originally Posted by jmsrickland
    If you want to "force" a user to input "123" and nothing else is accepted then why even have the user enter anything at all? Just put "123" in the Textbox and lock it so user can't change it.
    I'm guessing that the OP wants to create a password verifier.

  6. #6
    Hyperactive Member
    Join Date
    Jan 2006
    Location
    Pakistan
    Posts
    388

    Re: if (not) command?

    Or you could verify it like this too. Its the same as the other methods, only I would consider it more user friendly.
    Code:
    Dim holdcursor As Boolean
    holdcursor = False
    If Text1.Text <>"123" Then     'or whatever you want it to be
       MsgBox "Incorrect value. The value needs to be 123."
       'here it is your choice to follow either way of those below
       'if you want to "force" your value
       Text1.Text = "123"
       'and if you simply want to put the cursor back to the textbox and verify it
       holdcursor = True
    Else
       holdcursor = False
    End If
    
    Private Sub Text1_LostFocus()
       If holdcursor Then Text1.SetFocus
    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