Results 1 to 9 of 9

Thread: How to place all textbox numeric updowndata in single string for UART Tx

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2016
    Posts
    11

    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

  2. #2
    Frenzied Member Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Skunthorpe, North Lincolnshire, England.
    Posts
    1,830

    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 2
    2
    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.
    Last edited by Shaggy Hiker; Feb 17th, 2016 at 05:02 PM.
    Along with the sunshine there has to be a little rain sometime.

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,953

    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)())

  4. #4
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,252

    Re: How to place all textbox numeric updowndata in single string for UART Tx

    Quote Originally Posted by jmcilhinney View Post
    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}~"

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2016
    Posts
    11

    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 View Post
    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 2
    2
    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.

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    35,023

    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.
    My usual boring signature: Nothing

  7. #7
    Frenzied Member Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Skunthorpe, North Lincolnshire, England.
    Posts
    1,830

    Re: How to place all textbox numeric updowndata in single string for UART Tx

    Quote Originally Posted by Shaggy Hiker View Post
    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.
    Last edited by Poppa Mintin; Feb 17th, 2016 at 07:43 PM. Reason: Typo.
    Along with the sunshine there has to be a little rain sometime.

  8. #8
    Frenzied Member Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Skunthorpe, North Lincolnshire, England.
    Posts
    1,830

    Re: How to place all textbox numeric updowndata in single string for UART Tx

    Quote Originally Posted by cfcorp View Post
    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.
    Along with the sunshine there has to be a little rain sometime.

  9. #9
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    35,023

    Re: How to place all textbox numeric updowndata in single string for UART Tx

    Quote Originally Posted by Poppa Mintin View Post
    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.
    My usual boring signature: Nothing

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width