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

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

    Select Case to While


    Tell me if this code will work. The following code is in Visual Basic, the code I need to know if it will work is the second code.

    Code:
    Select Case GetWORD(Mid(Data, 5, 2))
         Case &H0
              stuff..........
              stuff..........
              stuff..........
    Code:
    while GetWORD(data[5:2]):
         while GetWORD(data[5:2]) == 0x00:
              stuff......
              stuff......
    Now I'm not sure if this code will work, I need some help with it.
    I also have one mroe very quick question. Will msg[5:5] work?
  2. #2
  3. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    14
    Guessing that data is just a stream of characters then something like this perhaps is the python equivalent of your case structure:
    Code:
    word = data[5:7] #get a slice of 2 characters (at position 5 and 6 in the string)
    if word == 'ab':
        #do ab stuff
    elif word == 'cb':
       #do cb stuff
    elif word == 'zh':
       # do ...
    else:
       # do whatever

    even if data was actaully read from a file of binary data it will still be treated as a big string of 8-bit characters on which you can apply slicing.

    You can always use the interactive shell to test things like msg[5:5]
    It works but produces nothing useful - the second index is the same as the first so the slice is zero length

    grim

IMN logo majestic logo threadwatch logo seochat tools logo