INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Is there a better way to write this conditonal statement . . .

Is there a better way to write this conditonal statement . . .

Is there a better way to write this conditonal statement . . .

(OP)
Hi,
Is there a better way for me to write this conditional statement?
It is working, but it is very long.
I also attached the file for better readability.

Thank-you in advance!


'Loop Script

For size = 64 to 8976

print "Packet length is " & size

For i = 1 to 1
If size > 64 AND size = 256 Then
size = 511
print vbcrlf
print size
print vbcrlf
Exit For
ElseIf size > 512 AND size = 528 Then
size = 767
print vbcrlf
print size
print vbcrlf
Exit For
ElseIf size = 784 Then
size = 1023
print vbcrlf
print size
print vbcrlf
Exit For
ElseIf size > 1024 AND size = 1040 Then
size = 1279
print vbcrlf
print size
print vbcrlf
Exit For
ElseIf size = 1296 Then
size = 1535
print vbcrlf
print size
print vbcrlf
Exit For
ElseIf size > 1536 AND size = 1552 Then
size = 1791
print vbcrlf
print size
print vbcrlf
Exit For
ElseIf size = 1808 Then
size = 2047
print vbcrlf
print size
print vbcrlf
Exit For
ElseIf size > 2048 AND size = 2064 Then
size = 2303
print vbcrlf
print size
print vbcrlf
Exit For
ElseIf size = 2320 Then
size = 2559
print vbcrlf
print size
print vbcrlf
Exit For
ElseIf size > 2560 AND size = 2576 Then
size = 2815
print vbcrlf
print size
print vbcrlf
Exit For
ElseIf size = 2832 Then
size = 3071
print vbcrlf
print size
print vbcrlf
Exit For
ElseIf size > 3072 AND size = 3088 Then
size = 3327
print vbcrlf
print size
print vbcrlf
Exit For
ElseIf size = 3344 Then
size = 3583
print vbcrlf
print size
print vbcrlf
Exit For
ElseIf size > 3584 AND size = 3600 Then
size = 3839
print vbcrlf
Exit For
ElseIf size = 3856 Then
size = 4095
print vbcrlf
Exit For
ElseIf size > 4096 AND size = 4112 Then
size = 4351
print vbcrlf
Exit For
ElseIf size = 4368 Then
size = 4607
print vbcrlf
Exit For
ElseIf size > 4608 AND size = 4624 Then
size = 4863
print vbcrlf
Exit For
ElseIf size = 4880 Then
size = 5119
print vbcrlf
Exit For
ElseIf size > 5120 AND size = 5136 Then
size = 5375
print vbcrlf
Exit For
ElseIf size = 5392 Then
size = 5631
print vbcrlf
Exit For
ElseIf size > 5632 AND size = 5648 Then
size = 5887
print vbcrlf
Exit For
ElseIf size = 5904 Then
size = 6143
print vbcrlf
Exit For
ElseIf size > 6144 AND size = 6160 Then
size = 6399
print vbcrlf
Exit For
ElseIf size = 6416 Then
size = 6655
print vbcrlf
Exit For
ElseIf size > 6656 AND size = 6672 Then
size = 6911
print vbcrlf
Exit For
ElseIf size = 6928 Then
size = 7167
print vbcrlf
Exit For
ElseIf size > 7168 AND size = 7184 Then
size = 7423
print vbcrlf
Exit For
ElseIf size = 7440 Then
size = 7679
print vbcrlf
Exit For
ElseIf size > 7680 AND size = 7696 Then
size = 7935
print vbcrlf
Exit For
ElseIf size = 7952 Then
size = 8191
print vbcrlf
Exit For
ElseIf size > 8192 AND size = 8208 Then
size = 8447
print vbcrlf
Exit For
ElseIf size = 8464 Then
size = 8703
print vbcrlf
Exit For
ElseIf size > 8704 AND size = 8720 Then
size = 8959
print vbcrlf
Exit For
ElseIf size = 8976 Then
print "last size is " & size
Exit For
End If
Next

Next

RE: Is there a better way to write this conditonal statement . . .

Hi,

You never answered the replies to your previous question in October.

How can we be sure that you'll reply to this one?

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Is there a better way to write this conditonal statement . . .

You can see the pattern better if you convert all the numbers to hex.

RE: Is there a better way to write this conditonal statement . . .

If size > 64 AND size = 256 is equivalent to If size = 256. Your loop is executed only once (from 1 to 1) so it's not necessary. For the series of contitions I would use Select Case statement.

combo

RE: Is there a better way to write this conditonal statement . . .

If you follow xwb's advice you should see that you can pretty much do this without an if/then (or case) statement at all.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close