Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default Exiting a select case group

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Exiting a select case group

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Exiting a select case group

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default Exiting a select case group

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Exiting a select case group

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Case without Select Case error problem Ayo Excel Discussion (Misc queries) 2 May 16th 08 03:48 PM
End Select without Select Case, Block If without End If errors Atreides Excel Programming 12 November 17th 06 05:10 PM
Case Select Jimbola Excel Programming 11 December 11th 05 06:45 PM
SELECT CASE - Which Row am I on? Craigm[_15_] Excel Programming 1 June 27th 05 08:18 PM


All times are GMT +1. The time now is 08:38 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"