Dim CosZenith, pi Dim Field(7) CosZenith=-0.014543897651582 ' cos(sun's civil zenith) = cos(90deg 50mins) pi= 4 * Atn(1) Sub Submit1_onclick () Dim StartText, FinishText ' strings from webpage form Dim GCLatitude, GCLongitude ' lat & lon in rads for waypoints on GC track Dim GCLatitudeOld, GCLongitudeOld Dim UTSR, UTSS ' UTC times for sunrise & sunset Dim Latitude1, Longitude1 ' lat/lon for the dep point expressed as radians Dim Latitude2, Longitude2 ' lat/lon for the arr point expressed as radians Dim DistanceRad ' =distance in radians between start & finish Dim DistanceNM ' GC distance in nautical miles Dim DistAlongGCRad ' distance along GC track in radians Dim Increment, LoopCounter Dim Counter, Counter1 ' the time interval in decimal hours between waypoints Dim InitialTrueCourseRad ' Initial True Course along GC track in rads Dim DecDepTime, DecArrTime ' departure & arrival times in decimal Dim DepDate, ArrDate ' departure & arrival dates in VB date format Dim Groundspeed, FltTime ' average Groundspeed & Flight Time Dim LoopTime ' time now during loop Dim CumFltTimeDay, CumFltTimeNight ' cumalative day & night totals of time Dim DLongitude Dim DateStart ' start date of departure Dim BreakOut ' Logic Variable Dim TextAreaStr(10) ' holds string data for results Dim TextStr(6) ' holds strings Dim GCTrackData() ' Array for GC waypoint data Dim Temp ' format of long/lat positions is 15 digit string ' pos 1 - "N" or "S" - north or south indicator ' pos 2 to 3 - whole degrees of latitude ' pos 4 to 7 - minutes of latitude accurate to 1 decimal place ' pos 8 - "E" or "W" - east or west indicator ' pos 9 to 11 - whole degrees of longitude ' pso 12 to 15 - minutes of longitude accurate to 1 decimal place ' lat N=+ve, S=-ve ' lon E=+ve, W=-ve ' Initilize Field() variable For Counter= 1 To 7 Field(Counter)=0 Next ' Start of Dep & Arr points CX StartText=uCase(trim(text1.value)) FinishText=uCase(trim(text2.value)) If StartText=FinishText Then MsgBox("Error: Departure and Arrival points are the same.") End If Select Case CheckLatLon(StartText) Case -1 MsgBox("Error in departure point lat/lon") Exit Sub Case -2 field(1)=-1 End Select Select Case CheckLatLon(FinishText) Case -1 MsgBox("Error in arrival point lat/lon") Exit Sub Case -2 field(2)=-1 End Select If Field(1)<>-1 Then Latitude1=((Eval(Mid(StartText,2,2))+(Eval(Mid(StartText,4,4))/60))*pi)/180 Longitude1=((Eval(Mid(StartText,9,3))+(Eval(Mid(StartText,12,4))/60))*pi)/180 If Mid(StartText,1,1)="S" Then Latitude1=Latitude1*-1 If Mid(StartText,8,1)="W" Then Longitude1=Longitude1*-1 End If If Field(2)<>-1 Then Latitude2=((Eval(Mid(FinishText,2,2))+(Eval(Mid(FinishText,4,4))/60))*pi)/180 Longitude2=((Eval(Mid(FinishText,9,3))+(Eval(Mid(FinishText,12,4))/60))*pi)/180 If Mid(FinishText,1,1)="S" Then Latitude2=Latitude2*-1 If Mid(FinishText,8,1)="W" Then Longitude2=Longitude2*-1 End If ' End of Dep & Arr point CX ' Start Of Times CX Select Case CheckTime(text5.value) Case -1 MsgBox("Error in Departure Time") Exit Sub Case -2 Field(5)=-1 End Select Select Case CheckTime(text6.value) Case -1 MsgBox("Error in Arrival Time") Exit Sub Case -2 Field(6)=-1 End Select If Field(5)<>-1 Then DecDepTime=TimeStringToDecimal(text5.value) If Field(6)<>-1 Then DecArrTime=TimeStringToDecimal(text6.value) ' End of Times CX ' Start of date CX Select Case CheckDate(text3.value) Case -1 MsgBox("Error in Departure Date") Exit Sub Case -2 Field(3)=-1 End Select Select Case CheckDate(text4.value) Case -1 MsgBox("Error in Arrival Date") Exit Sub Case -2 Field(4)=-1 End Select If Field(3)<>-1 Then DepDate=CDate(text3.value) If Field(4)<>-1 Then ArrDate=CDate(text4.value) If Field(3)<>-1 Then DepDate=CDate(text3.value) DateStart=DepDate ' inital value set to departure date End If If Field(1)=-1 And Field(2)=-1 Then MsgBox("Please enter Depart Point and/or Arrival Point") Exit Sub End If If Field(3)<>-1 And Field(4)<>-1 And Field(5)<>-1 And Field(6)<>-1 Then If DecArrTime<=DecDepTime And ArrDate=DepDate Then MsgBox("Error: Arrival Time is same as/prior to Departure Time") Exit Sub End If End If ' the great circle distance in nm between two points ' Only executed if departure and arrival points entered on webpage If Field(1)<>-1 And field(2)<>-1 Then DistanceRad=Acos(Sin(Latitude1)*Sin(Latitude2)+Cos(Latitude1)*Cos(Latitude2)*Cos(Longitude1*-1-Longitude2*-1)) DistanceNM=DistanceRad*180*60/pi ' distance converted to nautical miles InitialTrueCourseRad=TrueCourseRad(Latitude1, Longitude1, Latitude2, Longitude2) End If ' If departure point was a pole then code effectively breaks to here ' calculate the flight time. Note may be more than 24hrs ' If departure and arrival the same day easy If Field(3)<>-1 And Field(4)<>-1 And Field(5)<>-1 And Field(6)<>-1 Then If ArrDate=DepDate Then FltTime=DecArrTime-DecDepTime Else FltTime=(((ArrDate-DepDate)-1)*24)+(24-DecDepTime)+DecArrTime ' If dIfferent days then not so easy End If Groundspeed=DistanceNM/FltTime ' calc average Groundspeed End If LoopTime=DecDepTime ' start at dep time LoopCounter=0 ' initialise Counter If Field(1)<>-1 And Field(2)<>-1 And Field(3)<>-1 And Field(4)<>-1 And Field(5)<>-1 And Field(6)<>-1 Then If Eval(text7.value)>59 Then MsgBox("Max Value of Time Interval is 59 mins") Exit Sub ElseIf eval(text7.value)<0 Then MsgBox("Min Value of Time Interval is 1 Min") Exit Sub ElseIf eval(text7.value)=False then MsgBox("Error in Time Interval Value. Please re-enter") Exit Sub End If ReDim GCTrackData(Fix(FltTime+2)*(60/Eval(text7.value)),6) ' Dimension array Increment=Eval(text7.value)/60 ' decimal time increment ' start loop that calculates day/night time DO If LoopCounter>0 Then GCLatitudeOld=GCLatitude GCLongitudeOld=GCLongitude End If DistAlongGCRad=(Groundspeed*Increment*LoopCounter)*pi/(180*60) ' calculate distance along track GCLatitude=Asin(Sin(Latitude1)*Cos(DistAlongGCRad)+Cos(Latitude1)*Sin(DistAlongGCRad)*Cos(InitialTrueCourseRad)) ' calc new latitude of waypoint DLongitude=Atan2(Sin(InitialTrueCourseRad)*Sin(DistAlongGCRad)*Cos(Latitude1), Cos(DistAlongGCRad)-Sin(Latitude1)*Sin(GCLatitude) ) ' calc dIfference in longtude GCLongitude=Modulus((Longitude1*-1)-DLongitude+pi, 2*pi)-pi ' calc new longitude of waypoint GCLongitude=GCLongitude*-1 ' ensure correct sign for E or W UTSR=CalcSRSSTimes(DateStart, Deg(GCLatitude), Deg(GCLongitude),0) ' calc time of sunrise at the waypoint UTSS=CalcSRSSTimes(DateStart, Deg(GCLatitude), Deg(GCLongitude),1) ' calc time of sunset at waypoint ' user has selected aviation time so Subtract 1/2 hour If checkbox1.status=False Then UTSR=UTSR-0.5 End If ' factor time in case not in range 0<=UTSR<=23:59 If UTSR>24 And UTSR<98 Then UTSR=UTSR-24 ElseIf UTSR<0 And UTSR>-98 Then UTSR=UTSR+24 End If If checkbox1.status=False Then UTSS=UTSS+0.5 ' user has Selected aviation time so add 1/2 hour End If ' factor time in Case not in range 0<=UTSR<=23:59 If UTSS>24 And UTSS<98 Then UTSS=UTSS-24 ElseIf UTSS<0 And UTSS >-98 Then UTSS=UTSS+24 End If ' If the final waypoint's time is less than Increment from arrival ' Then reduce Increment to equal time left until arrival time. ' eg arrival time=12:00, time (LoopTime) at last waypoint is 11:58 ' Then final Increment = 2 minutes (2/60). Ensures that the ' total of day and night times equals the flight time. If DateStart=ArrDate And (DecArrTime-LoopTime)1 Then If UTSS=99 Then CumFltTimeNight=CumFltTimeNight+Increment BreakOut=1 ElseIf UTSS=-99 Then CumFltTimeDay=CumFltTimeDay+Increment BreakOut=1 End If End If If BreakOut<>1 Then If UTSR=UTSR And LoopTime1 Then If UTSR>UTSS Then If LoopTime>=UTSR OR LoopTime0 Then GCTrackData(LoopCounter-1,6)=Cstr(Round(Deg(TrueCourseRad(GCLatitudeOld, GCLongitudeOld, GCLatitude, GCLongitude)),1)) End If End If LoopCounter=LoopCounter+1 ' increase LoopCounter by 1 LoopTime=LoopTime+Increment ' increase time now by Increment ' If LoopTime goes over 24:00 Then must be a new day If LoopTime>=24.0 Then DateStart=DateStart+1 ' add a day to date& LoopTime=LoopTime-24 ' Subtract 24:00 to get correct am time on new day End If Loop UNTIL ( (LoopTime>=DecArrTime) And (DateStart=ArrDate) ) ' keep looping until we get to the correct day and time ' If checkbox2.status=True Then GCTrackData(LoopCounter-1,6)=Cstr(Round(Deg(TrueCourseRad(GCLatitude, GCLongitude, Latitude2, Longitude2)),1)) ' MsgBox("looptime="+cstr(loopcounter)) If checkbox2.status=True Then If Len(cstr(LoopCounter))=4 Then GCTrackData(LoopCounter,1)="0"+cstr(LoopCounter) ElseIf Len(cstr(LoopCounter))=3 Then GCTrackData(LoopCounter,1)="00"+cstr(LoopCounter) ElseIf Len(cstr(LoopCounter))=2 Then GCTrackData(LoopCounter,1)="000"+cstr(LoopCounter) ElseIf Len(cstr(LoopCounter))=1 Then GCTrackData(LoopCounter,1)="0000"+cstr(LoopCounter) Else GCTrackData(LoopCounter,1)=Cstr(LoopCounter) End If GCTrackData(LoopCounter,2)=Cstr(DateStart) GCTrackData(LoopCounter,3)=DecHourToString(DecArrTime) GCTrackData(LoopCounter,4)=LatitudeDegreesToString(Deg(Latitude2)) GCTrackData(LoopCounter,5)=LongitudeDegreesToString(Deg(Longitude2)) GCTrackData(LoopCounter-1,6)=Cstr(Round(Deg(TrueCourseRad(GCLatitude, GCLongitude, Latitude2, Longitude2)),1)) If GCTrackData(LoopCounter,3)=GCTrackData(LoopCounter-1,3) Then GCTrackData(LoopCounter-1,6)="" For Counter=1 To 6 GCTrackData(LoopCounter,Counter)="" Next End If End If End If If DistanceNM>0 Then TextAreaStr(2)="Great Circle Distance = "+CStr(Round(DistanceNM,2))+"nm "+CStr(Round((DistanceNM*1.150779),2))+"mls "+CStr(Round((DistanceNM*1.852),2))+"kms" End If If CumFltTimeNight+CumFltTimeDay>0 Then TextAreaStr(1)="Total Flt Time = "+DecHourToString(CumFltTimeNight+CumFltTimeDay)+" Total Day = "+DecHourToString(CumFltTimeDay)+" Total Night = "+DecHourToString(CumFltTimeNight) TextAreaStr(3)="Average Grounspeed = "+CStr(Round(Groundspeed,2))+"nm/h "+CStr(Round((Groundspeed*1.150779),2))+"mph "+CStr(Round((Groundspeed*1.852),2))+"km/h" End If If Field(1)<>-1 And Field(2)<>-1 Then TextAreaStr(4)="Initial True Course is "+CStr(Round(Deg(InitialTrueCourseRad),1))+" degrees(T)" Else TextAreaStr(4)="No second waypoint - course undefined" End If TextStr(1)="Sunrise " TextStr(2)="Sunset " TextStr(3)="Departure point-" TextStr(4)="Arrival point-" TextStr(5)="Sun never rises" TextStr(6)="Sun never sets" If Field(1)<>-1 And Field(3)<>-1 Then Select Case CalcSRSSTimes(DepDate,Deg(Latitude1),Deg(Longitude1),0) Case 99 TextAreaStr(5)=TextStr(3)+TextStr(1)+TextStr(5) Case -99 TextAreaStr(5)=TextStr(3)+TextStr(1)+TextStr(6) Case Else TextAreaStr(5)=TextStr(3)+TextStr(1)+DecHourToString(CalcSRSSTimes(DepDate,Deg(Latitude1),Deg(Longitude1),0))+"z" End Select Select Case CalcSRSSTimes(DepDate,Deg(Latitude1),Deg(Longitude1),1) Case 99 TextAreaStr(6)=TextStr(3)+TextStr(2)+TextStr(5) Case -99 TextAreaStr(6)=TextStr(3)+TextStr(2)+TextStr(6) Case Else TextAreaStr(6)=TextStr(3)+TextStr(2)+DecHourToString(CalcSRSSTimes(DepDate,Deg(Latitude1),Deg(Longitude1),1))+"z" End Select Else TextAreaStr(5)="" TextAreaStr(6)="" End If If Field(2)<>-1 And Field(4)<>-1 Then Select Case CalcSRSSTimes(ArrDate,Deg(Latitude2),Deg(Longitude2),0) Case 99 TextAreaStr(7)=TextStr(4)+TextStr(1)+TextStr(5) Case -99 TextAreaStr(7)=TextStr(4)+TextStr(1)+TextStr(6) Case Else TextAreaStr(7)=TextStr(4)+TextStr(1)+DecHourToString(CalcSRSSTimes(ArrDate,Deg(Latitude2),Deg(Longitude2),0))+"z" End Select Select Case CalcSRSSTimes(ArrDate,Deg(Latitude2),Deg(Longitude2),1) Case 99 TextAreaStr(8)=TextStr(4)+TextStr(2)+TextStr(5) Case -99 TextAreaStr(8)=TextStr(4)+TextStr(2)+TextStr(6) Case Else TextAreaStr(8)=TextStr(4)+TextStr(2)+DecHourToString(CalcSRSSTimes(ArrDate,Deg(Latitude2),Deg(Longitude2),1))+"z" End Select Else TextAreaStr(7)="" TextAreaStr(8)="" End If TextAreaStr(0)="Results for" textarea1.value=String(79,"*")+vbNewLine+textarea1.value ' Loop to print GC route data If checkbox2.status=True And Field(1)<>-1 And Field(2)<>-1 And Field(3)<>-1 And Field(4)<>-1 And Field(5)<>-1 And Field(6)<>-1 Then Counter=LoopCounter Do For Counter1 = 6 To 1 step -1 textarea1.Value=GCTrackData(Counter,Counter1)+" "+textarea1.Value next Counter=Counter-1 textarea1.value=vbNewLine+textarea1.value Loop Until Counter=-1 textarea1.value="Waypoint Date Time(UTC) Latitude Longitude True Course"+vbNewLine+textarea1.value End If textarea1.value=vbNewLine+textarea1.value For Counter=1 To 5 Step 2 TextAreaStr(0)=TextAreaStr(0)+" "+eval("text"+cstr(counter)+".value") Next For Counter=2 To 6 Step 2 TextAreaStr(0)=TextAreaStr(0)+" "+eval("text"+cstr(counter)+".value") Next If checkbox2.status=False Then TextAreaStr(0)=TextAreaStr(0)+vbNewLine+"No Great Circle route data selected" Else TextAreaStr(0)=TextAreaStr(0)+vbNewLine+"Great Circle route data selected" End If If checkbox1.status=False Then TextAreaStr(0)=TextAreaStr(0)+" "+"Aviation Sunset/Sunrise Time Selected" Else TextAreaStr(0)=TextAreaStr(0)+" "+"Actual Sunset/Sunrise Time Selected" End If For Counter = 8 To 0 Step -1 textarea1.Value=TextAreaStr(Counter)+vbNewLine+textarea1.Value Next ' Loop Until GCTrackData(Counter,2)="" End Sub ' *******************Functions Start******************************* Function TrueCourseRad(LatRad1, LonRad1, LatRad2, LonRad2) ' returns true course in rads between two points Dim DistanceRads Dim TrueCourseValRad If LatRad1=pi/2 Then TrueCourseRad=pi ' If departure point is the North pole Then true course to ANY destination must be 180deg or pi rads ' Exit as do not need to calculate initial true course Exit Function ElseIf LatRad1=-pi/2 Then TrueCourseRad=0 ' If departure point is the Sounth pole Then true course to ANY destination must be 000deg or 0 rads Exit Function End If DistanceRads=2*asin(sqr((sin((LatRad1-LatRad2)/2))^2 + cos(LatRad1)*cos(LatRad2)*(sin((lonrad1-lonrad2)/2))^2)) TrueCourseValRad=(Sin(LatRad2)-Sin(LatRad1)*Cos(DistanceRads))/(Sin(DistanceRads)*Cos(LatRad1)) ' correct for double precision arithmetic errors If TrueCourseValRad>1 Then TrueCourseValRad=1 End If If TrueCourseValRad<-1 Then TrueCourseValRad=-1 End If ' initial true course from dep point to arr point ' note the dep point cannot be one of the poles - the above code takes care of pole departures If Sin((LonRad2*-1)-(LonRad1*-1))<0 Then TrueCourseRad=Acos(TrueCourseValRad) Else TrueCourseRad=2*pi-Acos(TrueCourseValRad) End If End Function Function CheckTime (TimeStr) ' check to see if a string is a valid 24 hr time format hh:mm If TimeStr="" Then CheckTime=-2 Exit Function End If If Len(TimeStr)<5 Then CheckTime=-1 Exit Function End If If Mid(TimeStr,3,1)<>":" Then CheckTime=-1 Exit Function ElseIf Eval(Mid(TimeStr,1,2))>23 Then CheckTime=-1 Exit Function ElseIf Eval(Mid(TimeStr,4,2))>59 Then CheckTime=-1 Exit Function End If CheckTime=0 End Function Function CheckDate (DateStr) ' checks date strings to see if are valid format dd/mm/yyyy If DateStr="" Then CheckDate=-2 Exit Function End If If Len(DateStr)<10 Then CheckDate=-1 Exit Function End If If Mid(DateStr,3,1)<>"/" Then CheckDate=-1 Exit Function ElseIf Mid(DateStr,6,1)<>"/" Then CheckDate=-1 Exit Function ElseIf Eval(Mid(DateStr,1,2))>31 Then CheckDate=-1 Exit Function ElseIf Eval(Mid(DateStr,1,2))=0 Then CheckDate=-1 Exit Function ElseIf Eval(Mid(DateStr,4,2))>12 Then CheckDate=-1 Exit Function ElseIf Eval(Mid(DateStr,4,2))=0 Then CheckDate=-1 Exit Function End If CheckDate=0 End Function Function CheckLatLon (CheckStr) ' to check that CheckStr is a valid lat & lon string If CheckStr="" Then CheckLatLon=-2 Exit Function End If If Mid(CheckStr,1,1)<>"N" AND Mid(CheckStr,1,1)<>"S" Then CheckLatLon=-1 Exit Function ElseIf Mid(CheckStr,8,1)<>"E" AND Mid(CheckStr,8,1)<>"W" Then CheckLatLon=-1 Exit Function ElseIf len(CheckStr)<>15 Then CheckLatLon=-1 Exit Function End If If Eval(Mid(CheckStr,2,6))>9000.0 or Eval(Mid(CheckStr,2,6))<0.0 Then CheckLatLon=-1 Exit Function ElseIf Eval(Mid(CheckStr,9,7))>18000 or Eval(Mid(CheckStr,9,7))<0 Then CheckLatLon=-1 Exit Function End If If Mid(CheckStr,6,1)<>"." or Mid(CheckStr,14,1)<>"." Then CheckLatLon=-1 Exit Function End If CheckLatLon=0 End Function Function CalcSRSSTimes (dte,plat,plon,typ) ' calculates sunrise or sunset times ' dte=VB date variant ' plat=latitude in degrees, plon=longitude in degrees ' If typ=0 returns sunrise times ' If typ=1 returns sunset times Dim DayNumOfYear ' The number of the day in the year Dim t, SunTrueLongitude, SunsRightAscention, Lquadrant, RAquadrant Dim SinSunDeclination, CosSunDeclination, SunLocalHourAngle, SunHour, SunTimeUTC Dim lat, lon lat=plat lon=plon DayNumOfYear=Int(275*month(dte)/9.0)-( Int((month(dte)+9)/12.0) * (1+Int((year(dte)-4*Int(year(dte)/4.0)+2)/3.0)))+day(dte)-30 If typ=0 Then t=DayNumOfYear+((6-(lon/15.0))/24.0) If typ=1 Then t=DayNumOfYear+((18-(lon/15.0))/24.0) SunTrueLongitude=((0.9856*t)-3.289)+(1.916*Sin(Rad(((0.9856*t)-3.289))))+(0.020*Sin(Rad(2*((0.9856*t)-3.289))))+282.634 If SunTrueLongitude>360 Then SunTrueLongitude=SunTrueLongitude-360 If SunTrueLongitude<0 Then SunTrueLongitude=SunTrueLongitude+360 SunsRightAscention=Deg(ATN(0.91764*Tan(Rad(SunTrueLongitude)))) Lquadrant=(Int((SunTrueLongitude/90.0)))*90.0 RAquadrant=(Int((SunsRightAscention/90.0)))*90.0 SunsRightAscention=(SunsRightAscention+(Lquadrant-RAquadrant))/15 SinSunDeclination=0.39782*Sin(Rad(SunTrueLongitude)) CosSunDeclination=Cos(Asin(SinSunDeclination)) If plat=90 Then lat=89.999999999 If plat=-90 Then lat=-89.9999999999 SunLocalHourAngle=(CosZenith-(SinSunDeclination*Sin(Rad(LAT)))) / (CosSunDeclination*Cos(Rad(lat))) If SunLocalHourAngle>1 Then SunTimeUTC=99 ' Sun nver rises CalcSRSSTimes=SunTimeUTC Exit Function End If If SunLocalHourAngle<-1 Then SunTimeUTC=-99 ' sun never sets CalcSRSSTimes=SunTimeUTC Exit Function End If If typ=0 Then SunHour=(360-Deg(Acos(SunLocalHourAngle)))/15 If typ=1 Then SunHour=(Deg(Acos(SunLocalHourAngle)))/15 SunTimeUTC=(SunHour+SunsRightAscention-(0.06571*t)-6.622)-lon/15.0 If SunTimeUTC<0 Then SunTimeUTC=SunTimeUTC+24 If SunTimeUTC>24 Then SunTimeUTC=SunTimeUTC-24 CalcSRSSTimes=SunTimeUTC End Function Function Deg (n) ' converts radians to degrees Deg=n*180/pi End Function Function Rad (n) ' converts degress to radians Rad=(pi*n)/180 End Function Function Acos (x) ' ArcCosine(x) If x=-1 Then Acos=pi ElseIf x=1 Then Acos=0 Else Acos = Atn(-x / Sqr(-x * x + 1)) + 2 * Atn(1) End If End Function Function Asin (x) 'Arc Sine(x) If x=-1 Then Asin=-pi/2 ElseIf x=1 Then Asin=pi/2 Else Asin=Atn(X / Sqr(-X * X + 1)) End If End Function Function TimeStringToDecimal(TimeString) ' converts time string(hh:mm) to decimal TimeStringToDecimal=Eval(Mid(Timestring,1,2))+Eval(Mid(TimeString,4,2))/60 End Function Function LongitudeDegreesToString (DegLongitudeValue) ' converts a decimal degree value to a latitude string Dim x, y, z, DegreeStr, MinuteStr, DecimalStr x=Abs(Fix(DegLongitudeValue)) If Abs(DegLongitudeValue)>180 Then LongitudeDegreesToString="Error Longitude >180" Exit Function End If If Abs(DegLongitudeValue)<1 Then y=Round(Abs(DegLongitudeValue*60),1) Else y=round((Abs(DegLongitudeValue)-x)*60,1) End If If y<10 Then MinuteStr="0"+Cstr(Fix(y)) Else MinuteStr=Cstr(Fix(y)) End If z=Abs(y)-Fix(ABS(y)) If z=0 Then DecimalStr="0" Else DecimalStr=Mid(Cstr(round(z,1)),3,1) End If If MinuteStr="60" Then MinuteStr="00" x=x+1 End If If x<10 and x>=1 Then DegreeStr="00"+Cstr(x) ElseIf x<1 Then DegreeStr="000" ElseIf x>=10 and x<100 Then DegreeStr="0"+Cstr(x) Else DegreeStr=Cstr(x) End If If DegLongitudeValue>0 Then LongitudeDegreesToString="E"+DegreeStr+MinuteStr+"."+DecimalStr Else LongitudeDegreesToString="W"+DegreeStr+MinuteStr+"."+DecimalStr End If End Function Function LatitudeDegreesToString (DegLatitudeValue) ' converts a latitude in degrees to a latitude string format Hddmm.mGdddmm.m ' H=N or S G=E or W Dim x, y, z, DegreeStr, MinuteStr, DecimalStr x=Abs(Fix(DegLatitudeValue)) If Abs(DegLatitudeValue)>90 Then LatitudeDegreesToString="Error Latitude >90" Exit Function End If If Abs(DegLatitudeValue)<1 Then y=Round(Abs(DegLatitudeValue*60),1) Else y=round((Abs(DegLatitudeValue)-x)*60,1) End If If y<10 Then MinuteStr="0"+Cstr(Fix(y)) Else MinuteStr=Cstr(Fix(y)) End If z=Abs(y)-Fix(ABS(y)) If z=0 Then DecimalStr="0" Else DecimalStr=Mid(Cstr(round(z,1)),3,1) End If If MinuteStr="60" Then MinuteStr="00" x=x+1 End If If x<10 and x>=1 Then DegreeStr="0"+Cstr(X) ElseIf x<1 Then DegreeStr="00" Else DegreeStr=Cstr(x) End If If DegLatitudeValue>0 Then LatitudeDegreesToString="N"+DegreeStr+MinuteStr+"."+DecimalStr Else LatitudeDegreesToString="S"+DegreeStr+MinuteStr+"."+DecimalStr End If End Function Function DecHourToString (DecHourNum) ' converts a decimal hour to a time string format hh:mm Dim x, y, HourString, MinuteString If DecHourNum < 0 Then DecHourToString = "Error time is negative" Exit Function End If x=Fix(DecHourNum) y=(DecHourNum-x)*60 MinuteString=CStr(Round(y,0)) If MinuteString="60" Then MinuteString="00" x=x+1 End If If x<10 Then HourString="0"+Cstr(x) Else HourString=Cstr(x) End If If Eval(MinuteString) < 10 And MinuteString<>"00" Then MinuteString="0"+MinuteString End If DecHourToString = HourString+":"+MinuteString End Function Function Atan2 (y,x) ' Returns the arctangent of the specified x- and y-coordinates. The ' arctangent is the angle from the x-axis to a line containing the origin (0, 0) ' and a point with coordinates (y, x). The angle is given in radians ' between -pi and pi, excluding -pi. If x>0 Then Atan2=ATN(y/x) Exit Function End If If x<0 And y>=0 Then Atan2=ATN(y/x)+pi Exit Function End If If x=0 And y>0 Then Atan2=pi/2 Exit Function End If If x<0 And y<0 Then Atan2=ATN(y/x)-pi Exit Function End If If x=0 And y<0 Then Atan2=-pi/2 Exit Function End If End Function Function Modulus (y,x) ' calculates the remainder of y/x If y>=0 Then Modulus=y-X*Fix(y/x) Else Modulus=y+x*(Fix(-y/x)+1) End If End Function Sub reset1_onclick text1.value="" text2.value="" text3.value="" text4.value="" text5.value="" text6.value="" textarea1.value="" checkbox2.status=False End Sub Sub button1_onclick text1.value="N5128.2W00027.1" text2.value="N3545.8E14023.4" text3.value="31/08/2000" text4.value="01/09/2000" text5.value="18:00" text6.value="05:00" text7.value="10" textarea1.value="" checkbox2.status=True End Sub