Solved

Focus()

Posted on 2004-10-13
6
296 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
count8 challlenge 13 119
changePi Challenge 15 107
tidtcpserver connection lost handle 2 71
Currency Conversion? 1 73
A short article about a problem I had getting the GPS LocationListener working.
This is an explanation of a simple data model to help parse a JSON feed
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

867 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now