Results 1 to 9 of 9

Thread: com buffer to different variables(vb6)

  1. #1
    Variable Bitrate gameboy's Avatar
    Join Date
    May 2005
    Location
    Elizabeth City, NC
    Posts
    294

    com buffer to different variables(vb6)

    i'm a total newb at VB6. i've done a few simple things but have no idea how to do this. I can connect to the com1 and recieve data, but do not know how to parse the data.


    what i'm trying to write a little program to take the diagnostic feed from the DSATX power supply, and place them in different variables?

    the string comming from the com port looks like this:

    +030.3:12.56:12.00:05.19:03.34:10.49:0560:YNYY:3:0 558
    +030.3:12.56:12.00:05.19:03.34:10.49:0560:YNYY:3:0 558
    +030.3:12.56:12.00:05.19:03.34:10.49:0560:YNYY:3:0 558
    +030.3:12.56:12.00:05.19:03.34:10.49:0560:YNYY:3:0 558

    and while it is in diagnostic feed mode that information will continue to spit out. the infromation is seperated by :.

    how can i seperate it into different variables?
    PS Temeratures - +0.30.3
    Input voltage - 12.56
    etc.....
    95 Mazda Protege LX
    Worklog
    Overall [Project Dead] 0%

    2003 Nissan Altima
    [XXXXXXXX--] 80% Planning
    [XX--------] 20% FABRICATION/INSTALLATION

    Worklog

  2. #2
    Newbie
    Join Date
    Sep 2006
    Posts
    17
    Very simple!

    Heres some code from the top of my head that will split it into an array for you!

    Data being the strings your receiving.
    Code:
    Dim Test(8) as string '0-8 = 9
    
    Test = Split(Data,":")
    
    msgbox Test(0) 
    msgbox Test(1) 
    msgbox Test(2) 
    msgbox Test(3) 
    msgbox Test(4) 
    msgbox Test(5)
    'continue to 8
    
    'to put each data into its own variable just simply do
    'VariableName = test(3) 'or whatever number holds the data you want!
    if the data is not always in the same format it will cause errors let me know!

    By the way if you then need to seperate the data by . just do it again
    Code:
    Dim test2() as string
    test2 = split(test(0), ".")
    msgbox test2(0)
    msgbox test2(1)
    Hope this helpped.

  3. #3
    Variable Bitrate kamikaze2112's Avatar
    Join Date
    Feb 2005
    Location
    Barrie Ontario
    Posts
    406
    You've got the right idea, but then there's no way of telling what is what. What happens if you open the com port mid stream? What you need to do is look for the beginning of the stream (the + sign by the looks of things) and then starting to do what you were saying with the split function. The other problem that you might run into is missing data. you need to know how you are going to handle that as well.


  4. #4
    Newbie
    Join Date
    Sep 2006
    Posts
    17
    lol well he wasn't that specific, if you really want to add checks its simple.

    Code:
    if Mid(Data,1,1) = "+" then
     'continue with split
    end
    Split is really a horrible function if theres missing data because it spits out errors.. thats why i said if the format isn't consistant it will have problems. Theres other ways to do it so let me know.

    Will there ever be bunched up data?

    Honestly, if you really want to do it right I would use InStr() to search + then have it copy the rest of the data from there or untill it finds another +.

  5. #5
    Newbie
    Join Date
    Jul 2006
    Posts
    37
    You should also look at using perl, which can be downloaded at activeperl.com.

    It's extermely flexable and forgiving!

  6. #6
    Variable Bitrate gameboy's Avatar
    Join Date
    May 2005
    Location
    Elizabeth City, NC
    Posts
    294
    thanks for the replys...more questiosn

    what if i tossed out the first buffer dump? and started with the next line, that should eliminate the starting mid stream right?

    i'm prob only going to poll the information once every 5-10 seconds or so. the information is not that criticial(i dont think).

    also the + at the begining could be a - or nothing as it is a temp reading. and here it does get below 0C
    95 Mazda Protege LX
    Worklog
    Overall [Project Dead] 0%

    2003 Nissan Altima
    [XXXXXXXX--] 80% Planning
    [XX--------] 20% FABRICATION/INSTALLATION

    Worklog

  7. #7
    Variable Bitrate gameboy's Avatar
    Join Date
    May 2005
    Location
    Elizabeth City, NC
    Posts
    294
    Quote Originally Posted by Vexus View Post
    Very simple!

    Heres some code from the top of my head that will split it into an array for you!

    Data being the strings your receiving.
    [code]
    Test = Split(Data,":")
    i get an copmile error on that line - cant assign to array
    95 Mazda Protege LX
    Worklog
    Overall [Project Dead] 0%

    2003 Nissan Altima
    [XXXXXXXX--] 80% Planning
    [XX--------] 20% FABRICATION/INSTALLATION

    Worklog

  8. #8
    Newbie
    Join Date
    Sep 2006
    Posts
    17
    Sorry about that, just make Test(8), Test()

  9. #9
    Variable Bitrate gameboy's Avatar
    Join Date
    May 2005
    Location
    Elizabeth City, NC
    Posts
    294
    Quote Originally Posted by Vexus View Post
    Sorry about that, just make Test(8), Test()
    ty
    95 Mazda Protege LX
    Worklog
    Overall [Project Dead] 0%

    2003 Nissan Altima
    [XXXXXXXX--] 80% Planning
    [XX--------] 20% FABRICATION/INSTALLATION

    Worklog

Similar Threads

  1. Idea - Sound Buffer (faux fast boot) ??
    By SoulCoughy in forum Hardware Development
    Replies: 7
    Last Post: 09-03-2005, 09:48 AM
  2. D3 SDK GPS buffer how to use ?
    By CdRsKuLL in forum Software & Software Development
    Replies: 8
    Last Post: 08-10-2005, 02:45 AM
  3. Car Cameras - Create a buffer of 1 hour of recorded video?
    By dualfragment in forum Software & Software Development
    Replies: 32
    Last Post: 01-07-2005, 04:43 PM
  4. 2mb Buffer Hard Drive?
    By johnnyutah36 in forum General Hardware Discussion
    Replies: 3
    Last Post: 08-03-2004, 10:19 PM
  5. Anyone understand Java ? I need help.
    By frodobaggins in forum Software & Software Development
    Replies: 31
    Last Post: 05-24-2004, 11:53 PM

Bookmarks

Posting Permissions

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