Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

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

Status
Not open for further replies.

Adohr

Technical User
Oct 27, 2017
2
US
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

 
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,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
You can see the pattern better if you convert all the numbers to hex.
 
[tt]If size > 64 AND size = 256[/tt] is equivalent to[tt] If size = 256[/tt]. Your loop is executed only once (from 1 to 1) so it's not necessary. For the series of contitions I would use [tt]Select Case[/tt] statement.

combo
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top