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.
Sub Main()
dim sn_work as single
dim by_MMfn as byte
sn_work=30.00001
by_MMfn=cbyte(sn_Work / 60.0)
debug.print cstr(by_mmfn)
End Sub
Result is 1 for any value of sn_work > 30
Either I'm very tired or there is something unexpected happening here and my display clock function doesn't work as a result.
I see - i thought cbyte was just a type conversion, but it is rounding also, hence my problem.
would this produce the best way to get the desired result
by_MMfn=cbyte(fix(sn_Work / 60.0))
i wrongly though my first version of code was equivlent to other forms of basic that do not require explicit type conversion. Would i be correct in saying
by_MMfn=30.0001/60.0 in VB6 would result in zero ?
FFMan wrote:Would i be correct in saying by_MMfn=30.0001/60.0 in VB6 would result in zero ?
No. CByte() in VB6 exhibits the same behavior.
If you want conversion without rounding, see the description of FixB(). Another option is to use Fix() or Floor() to get the integral portion of the Single value and then convert that to Byte using CByte(). The difference between Fix() and Floor() is how negative values are handled, for non-negative values the results are the same.
FFMan wrote:Will you issue a fix or shall I code using Floor instead ?
The correction has been made and will be in a near future release of the compiler. In the interim, you'll need to use Floor() or Fix() within a CByte() call to get the desired result.