Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compress multiple if statements 2

Status
Not open for further replies.

smurfhell

MIS
Nov 5, 2004
45
US
Is there a better way to write this out?
Code:
    strlength = Len(item.BillingInformation)
    If strlength = 5 Then
    job2 = Left(item.BillingInformation, 2)
        If job2 = 12 Then
        sjob = "p:\12000s\" & item.BillingInformation
        MsgBox (sjob)
        Else
            If job2 = 11 Then
            sjob = "p:\11000s\" & item.BillingInformation
            MsgBox (sjob)
            Else
                If job2 = 10 Then
                sjob = "p:\10000s\" & item.BillingInformation
                MsgBox (sjob)
                Else
                    If job2 = 13 Then
                    sjob = "p:\13000s\" & item.BillingInformation
                    MsgBox (sjob)
                    End If
                End If
            End If
        End If
    End If
   
   If strlength = 4 Then
   job1 = Left(item.BillingInformation, 1)
        If job1 = 1 Then
        sjob = "p:\01000s\" & item.BillingInformation
        MsgBox (sjob)
        Else
            If job1 = 2 Then
            sjob = "p:\02000s\" & item.BillingInformation
            MsgBox (sjob)
            Else
                If job1 = 3 Then
                sjob = "p:\03000s\" & item.BillingInformation
                MsgBox (sjob)
                Else
                    If job1 = 4 Then
                    sjob = "p:\04000s\" & item.BillingInformation
                    MsgBox (sjob)
                    Else
                        If job1 = 5 Then
                        sjob = "p:\05000s\" & item.BillingInformation
                        MsgBox (sjob)
                        Else
                            If job1 = 6 Then
                            sjob = "p:\06000s\" & item.BillingInformation
                            MsgBox (sjob)
                            Else
                                If job1 = 7 Then
                                sjob = "p:\07000s\" & item.BillingInformation
                                MsgBox (sjob)
                                Else
                                    If job1 = 8 Then
                                    sjob = "p:\08000s\" & item.BillingInformation
                                    MsgBox (sjob)
                                    Else
                                        If job1 = 9 Then
                                        sjob = "p:\09000s\" & item.BillingInformation
                                        MsgBox (sjob)
                                        End If
                                    End If
                                End If
                            End If
                        End If
                    End If
                End If
            End If
        End If
    End If
 
Select ... Case is generally easier than multiif-then-else.

However, in this case how about simply:

Code:
sjob = "p:\0" & job1 & "000s\" & item.BillingInformation
 
I think you probably mean

sjob = "p:\" & format(job1, "00") & "000s\" & item.BillingInformation
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top