Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
How can I jump out of a select case process if a particular condition occurs?
Exit doesn't seem to apply, and if I try to use End Select in the if statement then I get an error that there is an End Select not matched by a Select Case. Grateful for advice. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi
Doesn't it exit automatically once the condition is true? You only need to exit if you are in a loop surely? regards Paul On Jun 6, 9:49*am, simonc wrote: How can I jump out of a select case process if a particular condition occurs? Exit doesn't seem to apply, and if I try to use End Select in the if statement then I get an error that there is an End Select not matched by a Select Case. Grateful for advice. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
It should exit automatically but there may be reasons why you would want to
terminate manually and End Select should work. If it doesn't then that may suggest a problem with the code. May we see it? Mike "simonc" wrote: How can I jump out of a select case process if a particular condition occurs? Exit doesn't seem to apply, and if I try to use End Select in the if statement then I get an error that there is an End Select not matched by a Select Case. Grateful for advice. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I am using Excel 2000.
This code reads values from a big endian binary file and converts them to decimal so the values can be displayed in a label object on a form. The form also has four option buttons where the user can select which of four possible formats the binary value is in. I found a problem with an overflow error in cases 1 and 2 if the first byte was greater than 127 so I wanted to jump out of the select sequence if this occurred. The statement followed by asterisks is the one which wouldn't compile properly. Public read_two_bytes(1 To 2) As Byte Public read_four_bytes(1 To 4) As Byte Dim byte_offset As Long Dim integer_value As Variant Dim fp_value As Single Dim fp_exponent As Integer Dim fp_sign As Integer If optInline16bit = True Then inline_byte_format = 1 ElseIf optInline32bit = True Then inline_byte_format = 2 ElseIf optInlineIBMfp = True Then inline_byte_format = 3 Else inline_byte_format = 4 End If If txtInline_byte.Text < "" Then byte_offset = CLng(txtInline_byte.Text) + 3600 Select Case inline_byte_format Case 1 '16 bit integer Get #1, byte_offset, read_two_bytes integer_value = read_two_bytes(1) * 256 + read_two_bytes(2) lblFirstInline.Caption = "=" & CStr(integer_value) Case 2 '32 bit integer Get #1, byte_offset, read_four_bytes if read_four_bytes(1) 127 then end select '**************** integer_value = read_four_bytes(1) * 2 ^ 24 + read_four_bytes(2) * 2 ^ 16 _ + read_four_bytes(3) * 2 ^ 8 + read_four_bytes(4) lblFirstInline.Caption = "=" & CStr(integer_value) Case 3 'IBM floating point Get #1, byte_offset, read_four_bytes fp_exponent = read_four_bytes(1) Mod 128 If read_four_bytes(1) 127 Then fp_sign = -1 Else fp_sign = 1 fp_value = (read_four_bytes(2) * (16 ^ (fp_exponent - 2)) + read_four_bytes(3) * (16 ^ (fp_exponent - 4)) _ + read_four_bytes(4) * (16 ^ (fp_exponent - 6))) * fp_sign lblFirstInline.Caption = "=" & CStr(fp_value) Case 4 'IEEE floating point Get #1, byte_offset, read_four_bytes fp_exponent = (read_four_bytes(1) Mod 128) * 2 + Int(read_four_bytes(2) / 128) - 127 If read_four_bytes(1) 127 Then fp_sign = -1 Else fp_sign = 1 fp_value = (1 + (read_four_bytes(2) Mod 128) / 2 ^ 7 + read_four_bytes(3) / 2 ^ 15 _ + read_four_bytes(4) / 2 ^ 23) * 2 ^ fp_exponent * fp_sign lblFirstInline.Caption = "=" & CStr(fp_value) End Select End If "Mike H" wrote: It should exit automatically but there may be reasons why you would want to terminate manually and End Select should work. If it doesn't then that may suggest a problem with the code. May we see it? Mike "simonc" wrote: How can I jump out of a select case process if a particular condition occurs? Exit doesn't seem to apply, and if I try to use End Select in the if statement then I get an error that there is an End Select not matched by a Select Case. Grateful for advice. |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Use OnError.
Either have an label that the error jumps to or use OnError Resume Next and check the Err.Number at the appropriate points and exit appropriately. -- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "simonc" wrote in message ... I am using Excel 2000. This code reads values from a big endian binary file and converts them to decimal so the values can be displayed in a label object on a form. The form also has four option buttons where the user can select which of four possible formats the binary value is in. I found a problem with an overflow error in cases 1 and 2 if the first byte was greater than 127 so I wanted to jump out of the select sequence if this occurred. The statement followed by asterisks is the one which wouldn't compile properly. Public read_two_bytes(1 To 2) As Byte Public read_four_bytes(1 To 4) As Byte Dim byte_offset As Long Dim integer_value As Variant Dim fp_value As Single Dim fp_exponent As Integer Dim fp_sign As Integer If optInline16bit = True Then inline_byte_format = 1 ElseIf optInline32bit = True Then inline_byte_format = 2 ElseIf optInlineIBMfp = True Then inline_byte_format = 3 Else inline_byte_format = 4 End If If txtInline_byte.Text < "" Then byte_offset = CLng(txtInline_byte.Text) + 3600 Select Case inline_byte_format Case 1 '16 bit integer Get #1, byte_offset, read_two_bytes integer_value = read_two_bytes(1) * 256 + read_two_bytes(2) lblFirstInline.Caption = "=" & CStr(integer_value) Case 2 '32 bit integer Get #1, byte_offset, read_four_bytes if read_four_bytes(1) 127 then end select '**************** integer_value = read_four_bytes(1) * 2 ^ 24 + read_four_bytes(2) * 2 ^ 16 _ + read_four_bytes(3) * 2 ^ 8 + read_four_bytes(4) lblFirstInline.Caption = "=" & CStr(integer_value) Case 3 'IBM floating point Get #1, byte_offset, read_four_bytes fp_exponent = read_four_bytes(1) Mod 128 If read_four_bytes(1) 127 Then fp_sign = -1 Else fp_sign = 1 fp_value = (read_four_bytes(2) * (16 ^ (fp_exponent - 2)) + read_four_bytes(3) * (16 ^ (fp_exponent - 4)) _ + read_four_bytes(4) * (16 ^ (fp_exponent - 6))) * fp_sign lblFirstInline.Caption = "=" & CStr(fp_value) Case 4 'IEEE floating point Get #1, byte_offset, read_four_bytes fp_exponent = (read_four_bytes(1) Mod 128) * 2 + Int(read_four_bytes(2) / 128) - 127 If read_four_bytes(1) 127 Then fp_sign = -1 Else fp_sign = 1 fp_value = (1 + (read_four_bytes(2) Mod 128) / 2 ^ 7 + read_four_bytes(3) / 2 ^ 15 _ + read_four_bytes(4) / 2 ^ 23) * 2 ^ fp_exponent * fp_sign lblFirstInline.Caption = "=" & CStr(fp_value) End Select End If "Mike H" wrote: It should exit automatically but there may be reasons why you would want to terminate manually and End Select should work. If it doesn't then that may suggest a problem with the code. May we see it? Mike "simonc" wrote: How can I jump out of a select case process if a particular condition occurs? Exit doesn't seem to apply, and if I try to use End Select in the if statement then I get an error that there is an End Select not matched by a Select Case. Grateful for advice. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Case without Select Case error problem | Excel Discussion (Misc queries) | |||
End Select without Select Case, Block If without End If errors | Excel Programming | |||
Case Select | Excel Programming | |||
SELECT CASE - Which Row am I on? | Excel Programming |