VivienW
asked on
Select..Case statement.Help.
I want to do this but it does not work:
Select Case i
Case i=1
Call f1()
Case i=2
Call f2()
.
.
End Select
What this code should be doing is for i=1,call suubroutine f1 and i=2,call f2 and so on.But it does not work,as i step thru the code,the Call f1()does not jump to subroutine f1.How should I do??
Select Case i
Case i=1
Call f1()
Case i=2
Call f2()
.
.
End Select
What this code should be doing is for i=1,call suubroutine f1 and i=2,call f2 and so on.But it does not work,as i step thru the code,the Call f1()does not jump to subroutine f1.How should I do??
This is The Syntax For Select
Select Case <Variable>
Case "Value":
------
Case "Value":
-----
Case "Value":
-----
Else
End Select
Regards,
Nambi
Select Case <Variable>
Case "Value":
------
Case "Value":
-----
Case "Value":
-----
Else
End Select
Regards,
Nambi
This is beacuse (as RMatzka and sazha says):
Case i=1
'This returns True (True equeals -1 numeric, not 1), thus F1 will never be fired
Case i=2
' This returns False (0) and will never ever call F2
Select Case i
Case 1: F1
Case 2: F2
End Select
Case i=1
'This returns True (True equeals -1 numeric, not 1), thus F1 will never be fired
Case i=2
' This returns False (0) and will never ever call F2
Select Case i
Case 1: F1
Case 2: F2
End Select
ASKER
Actually this is how my code looks like:
Private Sub FileERT_Click()
Dim i%, textline$, k1$, d1$, z1%, j%
d1 = DirERT.Path & "\" & FileERT.FileName
i = FreeFile
Open d1 For Input Shared As #i
Do While Not EOF(i)
Line Input #i, textline 'reading each line
k1 = Mid(textline, 2, 2)
first = Right(textline, 2)
z1 = CInt("&h" & first) + 3
last = Right("0" & Hex(z1), 2)
Select Case i
Case 1
Call cmdK1_Click
Case 2
Call cmdK2_Click
Case 3
Call cmdK3_Click
End Select
Loop
Close #i
End Sub
Here,whenever I read the first line of the file, I'd want to call cmdK1 and the second line cmdK2 and third line cmdK3 and so on. Using this code,whenever I read the second line(i=2),still cmdK1 is fired.
Any solution to this??
Private Sub FileERT_Click()
Dim i%, textline$, k1$, d1$, z1%, j%
d1 = DirERT.Path & "\" & FileERT.FileName
i = FreeFile
Open d1 For Input Shared As #i
Do While Not EOF(i)
Line Input #i, textline 'reading each line
k1 = Mid(textline, 2, 2)
first = Right(textline, 2)
z1 = CInt("&h" & first) + 3
last = Right("0" & Hex(z1), 2)
Select Case i
Case 1
Call cmdK1_Click
Case 2
Call cmdK2_Click
Case 3
Call cmdK3_Click
End Select
Loop
Close #i
End Sub
Here,whenever I read the first line of the file, I'd want to call cmdK1 and the second line cmdK2 and third line cmdK3 and so on. Using this code,whenever I read the second line(i=2),still cmdK1 is fired.
Any solution to this??
Hi,
Try Out This. Just Declare One Variable to count The Line Number.
According to that You can call Functions As You Like
Private Sub FileERT_Click()
Dim i%, textline$, k1$, d1$, z1%, j%
Dim First, Last
d1 = DirERT.Path & "\" & FileERT.FileName
i = FreeFile
Open d1 For Input Shared As #i
Dim LineCount
LineCount = 0
Do While Not EOF(i)
LineCount = LineCount + 1
Line Input #i, textline 'reading each line
k1 = Mid(textline, 2, 2)
First = Right(textline, 2)
'z1 = CInt("&h" & First) + 3
Last = Right("0" & Hex(z1), 2)
Select Case LineCount
Case 1
'Call cmdK1_Click
Case 2
'Call cmdK2_Click
Case 3
'Call cmdK3_Click
End Select
Loop
Close #i
End Sub
I Hope this Will Help You Better Manner.
Regards,
Nambi
Try Out This. Just Declare One Variable to count The Line Number.
According to that You can call Functions As You Like
Private Sub FileERT_Click()
Dim i%, textline$, k1$, d1$, z1%, j%
Dim First, Last
d1 = DirERT.Path & "\" & FileERT.FileName
i = FreeFile
Open d1 For Input Shared As #i
Dim LineCount
LineCount = 0
Do While Not EOF(i)
LineCount = LineCount + 1
Line Input #i, textline 'reading each line
k1 = Mid(textline, 2, 2)
First = Right(textline, 2)
'z1 = CInt("&h" & First) + 3
Last = Right("0" & Hex(z1), 2)
Select Case LineCount
Case 1
'Call cmdK1_Click
Case 2
'Call cmdK2_Click
Case 3
'Call cmdK3_Click
End Select
Loop
Close #i
End Sub
I Hope this Will Help You Better Manner.
Regards,
Nambi
ASKER
Thanks Nambi, that looks really good. What if it comes to EOF?? Will LineCount still read the last line???
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
VivienW:
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
Experts: Post your closing recommendations! Who deserves points here?
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
Experts: Post your closing recommendations! Who deserves points here?
Moderator, my recommended disposition is:
Accept sazhagianambi's comment(s) as an answer.
DanRollins -- EE database cleanup volunteer
Accept sazhagianambi's comment(s) as an answer.
DanRollins -- EE database cleanup volunteer
Select Case i
Case 1
Call f1()
Case 2
Call f2()
.
.
End Select
When you use "Case i=1", the expression "i=1" evaluates either to true or false, which is -1 or 0, which does not match your values of i.