Good morning Charles..
I have a little question about select Case and Input. Something is Missing in my Code example I have Got an Error. About Input length but I think its another reason.. a similar example I have Made in freebasic and its working fine
Help is Welcome thanks , Frank
' oxygen, question about input and select case
' 21-08-2024, frank bruebach
'
uses console
indexbase 0
' Initialize user descriptions
Dim As String u1 = "I am more like thor"
Dim As String u2 = "I am more like ironman"
Dim As String u3 = "I am more like superman"
Dim As String u4 = "I am more like batman"
Dim As String u5 = "I am more like hawkeye"
Dim As String u6 = "I am more like hulk"
Dim As String u7 = "I am more like my own heroe"
' Display the menu
Printl "Choose the kind of heroe you are:"
Printl "1. "+ u1
Printl "2. "+ u2
Printl "3. "+ u3
Printl "4. "+ u4
Printl "5. "+ u5
Printl "6. "+ u6
Printl "7. "+ u7
printl ""
int le,i
printl cr "Enter your choice (1-7): "
' Get user input
Dim As String choice
choice=input
color 0xf0
Print ""
' Debug and feedback section
Printl "DEBUG: User input length is "+ Len(choice)+ " character(s)."
Printl "DEBUG: User input is '"+ choice+ "'."
Printl ""
' Validate and process the user's choice
If Len(choice) = 1 Then
le=len choice
Select Case choice
Case "1"
Print cr "You selected: "+ u1
Case "2"
Print cr "You selected: "+ u2
Case "3"
Print cr "You selected: "+ u3
Case "4"
Print cr "You selected: "+ u4
Case "5"
Print cr "You selected: "+ u5
Case "6"
Print cr "You selected: "+ u6
Case Else
Print cr " Invalid choice. Please enter a number between 1 and 7."
End Select
Else
Print " Error: Input length is invalid. Expected 1 character."
End If
Print ""
' End of program
color 0xf0
Print "Press any key to continue..."
wait
Hi Frank,
I think it should be
Select Case asc(choice)
In Oxygen, Select only works with numbers
Thank you charles..
example Works fine with asc() and dim as integer choice.. I wrote my example with a String that wasnt correct