December 17th, 2004, 04:53 PM
In VB6 when you use the code, KillNull(Mid$(databuf, 29)), in Python would i do databuf or databuf[:29]?
Also wut function does Python have that works like the VB6 function, Val().
And for my last question (for now), in Python is using the VB6 function, CLng() needed? Here's an example,
GTC = Val("&H" & StrToHex(StrReverse(data[8:4])))
GTC = CLng(GTC)
Ya, I'm still trying to work out this code to VB6, i just need to know about the Val() and the CLng() part. The GTC that I CLng()'ed gets used later in my code, that's why I'm not sure if using CLng() is needed or not.
December 17th, 2004, 08:05 PM
Sometimes I get the idea that you are missing Python's interactive interpreter...
If you are, then go to Start -> Python 2.3 -> IDLE
In IDLE, go to Run -> Shell.
Type Python code, press enter. Be impressed. Get answers instantly. Develop faster.
Mid$ with one number parameter seems to take text from that point onwards, so it would be databuf[29:].
string[startPos:endPos], but if you leave one out it defaults to the beginning/end.
I don't know, it might depend on the use in the future.
Python will automatically handle long integers so they don't overflow, that might be enough, but if it needs to be a set number of bytes to send over a network link then you might need to bring in struct.pack() again.
December 17th, 2004, 08:11 PM
As I said earlier, the apparent purpose of the line
is to extend the 16 bit value from Val() to 32 bits. You don't need to do this in the Python code in question, because Python integers are already 32 bits wide.
Quite frankly, from the code you've shown us, the VB program you are converting is something of a hack; it spends a lot of time getting around the specific limitations of VB in handling raw data. Encoding these limitations in a Python program isn't going to help, especially since Python has very different limitations of it's own in this regard; every language's data model has it's blind spots, and places where specific conversions need to be done to accomplish something, and each language's solutions are different.
Last edited by Schol-R-LEA; December 17th, 2004 at 08:33 PM.