Sethi
asked on
Select Case problem
I have a few conditions in a problem. if the user enters AA and BB in two respective textboxes then the result will be CC. Similarly there are more than 50 prefixed combination that I hve in an application. So I want to use a select statement. However something like this is not working. I am not sure whether I am missing something or is it not possible in VB:
Select Case txtCombA And txtCombB
Case "AA" And "BB"
txtCombC = "CC
Case "AB" And "AC"
txtCombC = "AA"
End Select
I am getting type mismatch error in the first statement itself: Select Case txtCombA And txtCombB
Select Case txtCombA And txtCombB
Case "AA" And "BB"
txtCombC = "CC
Case "AB" And "AC"
txtCombC = "AA"
End Select
I am getting type mismatch error in the first statement itself: Select Case txtCombA And txtCombB
You're going to have to write a really large If...elseif...end if statement to cover all 50 prefixed combinations.
If txtCombA = "AA" AND txtCombB = "BB" then
txtCombC = "CC"
ElseIf txtCombA = "AB" AND txtCombB = "AC" then
txtCombC = "AA"
'etc. etc.
End If
If txtCombA = "AA" AND txtCombB = "BB" then
txtCombC = "CC"
ElseIf txtCombA = "AB" AND txtCombB = "AC" then
txtCombC = "AA"
'etc. etc.
End If
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That's what I wanted to avoid :-)
No solution with Select Case?
No solution with Select Case?
Or even
Select Case True
Case txtCombA = "AA" And txtCombB = "BB"
txtCombC = "CC
Case txtCombA = "AB" And txtCombB = "AC"
txtCombC = "AA"
End Select
Select Case True
Case txtCombA = "AA" And txtCombB = "BB"
txtCombC = "CC
Case txtCombA = "AB" And txtCombB = "AC"
txtCombC = "AA"
End Select
ASKER
Perfect..Thanks
Hi, Sethi.
If an IF/THEN statement is acceptable, you could:
IF txtCombA.text = "AA" and txtCombB.text = "BB" THEN
txtCombC.text = "CC"
ElseIF txtCombA.text = "AB" AND txtCombB.text = "AC" THEN
txtCombC.text = "AA"
ElseIF...
End IF
If an IF/THEN statement is acceptable, you could:
IF txtCombA.text = "AA" and txtCombB.text = "BB" THEN
txtCombC.text = "CC"
ElseIF txtCombA.text = "AB" AND txtCombB.text = "AC" THEN
txtCombC.text = "AA"
ElseIF...
End IF
Not bad...
Or even
Dim sAB() As String
Dim sC() As String
dim i as Long
sAB = Split("AA|BB~AB|AC","~")
sAC = Split("CC~AA","~")
For i = lbound(sAB) to UBound(sAB)
if txtCombA & "|" & txtCombB = sAB(i) Then
txtCombC = sAC(i)
Exit For
End If
Next
Dim sAB() As String
Dim sC() As String
dim i as Long
sAB = Split("AA|BB~AB|AC","~")
sAC = Split("CC~AA","~")
For i = lbound(sAB) to UBound(sAB)
if txtCombA & "|" & txtCombB = sAB(i) Then
txtCombC = sAC(i)
Exit For
End If
Next
ASKER
The accepted solution was perfect :-)
Select Case can only evaluate one expression. They way you have it typed is a logical expression, which only evaluates to True or False.