Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Tue May 30, 2017 2:17 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Function in RB
PostPosted: Sun Feb 17, 2013 6:07 am 
Offline
User avatar

Joined: Fri Feb 15, 2013 6:07 am
Posts: 24
Location: Oran, Algeria
Hello,
it's my first time in RB2012, i will start to convert all my applications from VB6 to RBasic.
I would like to Know how to call Func. and how to code it to be used in RB project: This function convert
Decimal deg. to DMS,

Example X=25.51--> 25° 30' 36"

Public Function DecDms(x As Double, xd As Double, xm As Double, xs As Double) As string
Dim s As String
Dim sn As Integer, xp As Double, a As Double
sn = Sgn(x): xp = Abs(x): xd = Int(xp)
a = (xp - xd) * 60: xm = Int(a)
xs = Int((a - xm) * 600 + 0.5) / 10
s = "+"
If sn = -1 Then s = "-"
If xs = 60 Then xs = 0: xm = xm + 1: xs = Int(xs): xm = Int(xm)
If xm = 60 Then xm = 0: xd = xd + 1: xm = Int(xm): xd = Int(xd)
If s = "-" Then xd = xd * -1

End Function


Regards


Top
 Profile  
 
 Post subject: Re: Function in RB
PostPosted: Sun Feb 17, 2013 6:31 am 
Offline

Joined: Mon May 30, 2011 12:56 am
Posts: 702
Looks a lot older code than VB, to be honest.

Most of what needs doing is just lose the colons..

What is it supposed to do? It would be a good idea to change the variable names to be more meaningful.

Public Function DecDms(x As Double, xd As Double, xm As Double, xs As Double) As string
Dim s As String
Dim sn As Integer
dim xp As Double
dim a As Double

sn = Sgn(x)
xp = Abs(x)
xd = Int(xp)

a = (xp - xd) * 60
xm = Int(a)
xs = Int((a - xm) * 600 + 0.5) / 10
s = "+"
If sn = -1 Then s = "-"
If xs = 60 Then xs = 0
xm = xm + 1
xs = Int(xs)
xm = Int(xm)
If xm = 60 Then xm = 0
xd = xd + 1
xm = Int(xm)
xd = Int(xd)
If s = "-" Then
xd = xd * -1
end if

End Function


Top
 Profile  
 
 Post subject: Re: Function in RB
PostPosted: Sun Feb 17, 2013 6:48 am 
Offline
User avatar

Joined: Fri Feb 15, 2013 6:07 am
Posts: 24
Location: Oran, Algeria
Hello,

Want to know the syntax in the function, how to return a string xd,xm,xs for a given x


Top
 Profile  
 
 Post subject: Re: Function in RB
PostPosted: Sun Feb 17, 2013 7:10 am 
Offline

Joined: Mon Oct 13, 2008 4:26 am
Posts: 63
At the end of your code add

Return str(xd) + "° " + str(xm) + "' " + str(xs) + chr(34)


Top
 Profile  
 
 Post subject: Re: Function in RB
PostPosted: Sun Feb 17, 2013 7:23 am 
Offline

Joined: Mon Oct 13, 2008 4:26 am
Posts: 63
This appears to do what you are looking for

Function DecDms(x As Double) As string
Dim s As String
Dim sn As Integer
dim xp As Double
dim a As Double

Dim xDegrees, xMinutes, xSeconds As Double

sn = Sin(x)
xp = Abs(x)
xDegrees = floor(xp)

a = (xp - xDegrees) * 60
xMinutes = floor(a)
xSeconds = floor((a - xMinutes) * 600 + 0.5) / 10
s = "+"
If sn = -1 Then s = "-"
If xSeconds = 60 Then
xSeconds = 0
xMinutes = xMinutes + 1
xSeconds = floor(xSeconds)
xMinutes = floor(xMinutes)
end if
If xMinutes = 60 Then
xMinutes = 0
xDegrees = xDegrees + 1
xMinutes = floor(xMinutes)
xDegrees = floor(xDegrees)
end if
If s = "-" Then
xDegrees = xDegrees * -1
end if

Return str(xDegrees) + "° " + str(xMinutes) + "' " + str(xSeconds) + chr(34)
End Function


Top
 Profile  
 
 Post subject: Re: Function in RB
PostPosted: Sun Feb 17, 2013 2:24 pm 
Offline
User avatar

Joined: Fri Feb 15, 2013 6:07 am
Posts: 24
Location: Oran, Algeria
Hello,
Perfect, thank you every body !


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group