quote:
Originally posted by CookieRevised
Or the smart advanced method:
(allows you to send/recieve _a lot_ of integers! Per character, you normally could send, you have 1 integer. Because a character is actually always 2 bytes, the same as an integer...)
your integers are the same as above,
Since an integer (or whatever) is stored as sequences of bytes in memory and strings are stored just the same way, you can interpret each integer as a wide character of a string. Because an integer consist of two bytes and a wide string character also consist of two bytes. Thus the string, using the example integers above, would consist of only 3 wide characters (=6 bytes, this in contrast to the first method where your string consists of 26 bytes): ChrW$(1234) & ChrW$(-4789) & ChrW$(45).
eg: sResult = Chr$(nCCNotify) & "smvpg" & ChrW$(1234) & ChrW$(-4789) & ChrW$(45)
Using the ReceiveNotify procedure, sText will contain ChrW$(1234) & ChrW$(-4789) & ChrW$(45). Thus, you interpret it again by getting the wide characters one by one:
Dim I as Integer
For T=1 To Len(therecievedstring)
I = AscW(Mid$(therecievedstring, T, 1))
Next T
i wouldn't do that because there may be problems with integers which one of their bytes is zero... that would be the NUL character used to mark the end of a string and that could give problems because messenger would only send the first bytes up to the first zero (NUL) byte.
For example:
code:
'......
Dim I1 as Integer
Dim I2 as Integer
Dim I3 as Integer
'.......
I1 = 1234
I2 = 0
I3 = 4500
'.....
sResult = Chr$(nCCNotify) & "smvpg" & ChrW$(I1) & ChrW$(I2) & ChrW$(I3)
' ^ that would create a string that has the notify code, the letters "smvpg",
' two bytes (&H4 and &HD2) and then two bytes set to zero
' and finally two bytes more (&H11 adn &H94)
' but the first byte set to zero (coming from I2) will indicate end of string
' (remember that in C, strings end in '\0')
' That would cause problems when sending the message
In fact, if the integers are in the range 0..255 or if they are a multiple of 256 (including negative multiples) that issue would happen.
As a work arround for that, maybe the best way to send the numbers would be in hexadecimal format...