Posts: 346
Threads: 45
Joined: Jun 2024
Reputation:
32
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
Posts: 3,446
Threads: 376
Joined: Apr 2022
Reputation:
345
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!!)
Posts: 4,692
Threads: 222
Joined: Apr 2022
Reputation:
322
08-16-2025, 07:11 AM
(This post was last modified: 08-16-2025, 07:28 AM by bplus.)
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
Posts: 346
Threads: 45
Joined: Jun 2024
Reputation:
32
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
Posts: 4,692
Threads: 222
Joined: Apr 2022
Reputation:
322
Seems like you already started dreaming before getting to bed, those dreams never follow logic or reality very closely.
724 855 599 923 575 468 400 206 147 564 878 823 652 556 bxor cross forever
Posts: 18
Threads: 0
Joined: Apr 2022
Reputation:
5
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.
Posts: 954
Threads: 52
Joined: May 2022
Reputation:
38
08-28-2025, 04:03 PM
(This post was last modified: 08-29-2025, 06:14 PM by Kernelpanic.)
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!
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
Posts: 2,910
Threads: 305
Joined: Apr 2022
Reputation:
167
Thank you for your brief case examples.
Posts: 954
Threads: 52
Joined: May 2022
Reputation:
38
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
Posts: 346
Threads: 45
Joined: Jun 2024
Reputation:
32
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
|