[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Select Case problem

Posted on 2005-04-13
10
Medium Priority
?
173 Views
Last Modified: 2010-05-02
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
0
Comment
Question by:Sethi
  • 3
  • 3
  • 3
  • +1
10 Comments
 
LVL 66

Expert Comment

by:Jim Horn
ID: 13774537
>Select Case txtCombA And txtCombB
Select Case can only evaluate one expression.  They way you have it typed is a logical expression, which only evaluates to True or False.
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 13774556
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
0
 
LVL 10

Accepted Solution

by:
fds_fatboy earned 2000 total points
ID: 13774569
You could do this instead:

Select Case txtCombA & "|" & txtCombB
Case "AA|BB"
   txtCombC = "CC
Case "AB|AC"
   txtCombC = "AA"
End Select
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 18

Author Comment

by:Sethi
ID: 13774575
That's what I wanted to avoid :-)

No solution with Select Case?
0
 
LVL 10

Expert Comment

by:fds_fatboy
ID: 13774585
Or even
Select Case True
Case  txtCombA = "AA" And  txtCombB = "BB"
   txtCombC = "CC
Case  txtCombA = "AB" And  txtCombB = "AC"
   txtCombC = "AA"
End Select
0
 
LVL 18

Author Comment

by:Sethi
ID: 13774621
Perfect..Thanks
0
 
LVL 10

Expert Comment

by:edwardiii
ID: 13774626
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
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 13774640
Not bad...
0
 
LVL 10

Expert Comment

by:fds_fatboy
ID: 13774656
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
0
 
LVL 18

Author Comment

by:Sethi
ID: 13774669
The accepted solution was perfect :-)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question