Hi,
If I have:
.......................................
Dim myvar as Word
myvar=1234
USART.Write (DectoStr(myvar,1))
...................................................
I get '4' which is the last character in the string.
What do I have to write to get the first and/or second character in the string?
Thank you for your help.
Regards
Francesco
Formatting USART.Write
Moderators: David Barker, Jerry Messina
I'm sure if you looked at the Help File you would understand what is really happening.
You have 'padded out' your decimal down to a single character. If you replace the '1' with 5 you should see '01234'.
If you want just your original number use:
USART.Write (DectoStr(myvar))
If all else fails Read the Manual!
You have 'padded out' your decimal down to a single character. If you replace the '1' with 5 you should see '01234'.
If you want just your original number use:
USART.Write (DectoStr(myvar))
If all else fails Read the Manual!
- David Barker
- Swordfish Developer
- Posts: 1214
- Joined: Tue Oct 03, 2006 7:01 pm
- Location: Saltburn by the Sea, UK
- Contact:
There are many ways you could do this - this is one way (which assumes you want a string result). It should be quite easy to follow...
The character access is zero indexed, so
0 = 6
1 = 7
2 = 8
3 = 9
Code: Select all
Include "usart.bas"
Include "Convert.bas"
Function CharAt(pNum as word, pIndex as byte) as string(2)
result = DecToStr(pNum)
result = result(pIndex) + #0
end function
Dim myvar As Word
myvar=6789
USART.SetBaudrate(br19200)
USART.Write (CharAt(myvar, 2),13,10)
0 = 6
1 = 7
2 = 8
3 = 9
-
- Posts: 41
- Joined: Thu Feb 26, 2009 6:54 pm
- Location: UK
Thanks David for the hint.
I have found my solution. like this:
---------------------------------------------------------
MyVar=1234
USART.Write(Mid(DecToStr(MyVar),0,2),10,13)
------------------------------------------------------
Using string function 'Mid' I can print any portion of may variable.
Regards
Francesco
I have found my solution. like this:
---------------------------------------------------------
MyVar=1234
USART.Write(Mid(DecToStr(MyVar),0,2),10,13)
------------------------------------------------------
Using string function 'Mid' I can print any portion of may variable.
Regards
Francesco
- David Barker
- Swordfish Developer
- Posts: 1214
- Joined: Tue Oct 03, 2006 7:01 pm
- Location: Saltburn by the Sea, UK
- Contact: