|
|
| Author |
Message |
dkinzer Site Admin
Joined: 03 Sep 2005
Posts: 2593
Location: Portland, OR
|
|
Posted: 26 December 2010, 21:47 PM Post subject: |
|
|
| mikep wrote: | | Code: | | Call PutQueueStr(SSCOQ, Chr(rates(i+1))) |
|
I suspect that this should be written as: | Code: | | Call PutQueueStr(SSCOQ, CStr(rates(i+1))) |
If you wanted to avoid using strings, you could use a helper routine like the one below which places bytes into the queue for each decimal digit. | Code: | '
'' PutQueueValue
'
' Write a sequence of characters to the specified queue comprising
' the decimal representation of the given value.
Sub PutQueueValue(ByRef q() as Byte, ByVal val as UnsignedInteger)
If (val > 9) Then
Call PutQueueValue(q, val \ 10)
val = val Mod 10
End If
Call PutQueueByte(q, CByte(val) + &H30)
End Sub |
The implementation above uses recursion and it may invoke itself up to four times. You could implement the same functionality without using recursion, an example of which is shown below. | Code: | '
'' PutQueueValue
'
' Write a sequence of characters to the specified queue comprising
' the decimal representation of the given value.
Sub PutQueueValue(ByRef q() as Byte, ByVal val as UnsignedInteger)
Dim buf(1 to 5) as Byte
Dim i as Byte
' generate the characters in reverse order in the buffer
For i = 1 to 5
buf(i) = CByte(val Mod 10) + &H30
val = val \ 10
If (val = 0) Then
Exit For
End If
Next i
' output the generated characters to the queue
Do While (i > 0)
Call PutQueueByte(q, buf(i))
i = i - 1
Loop
End Sub |
Last edited by dkinzer on 27 December 2010, 0:18 AM; edited 2 times in total |
|
| Back to top |
|
 |
mikep
Joined: 24 Sep 2005
Posts: 771
Location: Austin, TX
|
|
Posted: 26 December 2010, 21:58 PM Post subject: |
|
|
| dkinzer wrote: | | mikep wrote: | | Code: | | Call PutQueueStr(SSCOQ, Chr(rates(i+1))) |
|
I suspect that this should be written as: | Code: | | Call PutQueueStr(SSCOQ, CStr(rates(i+1))) |
| Don is correct. I have edited my append to avoid any problems if it is read by itself. |
|
| Back to top |
|
 |
everest
Joined: 31 May 2010
Posts: 96
|
|
Posted: 26 December 2010, 22:47 PM Post subject: |
|
|
Ahh, thanks Mike!! I'd totally forgotten about Asc!! DOH!! That's perfect! There's just so much to remember about how to get things done, even with a relatively simple language like Zbasic!!
-Jeff |
|
| Back to top |
|
 |
|