# Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
 It is currently Wed Oct 17, 2018 5:34 pm

 All times are UTC - 5 hours

 Page 1 of 1 [ 6 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Function in RBPosted: Sun Feb 17, 2013 6:07 am

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

 Post subject: Re: Function in RBPosted: Sun Feb 17, 2013 6:31 am

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

 Post subject: Re: Function in RBPosted: Sun Feb 17, 2013 6:48 am

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

 Post subject: Re: Function in RBPosted: Sun Feb 17, 2013 7:10 am

Joined: Mon Oct 13, 2008 4:26 am
Posts: 63

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

Top

 Post subject: Re: Function in RBPosted: Sun Feb 17, 2013 7:23 am

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

 Post subject: Re: Function in RBPosted: Sun Feb 17, 2013 2:24 pm

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

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 6 posts ]

 All times are UTC - 5 hours

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

Search for:
 Jump to:  Select a forum ------------------ General    General    Getting Started    Networking    Databases    Visual Basic to REAL Studio Conversion    Games    Plugins    Tips    Web Control SDK Platform Specific    Windows    Macintosh    Linux    Web Other Topics    Announcements    Off-Topic    Third Party Add-ons