How to place all textbox numeric updowndata in single string for UART Tx
Hi,
As the title suggests I would like to know how to add all the data from various textboxes or numeric up/down boxes into one string using say a single apply button for transmission to uart. Currently i have a few 'OK' buttons that send the data separately using serialport.write etc.
Also given that can I add between the different data from different boxes an A or B etc so I can differentiate the data on the other side, while having everything sent at once?
all the data will be numerics floats or integers values. so A200B12.5C60D0.01 etc would be perfect where the data is separated by letters.
Any help will be greatly appreciated
thanks
Re: How to place all textbox numeric updowndata in single string for UART Tx
Hi cfcorp,
Firstly all data will have to be 'String', you can't put numerical data into a String, that's not to say you can't send numeric data, just that it will be in characters not as Integers, Doubles, etc.
You will have to convert them back to their required variable type 'at the other end'.
Typical coding for this would look something like this:
Dim sendWord as String = ""
sendWord += Integer_A.ToString & "~"
sendWord += Integer_B.ToString & "~"
sendWord += Long_C.ToString & "~"
sendWord += String_D & "~"
sendWord += Double_E.ToString & "~"
Then you would transmit sendWord.
I've used the character ~ just as an example, you can use any character that's not likely to ever be part of the data, it's there to separate the individual data. You'd probably want to leave off the ~ after the final data.
There's no reason why you can't use a loop to add data to your string.
For i = 0 to 22
sendWord += Integer_F(i).ToString & "~"
Next
sendWord += Integer_F(23).ToString
Hope this gives you some ideas.
Poppa.
@ ADMINISTRATORS
I don't know what's going on here.
Every time I wrap the code in 'code' square brackets the preview adds extra sets of code brackets so that the code gets broken into two pieces! That's both sets of code, ie. four code wraps.
I tried VB.NET brackets and it was much worse, adding color brackets as well.
Then, going back to where I've written the post, all the extra brackets have been added there too !
So... As you can see, I've had to leave the code snippets unwrapped.
Poppa.
Re: How to place all textbox numeric updowndata in single string for UART Tx
This:
Code:
Dim sendWord as String = ""
sendWord += Integer_A.ToString & "~"
sendWord += Integer_B.ToString & "~"
sendWord += Long_C.ToString & "~"
sendWord += String_D & "~"
sendWord += Double_E.ToString & "~"
would be better written like this:
Code:
Dim sendWord = String.Format("{0}~{1}~{2}~{3}~{4}~",
Integer_A,
Integer_B,
Long_C,
String_D,
Double_E)
and this:
Code:
For i = 0 to 22
sendWord += Integer_F(i).ToString & "~"
Next
sendWord += Integer_F(23).ToString
would be better written like this:
Code:
sendWord = String.Join("~", Integer_F.Cast(Of Object)())
Re: How to place all textbox numeric updowndata in single string for UART Tx
Quote:
Originally Posted by
jmcilhinney
would be better written like this:
Code:
Dim sendWord = String.Format("{0}~{1}~{2}~{3}~{4}~",
Integer_A,
Integer_B,
Long_C,
String_D,
Double_E)
I like the way VS2015 lets you format strings, tho I haven't used it much I believe its simply this,...
Code:
Dim sendWord = $"{Integer_A}~{Integer_B}~{Long_C}~{String_D}~{Double_E}~"
Re: How to place all textbox numeric updowndata in single string for UART Tx
Hi Poppa Mintin,
I tried that and it works absolutely perfectly on VB 2010, thanks you so much
Quote:
Originally Posted by
Poppa Mintin
Hi cfcorp,
Firstly all data will have to be 'String', you can't put numerical data into a String, that's not to say you can't send numeric data, just that it will be in characters not as Integers, Doubles, etc.
You will have to convert them back to their required variable type 'at the other end'.
Typical coding for this would look something like this:
Dim sendWord as String = ""
sendWord += Integer_A.ToString & "~"
sendWord += Integer_B.ToString & "~"
sendWord += Long_C.ToString & "~"
sendWord += String_D & "~"
sendWord += Double_E.ToString & "~"
Then you would transmit sendWord.
I've used the character ~ just as an example, you can use any character that's not likely to ever be part of the data, it's there to separate the individual data. You'd probably want to leave off the ~ after the final data.
There's no reason why you can't use a loop to add data to your string.
For i = 0 to 22
sendWord += Integer_F(i).ToString & "~"
Next
sendWord += Integer_F(23).ToString
Hope this gives you some ideas.
Poppa.
@ ADMINISTRATORS
I don't know what's going on here.
Every time I wrap the code in 'code' square brackets the preview adds extra sets of code brackets so that the code gets broken into two pieces! That's both sets of code, ie. four code wraps.
I tried VB.NET brackets and it was much worse, adding color brackets as well.
Then, going back to where I've written the post, all the extra brackets have been added there too !
So... As you can see, I've had to leave the code snippets unwrapped.
Poppa.
Re: How to place all textbox numeric updowndata in single string for UART Tx
@Poppa: I tried editing your post to add the CODE tags and it showed up as expected. I then removed the edit so as not to make your addition seem peculiar.
Try it again, as it might have just been a temporary glitch.
Re: How to place all textbox numeric updowndata in single string for UART Tx
Quote:
Originally Posted by
Shaggy Hiker
Try it again, as it might have just been a temporary glitch.
Thanks for the reply Shaggy Hiker,
I tried again and got a different result, all the code was in a single line!
So... I deleted it all and started again, but this time I took screenshots to show you what was happening.
I took shots of how it was originally and then how it was with the [] code brackets [\] in place, then I did a preview and it worked properly... I've not been able to get it to go wrong since...
So I've dumped the photos.
Poppa.
Re: How to place all textbox numeric updowndata in single string for UART Tx
Quote:
Originally Posted by
cfcorp
Hi Poppa Mintin,
I tried that and it works absolutely perfectly on VB 2010, thanks you so much
I'm very pleased it worked for you cfcorp, but just an extra word (or two).
1. I'm an old hand at this stuff and too much of an old dog to learn new tricks, so my coding goes back a long way. You should really look at what the younger guys are telling you... There's a good chance my coding won't work for much longer.
2. If you're sure your question is answered, go to the top of this page and find the tab that says (something like) 'Thread Tools'. When you've clicked on that you'll find where you can mark this thread as Resolved. If you do that someone else with a similar problem might be tempted to see if it'll answer their problem too.
Poppa.
Re: How to place all textbox numeric updowndata in single string for UART Tx
Quote:
Originally Posted by
Poppa Mintin
Thanks for the reply Shaggy Hiker,
I tried again and got a different result, all the code was in a single line!
So... I deleted it all and started again, but this time I took screenshots to show you what was happening.
I took shots of how it was originally and then how it was with the [] code brackets [\] in place, then I did a preview and it worked properly... I've not been able to get it to go wrong since...
So I've dumped the photos.
Poppa.
Excellent. It's best when the problems solve themselves.