You are visitor number since 14 October 2004.
Go to Howard Kaikow's home page
Copyright © 1998-2001 by Howard Kaikow. All rights
reserved.
Date: 12 March 2001
From: Howard Kaikow <kaikow@standards.com>
Subject: Case Else may disappear when importing WordBasic into
VBA
Back in 1998, I reported in various newsgroups/forums that I had encountered at least 8 instances of Word 8 discarding a Case Else statement when importing WordBasic macros.
I have constructed a nonesense macro that reproduces this problem.
The first macro listed is the Bad macro. The Case Else just before the cmp = 1 statement gets discarded when imported into Word 8 or Word 9 from a WordBasic macro.
I also include the Good macro listed below. This uses REM statements to comment out the statements that might be causing the problem. In that case, (no) pun intended, the Case Else is not discarded.
Note that in this made up example, the outer Select Case … End Select is not needed, and its presence seems to cause the problem. Note that the real macro has code in the outer Select so the solution seems to be to convert the inner Select to If … End If.
The missing Case Else statements were really hard to track down in the real code.
REM Author email address: kaikow@standards.com REM macro BAD (12 December 1998) Sub MAIN Flag = 2 strTemp$ = "Bagels, Pizza" length = Len(strTemp$) Select Case Flag ' Other cases deleted Case Else Buffer$ = Left$(strTemp$, 1) ptr = 0 cmp = 0 While ptr < length Select Case Buffer$ Case "a" cmp = 2 Case Else cmp = 1 End Select ptr = ptr + 1 If ptr < length Then Buffer$ = "Corned Beef" Wend End Select MsgBox Str$(cmp) End Sub
REM Author email address: kaikow@standards.com REM macro Good (12 December 1998) Sub MAIN REM Flag = 2 strTemp$ = "Bagels, Pizza" length = Len(strTemp$) REM Select Case Flag ' Other cases deleted REM Case Else Buffer$ = Left$(strTemp$, 1) ptr = 0 cmp = 0 While ptr < length Select Case Buffer$ Case "a" cmp = 2 Case Else cmp = 1 End Select ptr = ptr + 1 If ptr < length Then Buffer$ = "Corned Beef" Wend REM End Select MsgBox Str$(cmp) End Sub