Extract Weight Value from String

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Norhalim
    New Member
    • Mar 2014
    • 2

    #1

    Extract Weight Value from String

    I use this code to capture weight from Avery weigher indicator through serial com

    Code:
     Private Sub Read_Click()
    'send the Print command and read the weight value.
    NETComm6.Output = "p" & Chr(13) 'send PRINT command to the scale.
    Dim Buffer As String 'define Buffer
        Buffer$ = Buffer$ & NETComm6.InputData 'wait for the data come into the serial port
        WtInfo = Buffer
    End Sub
    And i got this
    80 00 000S99291235 F80 00 000S99291236 E80 00 000S99291237 D80 00 000S99291238 K80 00 000S9929123

    How can I extract the 80 kg to my table field

    Thank you
  • jimatqsi
    Moderator Top Contributor
    • Oct 2006
    • 1293

    #2
    You can break that string into its various parts by using the split() function. If that is a space (it might be some other unprintable character) you can do it like this:
    Code:
    dim Wtarray as variant
    dim Weight as integer  // ?? or whatever is right data type
    Wtarray=split(WtInfo)
    Weight = Wtarray(0)   // assuming the weight is in the 1st position
    Jim

    Comment

    • Norhalim
      New Member
      • Mar 2014
      • 2

      #3
      Thank you for your reply

      I use left(WtInfo,10) instead

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32669

        #4
        There is no "80 kg" within the string. If you specify in your question specifically what it is you are trying to achieve then we can help you. I suspect Jim's answer is a more sensible solution than what you're using but without the details you have as to what it is you actually want it's impossible to say.

        Comment

        Working...