Announcement

Collapse
No announcement yet.

com buffer to different variables(vb6)

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


    • #3
      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.

      Comment


      • #4
        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 +.

        Comment


        • #5
          You should also look at using perl, which can be downloaded at activeperl.com.

          It's extermely flexable and forgiving!

          Comment


          • #6
            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

            Comment


            • #7
              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

              Comment


              • #8
                Sorry about that, just make Test(8), Test()

                Comment


                • #9
                  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

                  Comment

                  Working...
                  X