Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Select Case idea...
#1
Hey gang, 

Would this even be possible to add? It'd be useful when parsing files...

Code: (Select All)
            SELECT CASE instr(Anim_Name$)

              Case "This would be cool!"
              Case "Or is it just me???"

              end select

Thoughts?

Unseen
Reply
#2
I personally think you'd confuse the crap out of people with the above.

SELECT case INSTR(foo$)


Is foo$ the BASE$ or the SEARCH$?

result = INSTR(BASE$, SEARCH$)  normally, but your select case doesn't specify what you're doing with it.  Is it looking FOR Anim_Name$ in "This would be cool!", or is it looking for "This would be cool!" in Anim_Name$?

INSTR would have to be rewrote just to work in a completely new syntax for SELECT CASE.  SELECT CASE would have to be rewrote to allow INSTR to process like you're describing.  Lots of preexisting things would need to be tweaked or altered, and I really don't think it's an use case where enough people would ever use it to justify writing it.

Wouldn't the simplest way here be to just write a IF THEN ELSEIF ELSEIF ELSEIF ENDIF block?

IF INSTR(Anim_Name$, "This would be cool!") THEN

ELSEIF  INSTR(Anim_Name$, "Or is it just me?")

END IF

Personally, I think you'd generate the exact same C code once all was said and done (SELECT CASE translates directly into a series of IF ELSEIF statement), and the native IF version would be more commonly recognized and supported by the user base.  If you ever need to ask for help on something, folks would be more likely to understand it as they're familiar with it, rather than trying to correct you with, "Does this even work?  I've never seen syntax used like this before!  Maybe try to make it IF statements instead of whatever SELECT CRAP this is!"   (My impression of Pete or Clippy -- take your choice as sometimes they both tend to spout the *exact* same lines, though neither would ever admit it!!)
Reply
#3
Possible? It works with just a little more syntax!
Code: (Select All)
_Title "test Select Case"
Input "Enter y for yes, n for no, c for cancel"; test$
Select Case test$
    Case Is = "y": Print "you chose yes."
    Case Is = "n": Print "you chose no."
    Case Is = "c": Print "you chose cancel."
    Case Else: Print "you chose something besides y, n, c."
End Select

Oh this is about Instr, not just a string?

"I personally think you'd confuse the crap out of people with the above."
Aye!
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#4
I'd already done what i needed to when i had the thought so it's not that a big a deal, i was just asking if it was even possible to implement and from your replies...well i get the message! 

Im off to bed!

John
Reply
#5
Seems like you already started dreaming before getting to bed, those dreams never follow logic or reality very closely. Smile
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#6
Quote:Oh this is about Instr, not just a string?

He wants the convenience of Select Case with unique re-evaluations per Case. So there should be a way to do something similar to what he wants if it works with a function, though Select Case wouldn't be especially useful outside of providing a simple way to keep the code organized:

Code: (Select All)
a$ = "wuzza fuzza buzza"


Select EveryCase 1

    Case IsItInTheString(a$, "wuzza")

        Print "yes"

    Case IsItInTheString(a$, "fuzza")

        Print "it"

    Case IsItInTheString(a$, "muzza")

        Print "is"

    Case IsItInTheString(a$, "buzza")

        Print "!"

End Select



Function IsItInTheString (a$, b$)

    If InStr(1, a$, b$) > 0 Then IsItInTheString = 1

End Function

Function spits out a true or false response, and each Case just checks for true or false. Select Case 0 and Case is < Instr would work too.
Reply
#7
There's more one can do with Select Case than meets the eye. Here are a few ways to play around with it. One can certainly do something useful with the capabilities of SC.

PS: Second correction. I need a glass of Port!  Tongue

Code: (Select All)

'Uebung mit den Moeglichkeiten von Select Case, Obasiv Komp S.148ff
'27. Aug. 2025

Option _Explicit

Dim As Integer zahl, zahl1
Dim As String zeichen

Input "Zahl: ", zahl

Print
Select Case zahl
  Case Is < 5, 6 To 64, 91 To 96, 123 To 128, Is > 255
    Print "Eingabe unkorrekt, oder ausserhalb des ASCII Bereichs!"
  Case Is = 5
    GoTo Korrekt
  Case Asc("a") To Asc("z"), Asc("A") To Asc("Z")
    zeichen = Chr$(zahl)
    'Nur erster Buchstabe - S.262
    Print Using "Die Zahl entspricht dem Buchstaben: !"; zeichen
  Case zahl
    Input "Weitere Zahl: ", zahl1
    If zahl Mod zahl1 = 0 Then
      Print: Print Using "Entspricht Zeichen: !"; Chr$(zahl)
    Else
      Print: Print "Eingabe MOD zahl1 ergibt nicht 0!"
    End If
  Case Else
    Korrekt:
    Beep: Print "Bingo! Eingabe korrekt!"
End Select

End
Reply
#8
Thank you for your brief case examples.

[Image: ?u=https%3A%2F%2Fwebstockreview.net%2Fim...a237742f4b]
Reply
#9
An explanation of how to use Select Case in the program; if it should still be placed under the example above, please move it.

This is about the ASCII table.
1. In the first line, all values that do not represent the alphabet are excluded. 
The number 5 is excluded because I want to demonstrate that GoTo can also be used.

2. The third line, with Asc(X) To . . ., affects the uppercase/lowercase alphabet. When a matching number is entered, e.g., 65 = A, the corresponding letter is displayed. However, this only works if the characters to be displayed are continuous in the ASCII table. Otherwise, characters that are scattered throughout the table must be specified separately each time, such as "(" = 40, "[" = 91, and so on.

The third example is intended to demonstrate that one can also use IF . . . under Select Case; try it with FOR.  

And now Relax  Big Grin

Reply
#10
AS always, I appreciate the input, demos and I learned something too...thats the Germans for ya! They have ways of making it werk! 

John
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Just in case anyone doesn't fully appreciate this forum... Pete 8 834 09-06-2025, 06:37 PM
Last Post: SMcNeill
  Got an idea will it work ? doppler 7 1,137 05-27-2025, 11:20 PM
Last Post: Pete
  Using _Andalso with Select Case Dimster 3 630 05-22-2025, 12:43 PM
Last Post: Dimster
  Pete's Dumb Idea of the Day! Pete 18 2,966 10-23-2024, 10:29 PM
Last Post: Pete
  Idea for two new commands TerryRitchie 9 1,675 04-06-2024, 04:02 AM
Last Post: Pete

Forum Jump:


Users browsing this thread: 1 Guest(s)