Discussion about the ZBasic language including the System Library. If you're not sure where to post your message, do it here. However, do not make test posts here; that's the purpose of the Sandbox.
In the last 2 lines of the following code, I dont understand what Im doing wrong ? The commented out line (last line) creates the error message which is commented above the it. If I change it to the code above then its fine, but I didnt want to define extra variables and write the extra code if I dont have to.
public function enforceLeadingZero(byval i as Byte) as String
if (i < 10) then
enforceLeadingZero = "0" & i
else
enforceLeadingZero = CStr(i)
end if
end function
public function myTimeToString(byVal t as MyTime, byval showSeconds as Boolean = false) as String
Dim h as String
Dim m as String
Dim s as String
h = enforceLeadingZero(t.hour)
m = enforceLeadingZero(t.minute)
myTimeToString = h & ":" & m
if (showSeconds) then
s = enforceLeadingZero(t.seconds)
myTimeToString = myTimeToString & ":" & s
end if
end function
public function myDateToString(byVal da as MyDate) as String
Dim y as String
Dim m as String
Dim d as String
y = enforceLeadingZero(CByte(da.year))
m = enforceLeadingZero(da.month)
d = enforceLeadingZero(da.day)
myDateToString = d & "/" & m & "/" & y
end function
public function timeStampToString(byval ts as MyTimeStamp) as String
Dim tt as Mytime = ts.ttime
Dim td as MyDate = ts.tdate
timeStampToString = myDateToString(td) & " " & myTimeToString(tt)
' The following line gives compiler error
' Error: function "myDateToString", type conflict parameter 1,
' formal:Struct MyDate, actual:Structure
' timeStampToString = myDateToString(ts.tdate) & " " & myTimeToString(ts.ttime)
end function
This must be a syntax thing or something Im missing
Neil
Ive included all the code this time... its basicly the same as the start of this thread, but with a Main() added.... Although the part of code which wouldnt compile now does compile...the behaviour of the two versions (See comment in last sub of code) does not operate the same... one version displays updated time every second or so, and the second only displays the first time and dosnt increment at all...
Thanks
Neil
p.s I just confirmed I do use Version 2.6.12 of the ZBasic.exe
public Structure MyDate
Public year as Integer
Public month as Byte
Public day as Byte
End Structure
public Structure MyTime
Public hour as Byte
Public minute as Byte
Public seconds as Byte
End Structure
public Structure MyTimeStamp
Public dtInSec as UnsignedLong ' the time in seconds, store if calculated
' otherwise 0
Public tdate as MyDate
Public ttime as MyTime
Private isCurrent as Boolean ' Dont remember what this was for ?
End Structure
public function enforceLeadingZero(byval i as Byte) as String
if (i < 10) then
enforceLeadingZero = "0" & i
else
enforceLeadingZero = CStr(i)
end if
end function
public function myTimeToString(byVal t as MyTime, byval showSeconds as Boolean = false) as String
Dim h as String
Dim m as String
Dim s as String
h = enforceLeadingZero(t.hour)
m = enforceLeadingZero(t.minute)
myTimeToString = h & ":" & m
if (showSeconds) then
s = enforceLeadingZero(t.seconds)
myTimeToString = myTimeToString & ":" & s
end if
end function
public function myDateToString(byVal da as MyDate) as String
Dim y as String
Dim m as String
Dim d as String
y = enforceLeadingZero(CByte(da.year))
m = enforceLeadingZero(da.month)
d = enforceLeadingZero(da.day)
myDateToString = d & "/" & m & "/" & y
end function
public function timeStampToString(byval ts as MyTimeStamp, byval showSeconds as Boolean = false) as String
Dim tt as Mytime = ts.ttime
Dim td as MyDate = ts.tdate
timeStampToString = myDateToString(td) & " " & myTimeToString(tt, showSeconds)
' The following line did give a compile error, however with new version it compiles
'~ However when above 3 lines are commented and this line is UN commented the operation of
'~ Program isnt as I would expect... i.e in the Main below the time displayed dosnt change
timeStampToString = myDateToString(ts.tdate) & " " & myTimeToString(ts.ttime)
end function
'~ -------------------------------------------------------------------
'~ Retrieves the time from zx system
'~ -------------------------------------------------------------------
public sub myGetTimeStamp(ByRef ts as MyTimeStamp)
'~ Dim year as UnsignedInteger
Dim seconds as Single
'~ Dim ts as MyTimeStamp
Call GetTimeStamp(ts.tdate.year, ts.tdate.month, ts.tdate.day, _
ts.ttime.hour, ts.ttime.minute, seconds)
'~ ts.tdate.year = year)
ts.ttime.seconds = CByte(seconds)
'~ myGetTimeStamp = ts
end sub
sub Main()
Dim ts as MyTimeStamp
Do
myGetTimeStamp(ts)
Debug.print timeStampToString(ts, true)
delay(1.0)
loop
end sub
Unrelated to the issue you raised in your most recent post, the conversion from year to string in myDateToString() probably won't produce the effect that you want. Instead, I propose this: