Looping over Select Case possible?

Results 1 to 2 of 2

Thread: Looping over Select Case possible?

  1. #1
    Join Date
    Dec 1969

    Default Looping over Select Case possible?

    I&#039d like to use a Select Case statement. The number of cases is dynamic. I&#039m trying both of the following, but in each instance I get "Expected statement" on the word "Case."<BR>----------------------------------------<BR>caseVal = 0 &#039 want to use this to increment Case value<BR>someNum = 10 &#039represents total records<BR>randNum = 5 &#039draws a random number from someNum<BR><BR>Select Case randNum<BR>For x = 1 to someNum<BR>caseVal = caseVal+1<BR>Case caseVal<BR>someVar = "whatever"<BR>Next<BR>End Select<BR>-----------------------<BR>also trying this...<BR><BR>caseVal = 0<BR>someNum = 10<BR>randNum = 5<BR><BR>Select Case randNum<BR>caseVal = 0<BR>Do Until RS.EOF <BR>caseVal = caseVal+1<BR>Case caseVal<BR>someVar = RS("whatever")<BR>RS.MoveNext<BR>Loop<BR>End Select<BR><BR>Any thoughts? Thanks

  2. #2
    Join Date
    Dec 1969

    Default RE: Looping over Select Case possible?

    In general, you can&#039t "overlap" control structures in any computer language. <BR><BR>The entirety of a SELECT CASE...END SELECT may be embedded inside a loop, or an entire DO WHILE...LOOP may be embedded inside a single CASE, but you can&#039t mix the two. Further, you *MUST* follow SELECT CASE *immediately* with a CASE; you can&#039t have any intervening statements.<BR><BR>If you didn&#039t already know, be aware that SELECT CASE is just a shorthand for using a bunch of IF...ELSEIF...ELSEIF...ELSE...END IF lines instead. The SELECT CASE part of the construction is just a "prefix" that is used in each of the cases.<BR><BR>Anyway, how about *describing* what you are trying to do, because the code makes zero sense to me, as you have presented it.<BR><BR>Oh...and the number of CASEs in a SELECT CASE can *never* be dynamic. <BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts