Math functions

Please share your functions/code-snips

Math functions

Postby pappawinni » Thu Aug 19, 2010 6:44 pm

As I missed the DEG function and also a function to display an angle in degree, Minutes and Seconds,
I created the following.

Code: Select all
function f_Deg( dblRad as double ) as double
  ' converts rad to degree
  dim Pi as double
  PI = atn(1) * 4
  return dblRad * 180.0/PI
end function

function f_strDMS( dblDeg as double ) as string
  ' creates a string from angle in Deg
  ' as angle in Degree, Minutes and Seconds
  ' W. Oestreicher

  dim intG as integer , intM as integer , intSC as integer
  dim dblS as double , dblB as double
  dim strSign as string *2
  dim strOut as string
 
  strSign = iif (dblDeg < 0 , "-", "")

  dblB = round(abs(dblDeg) * 360000)
  intG = dblB \ 360000
  intM = (dblB - intG * 360000) \ 6000
  intSC = (dblB - intG * 360000 - intM * 6000)
  dblS = intSC / 100
 
  if intSC > 0 then
    strOut = strSign & intG & "°" & intM & "'" & dblS & Chr(34)
  elseif intM > 0 then
    strOut = strSign & intG & "°" & intM & "'"
  else
    strOut = strSign & intG & "°"
  end if
 
  return strOut
 
end function

sub Main()
  Dim dblA as double
  dblA = f_deg( CMath.asin(3/4) )
  ? dblA  & "° = " & f_strDMS ( dblA )
end sub

Main()
Last edited by pappawinni on Sun Aug 22, 2010 7:19 pm, edited 6 times in total.
Pappa makes everything what otherwise none likes :)
pappawinni
 
Posts: 192
Joined: Tue Jan 19, 2010 11:27 pm
Location: Germany

Re: Math functions

Postby Slowdown » Thu Aug 19, 2010 7:15 pm

Hi pappawinni,
Code: Select all
dblA = f_deg( CMath.asin(3/4) )

Get an error here :|
Regards
Slowdown for now i'm back
Slowdown
 
Posts: 347
Joined: Sat May 02, 2009 6:48 pm
Location: Netherlands

Re: Math functions

Postby pappawinni » Thu Aug 19, 2010 8:31 pm

You have a different system ?
I use windows, you ?
what happens if you type CMath.
Do You get a selection of possible functions, or not ?

I eleminated CMath function.
Try again.
Pappa makes everything what otherwise none likes :)
pappawinni
 
Posts: 192
Joined: Tue Jan 19, 2010 11:27 pm
Location: Germany

Re: Math functions

Postby Slowdown » Fri Aug 20, 2010 5:26 am

Seems that CMath is working,
CMath.png
CMath.png (12.54 KiB) Viewed 2152 times

Working on OSX, will try it again.
Regards
Slowdown for now i'm back
Slowdown
 
Posts: 347
Joined: Sat May 02, 2009 6:48 pm
Location: Netherlands

Re: Math functions

Postby pappawinni » Sat Aug 21, 2010 7:19 am

Please let me know your findings.
The problem should be created somewhere in the math functions...
so you could may be also test the following:
? atn(1)
? CMath.asin(0.75)
Pappa makes everything what otherwise none likes :)
pappawinni
 
Posts: 192
Joined: Tue Jan 19, 2010 11:27 pm
Location: Germany

Re: Math functions

Postby Slowdown » Sat Aug 21, 2010 9:04 am

Code: Select all
Private Sub Form_OnOpen()
  Dim dblA as double
  dblA = f_deg(CMath.asin(3/4))

  ? dblA  & "° = " & f_strDMS ( dblA )
End Sub

My bad pappawinni,
forgotten the Form_OnOpen :oops:
Regards
Slowdown for now i'm back
Slowdown
 
Posts: 347
Joined: Sat May 02, 2009 6:48 pm
Location: Netherlands

Re: Math functions

Postby pappawinni » Sun Aug 22, 2010 7:16 pm

Hee Slowdown,
you make me crazy :cry:
Who told you to use a project ?
/Winni
Pappa makes everything what otherwise none likes :)
pappawinni
 
Posts: 192
Joined: Tue Jan 19, 2010 11:27 pm
Location: Germany

Re: Math functions

Postby Slowdown » Sun Aug 22, 2010 7:28 pm

pappawinni wrote:Hee Slowdown,
you make me crazy :cry:
Who told you to use a project ?
/Winni

No one told me to use a project but i have a empty project called 'ToTest' and what i always do is copy / past codes from the
forum in that project to test/try them ;)
An error is easily made :oops:
Regards
Slowdown for now i'm back
Slowdown
 
Posts: 347
Joined: Sat May 02, 2009 6:48 pm
Location: Netherlands


Return to User-Functions

cron