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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with multiple IF...THEN statements 1

Status
Not open for further replies.

patrussell

Technical User
May 14, 2001
71
US
I have the following code that needs to compare two values to determine what value to save. I had everything working until I added the IF...THEN checks on whether value b is larger than a. When I try to compile I get the "Else without If" error at the second check (b1002).

I know this is probably something simple that I'm missing but I just can't see it. Any help is greatly appreciated.

I realize this is not the most efficient code...I plan to clean it up after I make sure it works in it's current structure.

Code:
        Set fs = CreateObject("Scripting.FileSystemObject")
        If fs.FileExists("D:\Uploads\lville.eq.runtime") Then
            If b1001 > a1001 Then e1001 = a1001
                Else
                    e1001 = Format(a1001 - b1001, "0000")
                End If
            If b1002 > a1002 Then e1002 = a1002
                Else
                    e1002 = Format(a1002 - b1002, "0000")
                End If
            If b1003 > a1003 Then e1003 = a1003
                Else
                    e1003 = Format(a1003 - b1003, "0000")
                End If
            If b1004 > a1004 Then e1004 = a1004
                Else
                    e1004 = Format(a1004 - b1004, "0000")
                End If
            If b1005 > a1005 Then e1005 = a1005
                Else
                    e1005 = Format(a1005 - b1005, "0000")
                End If
            If b1006 > a1006 Then e1006 = a1006
                Else
                    e1006 = Format(a1006 - b1006, "0000")
                End If
            If b1007 > a1007 Then e1007 = a1007
                Else
                    e1007 = Format(a1007 - b1007, "0000")
                End If
            If b1008 > a1008 Then e1008 = a1008
                Else
                    e1008 = Format(a1008 - b1008, "0000")
                End If
        Else
            e1001 = a1001
            e1002 = a1002
            e1003 = a1003
            e1004 = a1004
            e1005 = a1005
            e1006 = a1006
            e1007 = a1007
            e1008 = a1008
            

        End If

Pat Russell
 
If you're going to use an ELSE block then you can't have your first statement on the same line as the THEN statement.

Use something like:
Code:
If b1008 > a1008 Then 
   e1008 = a1008
Else
   e1008 = Format(a1008 - b1008, "0000")
End If
Hope this helps

HarleyQuinn
---------------------------------
Carter, hand me my thinking grenades!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before posting.

 
Glad to help, thanks for the star [smile]

HarleyQuinn
---------------------------------
Carter, hand me my thinking grenades!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before posting.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top