case statements

  • Thread starter Thread starter kronecker
  • Start date Start date
K

kronecker

Is there any way to make case statements case independent?

ie
Case Is = "dim the light"
or
Case Is = "Dim the light"

making them the same outcome without putting every possibility. eg

Case Is = "dim The light" as well

K.
 
Is there any way to make case statements case independent?

ie
Case Is = "dim the light"
or
Case Is = "Dim the light"

making them the same outcome without putting every possibility. eg

Case Is = "dim The light" as well

K.


Supposing that your present code looks something like:

Select Case AStringVariable
Case "dim the light"
....

Change it to
Select Case AStringVariable.toUpper (or toLower)
Case "DIM THE LIGHT" (or "dim the light")

Hope this helps
LS
 
Supposing that your present code looks something like:

Select Case AStringVariable
Case "dim the light"
...

Change it to
Select Case AStringVariable.toUpper (or toLower)
Case "DIM THE LIGHT" (or "dim the light")

Hope this helps
LS

Is there no way to switch of case dependency all together since there
may well be loads of possibilities. It comes from speech recognition?

K.
 
Is there any way to make case statements case independent?

ie
Case Is = "dim the light"
or
Case Is = "Dim the light"

making them the same outcome without putting every possibility. eg

Case Is = "dim The light" as well

The result depends on the setting of 'Option Compare'. If it is set to
'Text', the first branch in the sample below will be executed, if not, the
second branch will be called:

\\\
Select Case "FOO"
Case "foo"
MsgBox("foo")
Case "FOO"
MsgBox("FOO")
End Select
///

If you want to make the compare option independent from 'Option Compare',
you can use the code below:

\\\
Const Value As String = "FOO"
Const CompareMethod As CompareMethod = CompareMethod.Binary
Select Case True
Case StrComp(Value, "foo", CompareMethod) = 0
MsgBox("foo")
Case StrComp(Value, "FOO", CompareMethod) = 0
MsgBox("FOO")
End Select
///
 
I think you missed that if you make the case variable upper, and specify all
uppercase cases, then the case of the original doesn't matter.

Dim S As String

S = "Foo"
' or
S = "fOo"
' or
S = "fOO"
' or
S = "FoO"

Case S.ToUpper
Case "FOO"
' all get here

I don't have an original though since it comes from a recognition
engine for speech.

K.
 
Back
Top