B4R Question How to get the Index of an Array

Discussion in 'B4R Questions' started by pokhraj_d, Oct 26, 2018.

  1. pokhraj_d

    pokhraj_d Member

    Hello All,
    I am trying to parse NMEA sentence in GPS.
    The below is the GPS NMEA:
    Code:
    $GPGGA,194530.000,3051.8007,N,10035.9989,W,1,4,2.18,746.4,M,-22.2,M,,*6B
    Below is my Code:
    Code:
    #Region Project Attributes
        
    #AutoFlushLogs: True
        
    #CheckArrayBounds: True
        
    #StackBufferSize: 300
    #End Region

    Sub Process_Globals
        
    'These global variables will be declared once when the application starts.
        'Public variables can be accessed from all modules.
        Public Serial1 As Serial
        
    Private bc As ByteConverter
        
    Private nmea() As Byte="$GPGGA,194530.000,3051.8007,N,10035.9989,W,1,4,2.18,746.4,M,-22.2,M,,*6B"
    End Sub

    Private Sub AppStart
        Serial1.Initialize(
    115200)
        
    Log("AppStart")
        
    For Each s() As Byte In bc.Split(nmea,",")
            
    Log("The value of NMEA :",s)
        
    Next
    End Sub
    And this is the result I got which is fine:
    ===============
    The value of NMEA :$GPGGA
    The value of NMEA :194530.000
    The value of NMEA :3051.8007
    The value of NMEA :N
    The value of NMEA :10035.9989
    The value of NMEA :W
    The value of NMEA :1
    The value of NMEA :4
    The value of NMEA :2.18
    The value of NMEA :746.4
    The value of NMEA :M
    The value of NMEA :-22.2
    The value of NMEA :M
    The value of NMEA :
    The value of NMEA :*6B
    ================
    But I want the index of each element of the array like below :
    ===============
    The value of NMEA :$GPGGA -> Index 0
    The value of NMEA :194530.000 -> Index 1
    The value of NMEA :3051.8007 -> Index 2
    ==============
    How can I achieve this? Please advice.

    Thanks-
    Pokhraj Das
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Code:
    Dim Index As Int = 0
     
    For Each s() As Byte In bc.Split(nmea,",")
            
    Log("The value of NMEA :",s, " index: ", Index)
            Index = Index + 
    1
        
    Next
     
    Last edited: Oct 28, 2018
  3. BillMeyer

    BillMeyer Active Member Licensed User

    Hmmm - I think that Index = Index = 1 might just need to be Index = Index + 1 - although I could be wrong :p
     
    Erel likes this.
  4. Erel

    Erel Administrator Staff Member Licensed User

    Oops...
     
    BillMeyer likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice