Solved

Focus()

Posted on 2004-10-13
6
288 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Fibonacci challenge 11 84
word0 challenge 3 58
word0 challenge 4 54
Adding Namespace to the second node of the xml 16 35
This is an explanation of a simple data model to help parse a JSON feed
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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…

747 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

12 Experts available now in Live!

Get 1:1 Help Now