Re: Ping John Larkin



On Fri, 24 Aug 2007 16:55:37 -0700, John Larkin
<jjlarkin@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

I suppose not, since I don't know what VBA is. OK, what *is* VBA?

I wrote an excel spread*** for calculating results of a microwave ham
radio contest I participate in every year. One of the things involved in
the scoring is computing the distance between two points on the earth.
If you want to do that pretty accurately it takes a bit of number
crunching. I had that algorithm in C programs I wrote (adapted from
others more knowledgeable.) Maybe there was a way to port that into
excel without using VBA, but VBA certainly looked like the best way as I
saw it.

Here's an example of one of the functions I added in VBA to my excel
spread***...

---
Function ATan2(y As Double, x As Double) As Double
'
' Returns arctangent (y/x) with results from 0 to 2pi;
' also tolerates x = 0
'
Dim Pi As Double
Pi = 3.14159265359

If x = 0 Then
If y > 0 Then
ATan2 = Pi / 2
Else
ATan2 = -Pi / 2
End If
Else
ATan2 = Atn(y / x)
If x < 0 Then
If y >= 0 Then
ATan2 = ATan2 + Pi
Else
ATan2 = ATan2 - Pi
End If
End If
End If
If ATan2 < 0 Then ATan2 = ATan2 + 2 * Pi
End Function
---

That function was actually called by other VBA functions, but it could
have been called directly from excel spread*** cell formulas. In the
actual implementation, other VBA functions were called from the
spread*** and they called this function to do their computations.

I thought this real example might illustrate the kind of things VBA can
help with.

I also used it to define tools to manipulate the ***, like insert
formatted rows, or to export the *** results to a formatted text file.


.


Quantcast