By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,606 Members | 2,024 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,606 IT Pros & Developers. It's quick & easy.

Converting Strings to decimals and displaying in forms or textbox

P: n/a
RG
I am reading in from a serial port a 16 bit number from 0 to 65536. It
is being read as a string from my microcontroller into VB using DEC5
or 5 digits are displayed. I need to display this value live as a
decimal number so I can manipulate the value.

For instance I have the following line:

TextBox2.Text = buffer1 - 32768

but this generates an error after a few iterations because buffer1 is
a string.
I tried using a label.text also but I get the same problem.

Is there a different control to display numbers?
If not I assume I need to convert.todouble(buffer1).
But this also casues an error.
I also tried converting to double then back to text to display in the
textbox but I am still getting errors.

buffer1 = Convert.ToDouble(buffer1)
buffer1 = buffer1 - 32768
TextBox2.Text = Convert.ToString(buffer1)

Any help would be appreciated.

Mar 19 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
RG wrote:
I am reading in from a serial port a 16 bit number from 0 to 65536. It
is being read as a string from my microcontroller into VB using DEC5
or 5 digits are displayed. I need to display this value live as a
decimal number so I can manipulate the value.

For instance I have the following line:

TextBox2.Text = buffer1 - 32768

but this generates an error after a few iterations because buffer1 is
a string.
I tried using a label.text also but I get the same problem.

Is there a different control to display numbers?
If not I assume I need to convert.todouble(buffer1).
But this also casues an error.
I also tried converting to double then back to text to display in the
textbox but I am still getting errors.

buffer1 = Convert.ToDouble(buffer1)
buffer1 = buffer1 - 32768
TextBox2.Text = Convert.ToString(buffer1)

Any help would be appreciated.

I would try this:

TextBox2.Text = CInt(buffer1) - 32768

or

TextBox2.Text = CDbl(buffer1) - 32768

although I don't see why you are trying to use doubles for this anyway.

T

Mar 19 '07 #2

P: n/a
RG
No Luck
TextBox2.Text = CInt(buffer1) - 32768
error is: Conversion from string "" to type 'Integer' is not valid.

TextBox2.Text = CDbl(buffer1) - 32768
error is: Conversion from string "" to type 'Double' is not valid.

The reason I am using double is because I need to eventually multiply
the value by a decimal.
I would also like to display it with 2 decimal places.

Mar 19 '07 #3

P: n/a
RG wrote:
I am reading in from a serial port a 16 bit number from 0 to 65536. It
is being read as a string from my microcontroller into VB using DEC5
or 5 digits are displayed. I need to display this value live as a
decimal number so I can manipulate the value.

For instance I have the following line:

TextBox2.Text = buffer1 - 32768

but this generates an error after a few iterations because buffer1 is
a string.
I tried using a label.text also but I get the same problem.

Is there a different control to display numbers?
If not I assume I need to convert.todouble(buffer1).
But this also casues an error.
I also tried converting to double then back to text to display in the
textbox but I am still getting errors.

buffer1 = Convert.ToDouble(buffer1)
The conversion works fine, but when you put the value back in the string
variable, it's automatically converted back to a string. You need a
separate varable that is of the type double.
buffer1 = buffer1 - 32768
TextBox2.Text = Convert.ToString(buffer1)

Any help would be appreciated.

--
Göran Andersson
_____
http://www.guffa.com
Mar 20 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.