Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 10th, 2004, 07:39 PM
Yegg`'s Avatar
Yegg` Yegg` is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Dec 2004
Location: Meriden, Connecticut
Posts: 1,731 Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Weeks 6 Days 4 h 5 m 27 sec
Reputation Power: 83
Send a message via AIM to Yegg`
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?

Reply With Quote
  #2  
Old December 10th, 2004, 08:33 PM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 8
Send a message via MSN to Grim Archon
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
__________________
*** Experimental Python Markup CGI V2 ***

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Select Case to While


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT