Solved

Focus()

Posted on 2004-10-13
6
303 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
6 Comments
 
LVL 19

Accepted Solution

by:
arif_eqbal earned 20 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupSum6 challenge 6 114
Eclipse with various Java releases 7 51
what is the best Integrated development environment 2 41
Create .bat File 16 73
This is an explanation of a simple data model to help parse a JSON feed
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

726 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