Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17



Posted on 2004-10-13
Medium Priority
Last Modified: 2010-04-17
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
end if

This does not work, how do I code it right?
Question by:freebird317
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 19

Accepted Solution

arif_eqbal earned 60 total points
ID: 12305171
First thing if you'r checking If txtPassword.text = ""
there's no point setting txtPassword.clear()

However that's not an issue, there's nothing in this code it ought to work if there is no other thing which is stopping the focus...


Author Comment

ID: 12305212
What is happening is if the wrong password is put in then it does not clear the ***** and does not bring the focus back

Expert Comment

ID: 12305247
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
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

LVL 19

Expert Comment

ID: 12305268
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


Expert Comment

ID: 12307954
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
If txtPassword.text <> ""
  Messagebox.Show("message here")
  txtPassword.backcolor = color.aqua
  txtPassword.value = "" or txtPassword.text = ""
end if

Expert Comment

ID: 12310010
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 = ""
end if

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Six Sigma Control Plans

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question