Thread: Some Questions

    #1
  1. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154

    Some Questions


    In VB6 when you use the code, KillNull(Mid$(databuf, 29)), in Python would i do databuf[29] 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.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    624
    Rep Power
    34
    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.



    In VB6 when you use the code, KillNull(Mid$(databuf, 29)), in Python would i do databuf[29] or databuf[:29]?
    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.

    Also wut function does Python have that works like the VB6 function, Val().
    int()

    >>> int("2")
    2

    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)
    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.
  4. #3
  5. Commie Mutant Traitor
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2004
    Location
    Norcross, GA (again)
    Posts
    1,805
    Rep Power
    1570
    As I said earlier, the apparent purpose of the line
    Code:
    GTC = CLng(GTC)
    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.
    Rev First Speaker Schol-R-LEA;2 JAM LCF ELF KoR KCO BiWM TGIF
    #define KINSEY (rand() % 7) λ Scheme is the Red Pill
    Scheme in Short Understanding the C/C++ Preprocessor
    Taming Python A Highly Opinionated Review of Programming Languages for the Novice, v1.1

    FOR SALE: One ShapeSystem 2300 CMD, extensively modified for human use. Includes s/w for anthro, transgender, sex-appeal enhance, & Gillian Anderson and Jason D. Poit clone forms. Some wear. $4500 obo. tverres@et.ins.gov

IMN logo majestic logo threadwatch logo seochat tools logo