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

Extract Weight Value from String

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

Expand|Select|Wrap|Line Numbers
  1.  Private Sub Read_Click()
  2. 'send the Print command and read the weight value.
  3. NETComm6.Output = "p" & Chr(13) 'send PRINT command to the scale.
  4. Dim Buffer As String 'define Buffer
  5.     Buffer$ = Buffer$ & NETComm6.InputData 'wait for the data come into the serial port
  6.     WtInfo = Buffer
  7. 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
Mar 17 '14 #1
Share this Question
Share on Google+
3 Replies

Expert 100+
P: 1,240
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:
Expand|Select|Wrap|Line Numbers
  1. dim Wtarray as variant
  2. dim Weight as integer  // ?? or whatever is right data type
  3. Wtarray=split(WtInfo)
  4. Weight = Wtarray(0)   // assuming the weight is in the 1st position
Mar 17 '14 #2

P: 2
Thank you for your reply

I use left(WtInfo,10) instead
Mar 18 '14 #3

Expert Mod 15k+
P: 31,769
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.
Mar 18 '14 #4

Post your reply

Sign in to post your reply or Sign up for a free account.