RE: Obtaining direction from course heading

Discussion in 'Questions (Windows Mobile)' started by wm.chatman, Feb 19, 2009.

  1. wm.chatman

    wm.chatman Well-Known Member Licensed User

    Hello Folks

    Would you could you be kind enough, to help this Mann that does not know enough???

    I have been trying to implement this function. (Obtaining direction from course heading).

    This function returns a string direction such as "north," "east southeast," etc from a heading between 0 and 360 degrees.

    Sub getDirection(COG)
    Dim direction
    if COG >= 0 And COG <= 11.25 Then direction = "north"
    if COG > 348.75 and COG <= 360 Then direction = "north"
    if COG > 11.25 and COG <= 33.75 Then direction = "north northeast"
    if COG > 33.75 And COG <= 56.25 Then direction = "northeast"
    if COG > 56.25 And COG <= 78.75 Then direction = "east northeast"
    if COG > 78.75 And COG <= 101.25 Then direction = "east"
    if COG > 101.25 And COG <= 123.75 Then direction = "east southeast"
    if COG > 123.75 And COG <= 146.25 Then direction = "southeast"
    if COG > 146.25 And COG <= 168.75 Then direction = "south southeast"
    if COG > 168.75 And COG <= 191.25 Then direction = "south"
    if COG > 191.25 And COG <= 213.75 Then direction = "south southwest"
    if COG > 213.75 And COG <= 236.25 Then direction = "southwest"
    if COG > 236.25 And COG <= 258.75 Then direction = "west southwest"
    if COG > 258.75 And COG <= 281.25 Then direction = "west"
    if COG > 281.25 And COG <= 303.75 Then direction = "west northwest"
    if COG > 303.75 And COG <= 326.25 Then direction = "northwest"
    if COG > 326.25 And COG <= 348.75 Then direction = "north northwest"
    return direction
    End Sub

    :BangHead:I know we can use this with the GPS library to determine direction. Yust cant figure it out. How can i bind Sub getDirection(COG) with lblDirection?


    I want to use a Label(lblDirection)to show the Direction, on the Form.
    The App is running but..
    I added the source code into the main Module.
    Question? What am I missing and or forgetting here, because i can not get this to fire up.

    Thank you for the Effort to help!!!:)

    WmC

    PC: Laptop CoreDUo, Windows XP SP2 E
    PPC:hp5550"ARM"/Windows CE 4.2
    Bayern, Germany
     
    Last edited: May 19, 2009
  2. Erel

    Erel Administrator Staff Member Licensed User

    I've implemented your function in a different way:
    Code:
    Sub Globals
        
    Dim directions(0)
        directions() = 
    Array("north","north northeast","northeast","east northeast", _ 
            
    "east""east southeast""southeast""south southeast""south""south southwest", _ 
            
    "southwest""west southwest""west""west northwest""northwest""north northwest")
    End Sub

    Sub App_Start
        lblDirection.Text = getDirection(numericDirection) 
    End Sub

    Sub getDirection (COG)
        
    Dim direction
        direction = directions(Int(((COG + 
    11.25Mod 360)/22.5))
        
    Return direction
    End Sub
    This line: lblDirection.Text = getDirection(numericDirection)
    Sets the label text to the value returned from the function.
     
  3. wm.chatman

    wm.chatman Well-Known Member Licensed User

    Hello Erel

    Ein Herzliches Dankeschoen for your help!

    I've implemented your function to the App. Got a error saying:
    Objekt reference not set to an instance of an object.(see pic1)
    also lblDirection on the Main Form did not respond. So...

    In Sub Globals I then added (Dim numericDirection). The response was lblDirection gave out (north), with a freeze like Reation.
    lblDirection did NOT RESPOND, we do not have a function.
    (see pic2) on this.
    Question: Can a Timer Tick help here? Are there yet a small item i am missing?

    Thank you for the Effort to help Erel!!!

    WmC

    Greetings from Bayern Germany to all.

    PC: Laptop CoreDUo, Windows XP SP2 E
    PPC:hp5550"ARM"/Windows CE 4.2
    Bayern, Germany
     
    Last edited: May 19, 2009
  4. Erel

    Erel Administrator Staff Member Licensed User

    You should replace 'numericDirection' with the variable that holds the GPS direction.
     
  5. wm.chatman

    wm.chatman Well-Known Member Licensed User

    Hello Erel

    Again, Dankeschoen for your help!

    I've worked on your function to the App on the Weekend, and i am still taping in the Dark.

    Such a small thing but i just can not shake hands with this variable function, that holds the GPS direction. I know now, that it is not all that simple to work with GPS.
    Must say i am just a might TEED OFF at myself. But...

    I hope you do not mind Erel, i uploaded the App. Could you please take a'peak'for me?
    It took myself 11 Years to get PAT on VB4-6 working Databanks. NMEA and GPS is new to me.
    We are willing to learn, and this is a great Site to do so, and if i may say so:
    A prior Statement from myself, was uncalled for. I would like to Apologize for that.

    Thank you for the Effort to help Erel!!!

    WmC

    Greetings from Bayern Germany to all.

    PC: Laptop CoreDUo, Windows XP SP2 E
    PPC:hp5550"ARM"/Windows CE 4.2
    Bayern, Germany
     
    Last edited: May 19, 2009
  6. wm.chatman

    wm.chatman Well-Known Member Licensed User

    Hello Erel

    Again, Dankeschoen for your help but I don't understand the solution.

    WmC

    Greetings from Bayern Germany to all.

    PC: Laptop CoreDUo, Windows XP SP2 E
    PPC:hp5550"ARM"/Windows CE 4.2
    Bayern, Germany
     
  7. agraham

    agraham Expert Licensed User

    You have this "lblDirection.Text = getDirection(numericDirection)" in AppStart where it only gets executed once :( Also "numericDirection" never gets updated anyway :confused:

    You need to put the label update in the "GPS_GPSDecoded" and use the updated course.

    Code:
    If GPS.CourseOverGround <> "" Then
        Rotate(
    GPS.CourseOverGround) 'Rotate the compass arrow.
        lblCourse.Text = Round(GPS.CourseOverGround)
        [COLOR=
    "Red"]lblDirection.Text = getDirection(lblCourse.Text ) [/COLOR] 
    End If
     
  8. wm.chatman

    wm.chatman Well-Known Member Licensed User

    Dankeschoen an Erel und Agraham

    Hi Erel and agraham

    Thanks very much for your responses.
    I came near to this solution, but was not quite right yet.:sign0161:

    Again, Thank you for your time help and effort!!!

    Sinceraly,
    WmC

    PC: Laptop CoreDUo, Windows XP SP2 E
    PPC:hp5555"ARM"/Windows CE 4.2
    Bayern/Germany
     
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