I'm working on a script where users can select from multiple choices, but I've run into a problem. When the `$choices` variable has fewer than 10 items, everything works perfectly. However, once I hit 10 or more options, selecting any choice from 2-9 results in an 'invalid' message. Does anyone know why this might be happening? I've included my function code as well for reference.
3 Answers
Another way to handle numeric comparisons is to use the syntax: `} elsif (1 -ge $readinput -or $choices.Count -le $readinput) {`. This could simplify your conditional checks.
It looks like the issue might be due to how you're reading user input. The `Read-Host` command captures input as a string, so you should cast it to an integer like this: `[int]$readinput = Read-Host` to ensure proper numeric comparison.
Menus can indeed be tricky! Make sure you're defining the input types correctly. Good luck with your script!
You might also want to update this line: `} elseif ([int]$readinput -lt 1 -or [int]$readinput -gt $choices.Count) {` to make sure you're working with integers.