Click to See Complete Forum and Search --> : Select Case - Break - End Select
Marc D'Aoust
03-15-2000, 06:37 PM
I would like the Select Case structure to work like a C++ case statement
i.e. You don't exit until you hit a break statement. I would make validating
multiple conditions at the same time a snap.
Marc D'Aoust
Craig Clearman
03-15-2000, 09:12 PM
Marc,
>I would like the Select Case structure to work like a C++ case statement
>i.e. You don't exit until you hit a break statement. I would make validating
>multiple conditions at the same time a snap.
Then ask for a new language construct. Changing an existing construct
so that it breaks existing code should be number one on the *no* list.
Ciao, Craig
--
I've a terrible errible lot todue todie todue tootorribleday.
-- James Joyce
Marc D'Aoust
03-16-2000, 08:21 AM
Ok then how about a new Switch construct:
Switch X
Case X=1
...
Break
Case X=2
...
Case X=4
...
Case Else
...
Break
End Switch
It would solve a lot of my problems with long conditional business logic.
Marc D'Aoust
"Craig Clearman" <chclear@nospam.please> wrote in message
news:c6d0ds4nlf4l49prin84uj74l0jniku555@4ax.com...
> Marc,
>
> >I would like the Select Case structure to work like a C++ case statement
> >i.e. You don't exit until you hit a break statement. I would make
validating
> >multiple conditions at the same time a snap.
>
> Then ask for a new language construct. Changing an existing construct
> so that it breaks existing code should be number one on the *no* list.
>
> Ciao, Craig
>
> --
> I've a terrible errible lot todue todie todue tootorribleday.
> -- James Joyce
Tom Barnaby
03-16-2000, 08:23 PM
"Marc D'Aoust" <marc_daoust@hotmail.com> wrote:
Just a thought ...
How about we reuse the "continue" keyword? This was requested in another
thread to give a continue option in looping constructs. But it could be
used inside of a Select Case to indicate that you wish to process the next
case condition.
Of course that means we would have to have several types of "continues".
Continue Loop, Continue For, Continue Case, etc. Maybe continue isn't the
right word, but I could definitely see some sort of new keyword to handle
the functionality you are asking for.
This would avoid breaking any existing code and keep from introducing an
entirely new construct.
Tom
>Ok then how about a new Switch construct:
>
>Switch X
> Case X=1
> ...
> Break
> Case X=2
> ...
> Case X=4
> ...
> Case Else
> ...
> Break
>End Switch
>
>It would solve a lot of my problems with long conditional business logic.
>
>Marc D'Aoust
>
>
>
>"Craig Clearman" <chclear@nospam.please> wrote in message
>news:c6d0ds4nlf4l49prin84uj74l0jniku555@4ax.com...
>> Marc,
>>
>> >I would like the Select Case structure to work like a C++ case statement
>> >i.e. You don't exit until you hit a break statement. I would make
>validating
>> >multiple conditions at the same time a snap.
>>
>> Then ask for a new language construct. Changing an existing construct
>> so that it breaks existing code should be number one on the *no* list.
>>
>> Ciao, Craig
>>
>> --
>> I've a terrible errible lot todue todie todue tootorribleday.
>> -- James Joyce
>
>
Bob O`Bob
04-16-2000, 10:27 PM
Tom Barnaby wrote:
> How about we reuse the "continue" keyword? This was requested in another
> thread to give a continue option in looping constructs. But it could be
> used inside of a Select Case to indicate that you wish to process the next
> case condition.
ObFlashback: "Fallthru" (or maybe it was "Fallthrough")
this probably wasn't unique to JOVIAL, I suspect it was in
other ALGOL derivatives as well.
Bob O`Bob
--
The new address is very well spam-blocked, perhaps even overzealously
Look up the old one if your legitimate email to me should bounce
Luke T. Gatchell
05-08-2000, 11:04 PM
Considering you can already write:
Public Const MON = 1
Public Const TUE = 2
Public Const WED = 3
Public Const THU = 4
Public Const FRI = 5
Public Const SAT = 6
Public Const SUN = 7
Dim WeekDay as Long
Select Case WeekDay
Case MON, WED, FRI
Case TUE, THU
Case SAT, SUN
End Select
I don't understand what the additional logic is that you are
asking for. Doesn't the above validate multiple conditions?
The only thing I have desired is the ability to fallthrough and
execute say, MON and WED logic when WeekDay is MON,
but WED logic only when WeekDay is WED. Perhaps that is
what you are referring too. If so, I'm in full agreement!
Luke
Marc D'Aoust <marc_daoust@hotmail.com> wrote in message news:38d00d05$1@news.devx.com...
> I would like the Select Case structure to work like a C++ case statement
> i.e. You don't exit until you hit a break statement. I would make validating
> multiple conditions at the same time a snap.
>
> Marc D'Aoust
>
>
Ken Guest
05-10-2000, 06:26 AM
I believe Mark is looking for fallthroughs in the Select statement so that
Select case day
case mon
call DoLaundry
case tue
case wed
case thu
case fri
call GoToWork
Break
case sat
case sun
call BeLazyForAChange
Break
end select
will result with GoToWork being called for mon, tue, wed, thu and
fri and DoLaundry only being called for mon, and BeLazyForAChange being called
only for sat or sun
"Luke T. Gatchell" <ltgatchell@hotmail.com> wrote:
>Considering you can already write:
>
>Public Const MON = 1
>Public Const TUE = 2
>Public Const WED = 3
>Public Const THU = 4
>Public Const FRI = 5
>Public Const SAT = 6
>Public Const SUN = 7
>
>Dim WeekDay as Long
>
>Select Case WeekDay
> Case MON, WED, FRI
>
> Case TUE, THU
>
> Case SAT, SUN
>
>End Select
>
>I don't understand what the additional logic is that you are
>asking for. Doesn't the above validate multiple conditions?
>
>The only thing I have desired is the ability to fallthrough and
>execute say, MON and WED logic when WeekDay is MON,
>but WED logic only when WeekDay is WED. Perhaps that is
>what you are referring too. If so, I'm in full agreement!
>
>Luke
>
>Marc D'Aoust <marc_daoust@hotmail.com> wrote in message news:38d00d05$1@news.devx.com...
>> I would like the Select Case structure to work like a C++ case statement
>> i.e. You don't exit until you hit a break statement. I would make validating
>> multiple conditions at the same time a snap.
>>
>> Marc D'Aoust
>>
>>
>
>
fall-through is something entirely different:
select case true
case instr(somevar,"a")>0: Call Function1
case instr(somevar,"abc")>0 :call function2
end select
in the current version of VB an automatic "break" is assumed in the first
case if somevar contains the character "a"; case two won't be executed.
But sometimes you want it to be executed.
Marc D'Aoust
05-12-2000, 01:04 AM
Exactly, I was thinking of a C++ Switch type of structure
"Don" <dmurray@rcisd.com> wrote in message news:391b252d@news.devx.com...
>
>
> fall-through is something entirely different:
>
> select case true
> case instr(somevar,"a")>0: Call Function1
> case instr(somevar,"abc")>0 :call function2
> end select
>
> in the current version of VB an automatic "break" is assumed in the first
> case if somevar contains the character "a"; case two won't be executed.
>
> But sometimes you want it to be executed.
>
>
Dave Rothgery
05-12-2000, 10:21 AM
"Marc D'Aoust" <marc_daoust@hotmail.com> wrote:
>Exactly, I was thinking of a C++ Switch type of structure
>
Since this is a Visual Basic discussion group, we're not going to get many
language purity lawyers showing up to explain exactly why the C/C++-style
switch statement (i.e. one that requires an explicit 'break') is evil (basicly,
you have a Select statement that isn't Selecting) but even aside from that,
missing break statements in switch/case blocks are a very common source of
errors in C and languages that mimic C syntax too closely.
If you want that kind of behavior, use a stack of If statements. VB's Select/Case
is already more powerful and easier to use correctly than the C switch.
Marc D'Aoust
05-14-2000, 02:41 PM
OK, I agree with you. Switch structures can be a source of evil. I'm
thinking of something in between. Something that makes it possible to select
more then one case in a select case structure. A continue statement would
probably be the best approach. Requiring the Break statement would probably
lead to same kind of errors it does in C++ (and not to mention break a lot
of existing of code). What they could do however is make a completely new
Switch type of structure available to programmers.
If have written programs witch require long strands of complex conditional
logic (i.e. an ERP pay system). Embedding If statements and using Boolean
switches just doesn't cut it. It make the code very hard to follow and
extremely prone to logical errors. All I'm asking for is a conditional
structure which better supports long and complex conditional logic.
Marc D'Aoust
marc_daoust@hotmail.com
"Dave Rothgery" <drothgery@myrealbox.com> wrote in message
news:391c0567$1@news.devx.com...
>
> "Marc D'Aoust" <marc_daoust@hotmail.com> wrote:
> >Exactly, I was thinking of a C++ Switch type of structure
> >
> Since this is a Visual Basic discussion group, we're not going to get many
> language purity lawyers showing up to explain exactly why the C/C++-style
> switch statement (i.e. one that requires an explicit 'break') is evil
(basicly,
> you have a Select statement that isn't Selecting) but even aside from
that,
> missing break statements in switch/case blocks are a very common source of
> errors in C and languages that mimic C syntax too closely.
>
> If you want that kind of behavior, use a stack of If statements. VB's
Select/Case
> is already more powerful and easier to use correctly than the C switch.
Alan Gillott
05-15-2000, 01:53 PM
As a rule I don't include logic in a Case clause. By placing all case logic
in subroutines you can just run the list as needed within each case.
Alternatively you can Sub case each case
Select case xxxxx
Case 1,2,3,4
do1234Things
Select case xxxxx
case1,3
case 2,4
End select
Case 5,6,7,8
do5678things
Select case xxxxx
etc.
At least this way you can see what's happening.
there might be a case for a different type of Select.
"Select Exclusive|Inclusive Case condition"
where Exclusive (current behavior) is default
Inclusive will selects all cases where the case is True
Select Inclusive Case MyInputCode
Case 1,2,3
Case 2,3,4
Case 3,4,5
Case Else
End Select
It is very clear then what is happening and why. Any other approach with
drop through or Continue or whatever will create mega debug problems.
Marc D'Aoust <marc_daoust@hotmail.com> wrote in message
news:391ee45b@news.devx.com...
> OK, I agree with you. Switch structures can be a source of evil. I'm
> thinking of something in between. Something that makes it possible to
select
> more then one case in a select case structure. A continue statement would
> probably be the best approach. Requiring the Break statement would
probably
> lead to same kind of errors it does in C++ (and not to mention break a lot
> of existing of code). What they could do however is make a completely new
> Switch type of structure available to programmers.
>
> If have written programs witch require long strands of complex
conditional
> logic (i.e. an ERP pay system). Embedding If statements and using Boolean
> switches just doesn't cut it. It make the code very hard to follow and
> extremely prone to logical errors. All I'm asking for is a conditional
> structure which better supports long and complex conditional logic.
>
> Marc D'Aoust
> marc_daoust@hotmail.com
>
>
>
>
> "Dave Rothgery" <drothgery@myrealbox.com> wrote in message
> news:391c0567$1@news.devx.com...
> >
> > "Marc D'Aoust" <marc_daoust@hotmail.com> wrote:
> > >Exactly, I was thinking of a C++ Switch type of structure
> > >
> > Since this is a Visual Basic discussion group, we're not going to get
many
> > language purity lawyers showing up to explain exactly why the
C/C++-style
> > switch statement (i.e. one that requires an explicit 'break') is evil
> (basicly,
> > you have a Select statement that isn't Selecting) but even aside from
> that,
> > missing break statements in switch/case blocks are a very common source
of
> > errors in C and languages that mimic C syntax too closely.
> >
> > If you want that kind of behavior, use a stack of If statements. VB's
> Select/Case
> > is already more powerful and easier to use correctly than the C switch.
>
>
Rooky00
05-20-2000, 07:08 PM
A mandatory break is as confusing and error prone as c pointers.
A "Continue" statement would be unusual, and lead to a less understandable
code. (Similar to GoTo).
The following code sample has the same functionality, and is just as ugly.
Of course, you will not dream of using a goto statement in your code.
Dim i As Integer
i = 2
Debug.Print i; " ";
Select Case i
Case 1
Debug.Print "1";
Case 2
Debug.Print "2";
GoTo i3
Case 3
i3: Debug.Print "3";
Case 4
Debug.Print "4";
Case Else
Debug.Print "E"; "done";
End Select
Debug.Print
The goto statement is the currently supported syntax for "Continue".
"Alan Gillott" <agillott@tact.com> wrote in message
news:39202aea$1@news.devx.com...
> As a rule I don't include logic in a Case clause. By placing all case
logic
> in subroutines you can just run the list as needed within each case.
> Alternatively you can Sub case each case
> Select case xxxxx
> Case 1,2,3,4
> do1234Things
> Select case xxxxx
> case1,3
> case 2,4
> End select
> Case 5,6,7,8
> do5678things
> Select case xxxxx
> etc.
> At least this way you can see what's happening.
>
> there might be a case for a different type of Select.
>
> "Select Exclusive|Inclusive Case condition"
> where Exclusive (current behavior) is default
> Inclusive will selects all cases where the case is True
>
> Select Inclusive Case MyInputCode
> Case 1,2,3
> Case 2,3,4
> Case 3,4,5
> Case Else
> End Select
>
> It is very clear then what is happening and why. Any other approach with
> drop through or Continue or whatever will create mega debug problems.
>
> Marc D'Aoust <marc_daoust@hotmail.com> wrote in message
> news:391ee45b@news.devx.com...
> > OK, I agree with you. Switch structures can be a source of evil. I'm
> > thinking of something in between. Something that makes it possible to
> select
> > more then one case in a select case structure. A continue statement
would
> > probably be the best approach. Requiring the Break statement would
> probably
> > lead to same kind of errors it does in C++ (and not to mention break a
lot
> > of existing of code). What they could do however is make a completely
new
> > Switch type of structure available to programmers.
> >
> > If have written programs witch require long strands of complex
> conditional
> > logic (i.e. an ERP pay system). Embedding If statements and using
Boolean
> > switches just doesn't cut it. It make the code very hard to follow and
> > extremely prone to logical errors. All I'm asking for is a conditional
> > structure which better supports long and complex conditional logic.
> >
> > Marc D'Aoust
> > marc_daoust@hotmail.com
> >
> >
> >
> >
> > "Dave Rothgery" <drothgery@myrealbox.com> wrote in message
> > news:391c0567$1@news.devx.com...
> > >
> > > "Marc D'Aoust" <marc_daoust@hotmail.com> wrote:
> > > >Exactly, I was thinking of a C++ Switch type of structure
> > > >
> > > Since this is a Visual Basic discussion group, we're not going to get
> many
> > > language purity lawyers showing up to explain exactly why the
> C/C++-style
> > > switch statement (i.e. one that requires an explicit 'break') is evil
> > (basicly,
> > > you have a Select statement that isn't Selecting) but even aside from
> > that,
> > > missing break statements in switch/case blocks are a very common
source
> of
> > > errors in C and languages that mimic C syntax too closely.
> > >
> > > If you want that kind of behavior, use a stack of If statements. VB's
> > Select/Case
> > > is already more powerful and easier to use correctly than the C
switch.
> >
> >
>
>
devx.com
Copyright WebMediaBrands Inc. All Rights Reserved