3

I'm trying to write a VBA function for converting Declination & Right Ascension to their decimal values.

I have a perfectly working function for the RA but keep getting an

Argument not Optional

error.

The function is currently:

Public Function dec2decimal(Deg As Integer, Min2 As Integer, Sec2 As Integer) As Double

    Dim Dec As Double
    Dec = 0
    If Deg >= 0 Then
        Dec = (Deg + Min2 / 60 + Sec2 / 3600)
    Else
        Dec = (Deg - Min2 / 60 - Sec2 / 3600)
    End If

    ra2decimal = Dec
End Function

I'm obviously supplying it three arguements when I run it but its still not happy.

Any ideas?

5
  • 4
    ra2decimal? don't understand. Commented Mar 27, 2013 at 23:39
  • where and how do you call this function, in excel or in vba editor?? Commented Mar 27, 2013 at 23:43
  • 1
    one more suggestion- check the argument separation characters whether you don't mix them up. Commented Mar 27, 2013 at 23:50
  • Seems like I've been an idiot and forgot to change the last ra2decimal to dec2decimal. Thanks all. Commented Mar 28, 2013 at 1:26
  • 1
    @FergusBarker you may want to upvote those who offered their assistance here... Commented Mar 28, 2013 at 1:54

2 Answers 2

1

This is working perfectly fine for me.

Note the revision, change ra2decimal to dec2decimal.

Option Explicit
Sub testDec2Decimal()

MsgBox dec2decimal(1, 1, 1)

End Sub

Public Function dec2decimal(Deg As Integer, Min2 As Integer, Sec2 As Integer) As Double

    Dim Dec As Double
    Dec = 0
    If Deg >= 0 Then
        Dec = (Deg + Min2 / 60 + Sec2 / 3600)
    Else
        Dec = (Deg - Min2 / 60 - Sec2 / 3600)
    End If

    dec2decimal = Dec
End Function
Sign up to request clarification or add additional context in comments.

Comments

1

Check the following:

  • are you sure, you are executing the function which you described, is it possible, that another function in another namespace or class is executed?

  • are you sure you pass the parameters correctly, their type is correct and their number is correct and they are separated by comma?

  • are you sure you didn't make a typo or called the function through a delegate (which is not a problem, but we should know to be able to help you).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.