Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Visual Basic CHRW function in VFP
Message
From
23/09/2009 21:36:21
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
 
To
23/09/2009 21:16:07
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Vista
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01425853
Message ID:
01425860
Views:
108
This message has been marked as the solution to the initial question of the thread.
>Thank you my friend, your last idea do you think will work? i'm needing to convert numbers like 6500, 9600, 9450, etc. to their respective chr() string, would be possible to create a function to allow that?

Sure, you could convert (for example) to double-byte strings - but you won't be able to visualize these normally in Visual FoxPro. A simple command like ? lcMyText will show every byte as a separate character. You may have similar problems if you show the data in a TextBox.

It might be usable, though, if you just need to import, store, and export some data.

In any case, you would have to figure out how the data is stored - or at least, what format is used.

strconv() might help with the conversions; you will have to do some additional research on that topic. I see that conversions from "double-byte" to "unicode" are supported - whatever that means!

Let's assume that in a double-byte character, the first byte for each character is the high-order byte, and the second, the low-order. That is, the number is calculated as first_byte * 256 + second_byte. Please note that for your purposes, you have to verify this assumption; for example, I believe that what I explain is the "big-endian" convention, whereas some systems use the "little-endian" convention - with the high-order value in the second byte! So please check your requirements - how the data is to be stored!

Anyway, assuming the big-endian convention, you can get two bytes as follows:
lcByte1Value = number % 256
lcByte2Value = int(number / 256)
lcDoubleByteString = chr(lcByte1Value) + chr(lcByte2Value)
* Or simply:
lcDoubleByteString = chr(number % 256) + chr(int(number / 256))
I would combine this into a single statement and use less variables (as in the last line of the above sample code); I included the detailed version for clarity.


(A comment, not relevant for this discussion: Big-endians and Little-endians were two groups, in Lilliput, who had bitter fights over the question whether an egg should be opened from the big end, or from the little end.)
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform