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

x
?
Solved

Focus()

Posted on 2004-10-13
6
Medium Priority
?
306 Views
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
txtPassword.clear()
txtPassword.focus()
end if

This does not work, how do I code it right?
0
Comment
Question by:freebird317
[X]
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
6 Comments
 
LVL 19

Accepted Solution

by:
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...

0
 

Author Comment

by:freebird317
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
0
 

Expert Comment

by:shayne23d
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
0
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

by:arif_eqbal
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

0
 
LVL 5

Expert Comment

by:stumpy1
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
ie.
If txtPassword.text <> ""
  Messagebox.Show("message here")
  txtPassword.backcolor = color.aqua
  txtPassword.value = "" or txtPassword.text = ""
  txtPassword.Setfocus()
end if
0
 
LVL 4

Expert Comment

by:Sicos
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 = ""
  txtPassword.Setfocus()
end if
0

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