Link to home
Start Free TrialLog in
Avatar of freebird317
freebird317

asked on

Focus()

I have a textbox.  txtPassword and I need to clear it and put the focus back on it if a wrong password is entered.  This is what I have coded that does not work...

If txtPassword.text = ""
Messagebox.Show("message here")
txtPassword.backcolor = color.aqua
txtPassword.clear()
txtPassword.focus()
end if

This does not work, how do I code it right?
ASKER CERTIFIED SOLUTION
Avatar of arif_eqbal
arif_eqbal

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of freebird317
freebird317

ASKER

What is happening is if the wrong password is put in then it does not clear the ***** and does not bring the focus back
I believe what you it is an easy  fix. I beleive if you set txtPassword.text .Text = "" 

that will clear any thing in the text box.

Then the call you would want to make is txtPassword.text .SetFocus.

hope that works and  helps
See in case of wrong Password your if clause is not satisfied i.e.

If txtPassword.text = ""

because the TextBox is not Empty so the code to set focus is not run at all.

This code will run only if the textbox is empty

what language are you trying to do this in. It looks like client side VB Script but not sure. If it is try

Change If txtPassword.text = "" to If Not (txtPassword.text = "") then 'or If txtPassword.text <> "" then
ie.
If txtPassword.text <> ""
  Messagebox.Show("message here")
  txtPassword.backcolor = color.aqua
  txtPassword.value = "" or txtPassword.text = ""
  txtPassword.Setfocus()
end if
The reason why the box isn't cleared is because the textfield isn't empty...

What youre are doing is looking if it is empty and then try to clear it... but it isn't empty so It never gets cleared..
Use the folowing cod to fix this.

If txtPassword.text <> ""
  Messagebox.Show("message here")
  txtPassword.backcolor = color.aqua
  txtPassword.text = ""
  txtPassword.Setfocus()
end if