Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text conversion to numeric

Status
Not open for further replies.

ranshe

Programmer
Oct 5, 2004
27
0
0
US
I have a text field on a form.
It is for entry of a number which I use in a calculation.
When I use it in an expression like Some_integer - Text1 it gives the message "Argument not optional and highlights Text1.
When I try the command data_numeric=Val(text1.text) it gives me an error saying "Method or data member not found and highlights: ".text". It does the same with CStr.
Both of these were suggested to me but i must not have the syntax down right.
data_numeric=Val(text1) doesn't work either.

Any suggestions?
 
It sounds like Text1 is not a textbox. To be sure, add this code to the form_load event and report back the results.

MsgBox TypeName(Text1)

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Firstly, where do you have the code? Make sure it is in the code module that belongs to the Form.

Secondly, if VB gave you the second error then are you sure Text1 is a text box? It seems more likely that you are using a Label to me but then the first error would not make sense.

What you need to do is paste your code exactly as it is in your project.

Cheers
 
You could also look in your properties window for Text1, and it will tell you what type of control it is.

Bob
 
Well,
Don't ask me how, I guess i was up programming to late last night, but the Text1 had an Index set on it and was seeing it as Text1(2) and not as Text1. I should of noticed that but suffered from brain drain. When i tried "gmmastros" sugestion and put MsgBox TypeName(Text1) in the Load Form I discovered my problem because it did not find the name Text1.

Very sorry for wasting everyone's tome.

Thanks anyway.
It did help though.
 
ahh we should have been able to work that out from the symptoms! Drat

It was clear that it was not a text box but why would a label be called a named Text1? That's why I was suspect of my guess. I never thought of an index on the control :)
 
I'm glad that my suggestion, while not completely on mark, did lead you to discovering your problem for yourself.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top