having trouble converting textbox into double
-
Monday, May 07, 2012 2:58 AM
I am using two textBox's. The first to enter the data. The second to convert to answer
the program complies with no error, the debugger cannot convert data type from string to double.
Dim douFarhenheit As Double If e.KeyCode = Keys.Return Then douFarhenheit = CDbl(txtFahrenheit.ToString) lblCelsius.Text = CStr(((douFarhenheit - 32) * 5) / 9) End If
why does the program not convert the textbox txtFahrenheit from string to double?
All Replies
-
Monday, May 07, 2012 3:11 AM
It's just not smart enough. What value should CDbl(System.Windows.Forms.TextBox, Text: 123.456) have?
- Proposed As Answer by Heslacher Monday, May 07, 2012 4:51 AM
- Marked As Answer by Mark Liu-lxfModerator Wednesday, May 16, 2012 8:17 AM
-
Monday, May 07, 2012 3:41 AM
It's just not smart enough.
Ha!
John I swear if you weren't such a smarta__ I wouldn't know what do to do!
@Robert--> John is trying to make a good point and teach you something in the doing. Sometime in the next few hours, someone will post a few lines of code which will work ... you'll copy it, paste it, mark it as the answer, and move on.
I will encourage you now not to do that.
Think about what your routine there is essentially saying - and trying to do - and why it's not working. Do you want to learn or do you just want a quick answer so you can move on? The choice is yours.
Either way, I hope you get your program to work like you want. :)
Please call me Frank :)
- Proposed As Answer by Heslacher Monday, May 07, 2012 4:51 AM
- Marked As Answer by Mark Liu-lxfModerator Wednesday, May 16, 2012 8:16 AM
-
Monday, May 07, 2012 4:08 AMI just spent a year at college learning chemistry and I am finishing off the problems. General Chemistry has over 3000 problems that I must answer. I have not scratched the surface on organic chemistry, but I have spent years trying to pass the lab. I would try to go threw all of the function error of the complier, but I do not know how the 5th generation complier was really developed. I just know a little C/C++ and alot of VB. I do know that C++ is an object oriented source code for the objects such as buttons and textboxes. I do not understand there functionality or there min max capabilities. I only studyed programming at school and developed my own Data Chunks at home. I was never taught.
-
Monday, May 07, 2012 4:17 AM
I just spent a year at college learning chemistry and I am finishing off the problems. General Chemistry has over 3000 problems that I must answer. I have not scratched the surface on organic chemistry, but I have spent years trying to pass the lab. I would try to go threw all of the function error of the complier, but I do not know how the 5th generation complier was really developed. I just know a little C/C++ and alot of VB. I do know that C++ is an object oriented source code for the objects such as buttons and textboxes. I do not understand there functionality or there min max capabilities. I only studyed programming at school and developed my own Data Chunks at home. I was never taught.
what John + Frank are trying to tell you is simple.
Q\ what is a textbox? A\ it's a control + controls have Properties
which Textbox Property do you think contains the text?
thanks for any help
- Proposed As Answer by Heslacher Monday, May 07, 2012 4:51 AM
- Marked As Answer by Mark Liu-lxfModerator Wednesday, May 16, 2012 8:16 AM
-
Monday, May 07, 2012 4:23 AM
Robert,
I sense that you took it as a slight; I didn't mean it that way at all. If you took it that way then I proffer my apology.
It's nearly midnight here now so I won't be on long but let me point out a few things that I will implore you to consider, and I'm not suggesting these things to be condescending at all! I mean only to help improve your knowledge and I hope that you understand that.
First of all - your question itself, as stated, makes no sense. You want to convert a textbox (a Windows.Forms.Control) into a type (Double). Think about that one - it makes no sense. What you most likely mean is that you want to convert the text INSIDE that textbox to a type double, and sure that can be done once we qualify that that the user has entered valid data to start with.
Ah yes, that - the validation - I would encourage you to forget the whole keypress thing ... it's pointless and will fire even if they're pressing the backspace key. Let them type in whatever they want to and have a button "Calculate" or some such that you enable/disable when appropriate.
Now that we understand that we want to "convert what they typed in" ... what if they type in a space character? What if they typed in "My dog is asleep" ?
We have ways we can handle all of this, of course, but ... John's point was that you're asking your code, on a keypress when the control is focused, to convert a textbox into a type.
I'm heading off for the night but if you're interested then stay tuned. All of this can be done and the fine folks here can and will show you how to accomplish your manifest end.

Please call me Frank :)
-
Monday, May 07, 2012 4:40 AM
Use the debugger - it is a critical element of your IDE that can save you hours of effort.
Insert a breakpoint at the line where you are doing the conversion of the calculation. When the code stops at that line, open the Watch window. Add these names to the watch window.
txtFahrenheit
txtFahrenheit.ToStringNote the results. They will tell you exactly why the program is not smart enough to work out what you were trying to do with that code. If the Values don't seem to make a lot od sense, look at the Type.
- Edited by AcamarMicrosoft Community Contributor Monday, May 07, 2012 4:41 AM sp
- Proposed As Answer by Heslacher Monday, May 07, 2012 4:51 AM
- Marked As Answer by Mark Liu-lxfModerator Wednesday, May 16, 2012 8:16 AM

