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??
VivienWAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
sazhagianambiConnect With a Mentor Commented:
Hi Friend,

Defintely this will Work Until Eof File. If You Add One Else Part in Select Statement, ie

Select
Case 1
case 2
case 3
Else
  Call Function()
End select

Then It Will Work If Your File LineCount Exceeds the 3 lines. After 3rd line Every Time Else part will be called.

Regards,
Nambi



0
 
RMatzkaCommented:
Try this:

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.
0
 
sazhagianambiCommented:
This is The Syntax For Select

Select Case <Variable>

Case "Value":
        ------
Case "Value":
        -----
Case "Value":
        -----
Else

End Select

Regards,
Nambi
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
GunsenCommented:
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
0
 
VivienWAuthor Commented:
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??
0
 
sazhagianambiCommented:
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
0
 
VivienWAuthor Commented:
Thanks Nambi, that looks really good. What if it comes to EOF?? Will LineCount still read the last line???
0
 
CleanupPingCommented:
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?
0
 
DanRollinsCommented:
Moderator, my recommended disposition is:

    Accept sazhagianambi's comment(s) as an answer.

DanRollins -- EE database cleanup volunteer
0
All Courses

From novice to tech pro — start learning today.