473,408 Members | 1,747 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Converting Strings to decimals and displaying in forms or textbox

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
3 3993
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: Adrian Parker | last post by:
I'm using the code below in my project. When I print all of these fixed length string variables, one per line, they strings in questions do not properly pad with 0s. strQuantity prints as " ...
3
by: Ciar?n | last post by:
I have a table with over a million rows and one of the fields contains amounts of money in text format. What is the most efficient way of converting this field to a number format that I can sum...
7
by: Bil Muh | last post by:
Esteemede Developers, I would like to Thank All of You in advance for your sincere guidances. I am developing a software using Visual C++ .NET Standard Edition with Windows Form (.NET)...
7
by: Paul K | last post by:
I'm writing a small component that needs to be as fast as possible. The component needs to convert a string to decimal during the course of it's processing. However, I need to test the string...
0
by: Earl Teigrob | last post by:
I can create a new custom control (and not change it) and add it to the toolbox and drag it onto the disign screen and it works just fine, displaying the text . However, when I add the following...
2
by: moumita | last post by:
I have the folowing code..the logic according to me is correct..but I dont know...the msg boxes are not displaying anything...am I supposed to change any settings ??? Public Class Form1
7
by: Tor Aadnevik | last post by:
Hi, I have a problem converting values from Single to double. eg. When the Single value 12.19 is converted to double, the result is 12.1899995803833. Anyone know how to avoid this? Regards...
3
by: nvx | last post by:
Hi, I'm looking for a simple way to convert a Double to a String exactly the .ToString() does, except these two differences: - the number of decimals is given (rounding is applied if necessary),...
16
by: luca bertini | last post by:
Hi, i have strings which look like money values (ie 34.45) is there a way to convert them into float variables? everytime i try I get this error: "numb = float(my_line) ValueError: empty string...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.