Active Server Pages Programming (ASP)/Can't get data from a text box

Advertisement


Question
QUESTION: Private Sub Texta_KeyPress(KeyAscii As Integer)
'Dim dta1 As Integer
'Dim dta2 As Integer
'tryagain!Texta.Text   'compile error, invalid use of property
'Texta.Text          'same as above
'dta1.Text          'compile error, invalid qualifier
'dta1 = Text          'No error. Keyed input shows in the text box but nothing in text or dta1
'dta2 = dta1
'Object text box is Texta      Procedure text box is keypress

'I'm using VB6.0 Professional edition, 1991 - 99. Operating system is windows vista.   I want to
'enter data from the keyboard into the text property of the (only) text box(texta) on the only
'form(tryagain)in my program. Then I want to put the data into dta1.

'Can you provide the correct code/advise?  If so, please quote your rates.  Thank you.
'Ron Lowe   I use  B/A Visa

ANSWER: Try this:

Private Sub Texta_KeyPress(KeyAscii As Integer)
Dim dta1 As Integer
Dim dta2 As Integer
dta1 = Texta.text          'dta1 is a variable. It does not have the TEXT property
dta2 = dta1
End Sub

---------- FOLLOW-UP ----------

QUESTION: Tried the above.  Compiled ok, but at run time when I entered a number from the keyboard, program stopped and I got the error message" Run time error '13':
        Type mismatch

The Debug highlights:    dta1 = texta.text

Help says variable or property isn't of the correct type, etc..

I've been trying to solve this problem for weeks.  I'm new to VB. I would really appreciate some direction.  
Thank you for your consideration and time.
Ron

Answer
Hi,

If you type some other character other than, you would have got this error, because dta1 is declared as Integer.

My personal opinion is, it is not a good idea to store the value in keypress event, you may try with lostfocus event or keydown event. Try the same code in lostfocus event. Don't forget to comment the keypress event completely.

Let me know how it works.

Active Server Pages Programming (ASP)

All Answers


Answers by Expert:


Ask Experts

Volunteer


Hari Priya

Experience

I have 3+ years experience in ASP. I can answer all ASP questions and databases questions in MSAccess and MSSQL. Please do not ask ASP.NET questions.

Organizations
I work as a Software Engineer in Coimbatore.

Education/Credentials
B.Sc. Chemistry, Master of Computer Education (MCA)

Past/Present Clients
I don't have any direct clients. I am a volunteer in many websites like this. Please bookmark these websites: http://delicious.com/haripriya2007

©2012 About.com, a part of The New York Times Company. All rights reserved.