Results 1 to 11 of 11

Thread: [RESOLVED] Degree Minit Second in Visual Basic

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2024
    Posts
    24

    Resolved [RESOLVED] Degree Minit Second in Visual Basic

    I have 2 angle

    A = 100 degree, 40 minutes 10 seconds
    B = 90 degree, 50 minutes 00 seconds

    How to I can calculate it using visual basic to get the differences between these angle (A - B) . I have no idea in writing a code.

  2. #2
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,186

    Re: Degree Minit Second in Visual Basic

    I'm not sure your question is terribly language specific. It seems to be more about understanding surveying-type measurements and floating point numbers in any modern language. Also, there needs to be some fundamental understanding of how trigonometry works.

    But anyway, I just knocked this out on my Surface Tablet (in the default Form1's code):

    Code:
    Option Explicit
    
    Private Sub Form_Load()
        Dim degA As Long, minA As Long, secA As Long
        Dim degB As Long, minB As Long, secB As Long
        
        degA = 100
        minA = 40
        secA = 10
        
        degB = 90
        minB = 50
        secB = 0
        
        Dim dblA As Double, dblB As Double
        
        dblA = DegMinSecToDbl(degA, minA, secA)
        
        dblB = DegMinSecToDbl(degB, minB, secB)
        
        Dim dbl_answer As Double
        Dim deg_answer As Long
        Dim min_answer As Long
        Dim sec_answer As Long
        
        dbl_answer = dblA - dblB
        
        DblToDegMinSec dbl_answer, deg_answer, min_answer, sec_answer
        
        Debug.Print deg_answer, min_answer, sec_answer
        
        
        
    End Sub
    
    Public Function DegMinSecToDbl(deg As Long, min As Long, sec As Long) As Double
        DegMinSecToDbl = CDbl(deg) + CDbl(min) / 60# + CDbl(sec) / 3600#
    End Function
    
    Public Sub DblToDegMinSec(ByVal dbl As Double, deg_out As Long, min_out As Long, sec_out As Long)
        deg_out = Fix(dbl)
        dbl = dbl - CDbl(deg_out)
        min_out = Fix(dbl * 60#)
        dbl = dbl - CDbl(min_out) / 60#
        sec_out = CLng(dbl * 3600#)
    End Sub
    I didn't take any consideration of positive and negative numbers, nor the fact that degrees wrap when they hit 360.

    Also, just as a heads-up, all the trig functions in VB6 (or, pretty much any computer language for that matter) expect radians, not degrees. But that's not an issue here (but it probably will be if you do much more with this).
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  3. #3
    Fanatic Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    1,016

    Re: Degree Minit Second in Visual Basic

    This can be done directly without performing any conversion. Consider something like (not tried as I don't use VB):

    Code:
    Dim degA As Long, minA As Long, secA As Long
    Dim degB As Long, minB As Long, secB As Long
    Dim degR As Long, minR As Long, secR As Long
        
    degA = 100
    minA = 40
    secA = 10
        
    degB = 90
    minB = 50
    secB = 0
    
    secR = secA - secB
    If secR < 0 Then
        secR = secR + 60
        minA = minA - 1
    
        If minA < 0 Then
            minA = minA + 60
            degA = degA - 1
        End If
    End if
    
    minR = minA - minB
    If minR < 0 Then 
        minR = minR + 60
        degA = degA - 1
    End if
    
    degR = degA - degB
    
    Debug.Print degR, degM, degS
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  4. #4
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,892

    Re: Degree Minit Second in Visual Basic

    @Elroy, did you also get a Surface tablet over an Android or iPad option just so you could run your VB6 stuff on it?

    I finally got to play with code for touch UIs, autorotation, and radios.

  5. #5
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,186

    Re: Degree Minit Second in Visual Basic

    Quote Originally Posted by fafalone View Post
    @Elroy, did you also get a Surface tablet over an Android or iPad option just so you could run your VB6 stuff on it?

    I finally got to play with code for touch UIs, autorotation, and radios.
    I've had this Surface that lives on my spot at the breakfast table for a few years now. It's got an i5 8259U 8-core, running at 1.6GHz. For reading the news and replying to VBForums posts while I eat breakfast, it works pretty well. I've gone through a few keyboards, as they seem to crap-out after a couple of years. But the Surface itself is hanging in there.

    And the VB6 IDE runs absolutely fine on this thing. So it's great for knocking out (and testing) little code snippets for making VBForums replies.

    Before this, I had a Samsung Android tablet that lived here, that I absolutely hated, and was glad to toss it when I got this Surface.

    My wife is a huge Apple fan. On her side of the breakfast table lives one of those large-screen iPads. I very recently finally went to an iPhone, but I'm not really an Apple person. The main reason I finally went to an iPhone is so I could use the AirTags and also share my location with other family members (in case I wander off and forget who i am).
    Last edited by Elroy; Mar 25th, 2024 at 06:44 AM.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  6. #6
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,186

    Re: Degree Minit Second in Visual Basic

    Quote Originally Posted by 2kaud View Post
    This can be done directly without performing any conversion. Consider something like (not tried as I don't use VB):
    Yeah, I thought about that. It would stay with integer math that way (and be faster for + and -). But, I figured it'd ultimately involve some trig, and calling any of those functions would take floating point numbers, so I thought converting was probably best.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  7. #7
    Addicted Member
    Join Date
    Jul 2021
    Posts
    201

    Re: Degree Minit Second in Visual Basic

    My solution would be:
    Code:
    Dim dif As Date
    Dim Degree As Long, Minutes As Long, Seconds As Long
    dif = TimeSerial(100, 40, 10) - TimeSerial(90, 50, 0)
    Seconds = Second(dif)
    Minutes = Minute(dif)
    Degree = Hour(dif) + Int(dif) * 24

  8. #8
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,186

    Re: Degree Minit Second in Visual Basic

    Quote Originally Posted by Dry Bone View Post
    My solution would be:
    Code:
    Dim dif As Date
    Dim Degree As Long, Minutes As Long, Seconds As Long
    dif = TimeSerial(100, 40, 10) - TimeSerial(90, 50, 0)
    Seconds = Second(dif)
    Minutes = Minute(dif)
    Degree = Hour(dif) + Int(dif) * 24
    I thought about that too. But done that way, you don't wind up with a floating-point number that you can stick into the trig functions. The return of TimeSerial (cast to a double) is always less-than-one. In other words, the actual degrees wind up as a fraction.

    To use TimeSerial to make a floating-point double that could truly be considered degrees, you'd have to do something like:

    Code:
    Dim d As Double
    d = TimeSerial(0, min, sec) * 24# + deg
    Not tested, air-code.

    And the inverse would require similar gyrations.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  9. #9
    Addicted Member
    Join Date
    Jul 2021
    Posts
    201

    Re: Degree Minit Second in Visual Basic

    Quote Originally Posted by Elroy View Post
    The return of TimeSerial (cast to a double) is always less-than-one.
    No it's not.

  10. #10
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,186

    Re: Degree Minit Second in Visual Basic

    Quote Originally Posted by Dry Bone View Post
    No it's not.
    Ok, you're right if you've got more than 24 degrees. But Int(Your_TimeSerial) is not the degrees. It's just how many multiples of 24 degrees you have, which relates to nothing related to trig or surveying.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Mar 2024
    Posts
    24

    Re: Degree Minit Second in Visual Basic

    Thank you

Posting Permissions

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



Click Here to Expand Forum to Full Width