# Thread: [RESOLVED] Degree Minit Second in Visual Basic

1. ## [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. ## 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

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)

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

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

4. ## 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. ## Re: Degree Minit Second in Visual Basic

Originally Posted by fafalone
@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).

6. ## Re: Degree Minit Second in Visual Basic

Originally Posted by 2kaud
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.

7. ## 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. ## Re: Degree Minit Second in Visual Basic

Originally Posted by Dry Bone
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.

9. ## Re: Degree Minit Second in Visual Basic

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

10. ## Re: Degree Minit Second in Visual Basic

Originally Posted by Dry Bone
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.

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