?
Solved

Else without If?

Posted on 2003-02-27
10
Medium Priority
?
182 Views
Last Modified: 2010-04-07
Below are my IF statements.  When I compile I get an "Else without If" error.  Any idea what could be wrong?




             If transtype = "D" Then endbal = custbal - transamt
                credits = 0
                debits = transamt
                balancetotal = balancetotal + endbal
                FormatCurrency (custbal)
                Write #3, custnum, custname, custbal, debits, credits, endbal
               
           
            Else: If transtype = "C" Then endbal = custbal + transamt
                debits = 0
                credits = transamt
                balancetotal = balancetotal + endbal
                Write #3, custnum, custname, custbal, debits, credits, endbal
            End If
            End If



0
Comment
Question by:JustinBGSU
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
10 Comments
 
LVL 2

Expert Comment

by:Jacamar
ID: 8038030
If transtype = "D" Then endbal = custbal - transamt
               credits = 0
               debits = transamt
               balancetotal = balancetotal + endbal
               FormatCurrency (custbal)
               Write #3, custnum, custname, custbal, debits, credits, endbal
               
           
           Else: If transtype = "C" Then endbal = custbal + transamt
               debits = 0
               credits = transamt
               balancetotal = balancetotal + endbal
               Write #3, custnum, custname, custbal, debits, credits, endbal
           End If
           End If


try this.  I moved it around a bit
0
 
LVL 3

Expert Comment

by:Da_Weasel
ID: 8038032
Should prolly look something like this....

If transtype = "D" Then
  endbal = custbal - transamt
  credits = 0
  debits = transamt
  balancetotal = balancetotal + endbal
  FormatCurrency (custbal)
  Write #3, custnum, custname, custbal, debits, credits, endbal
Else If transtype = "C" Then
  endbal = custbal + transamt
  debits = 0
  credits = transamt
  balancetotal = balancetotal + endbal
  Write #3, custnum, custname, custbal, debits, credits, endbal
End If
0
 
LVL 2

Expert Comment

by:Jacamar
ID: 8038036
If transtype = "D" Then
    endbal = custbal - transamt
               credits = 0
               debits = transamt
               balancetotal = balancetotal + endbal
               FormatCurrency (custbal)
               Write #3, custnum, custname, custbal, debits, credits, endbal
               
           
           Else
           If transtype = "C" Then
           endbal = custbal + transamt
               debits = 0
               credits = transamt
               balancetotal = balancetotal + endbal
               Write #3, custnum, custname, custbal, debits, credits, endbal
           End If
           End If

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 2

Expert Comment

by:Jacamar
ID: 8038038
sorry, I pasted the wrong one.
0
 
LVL 2

Accepted Solution

by:
Jacamar earned 200 total points
ID: 8038057
The reason you had an error was because of this line.

If transtype = "D" Then endbal = custbal - transamt

and this line

Else: If transtype = "C" Then endbal = custbal + transamt

because you have your if condition with a statement on the same line, the statement  "endbal = custbal + transamt" is ending the if automatically because it is on the same line as the if statement.  

If you put the code that you want it to do all on lines after the if statement then it will leave the if open until you "end if"

I hope this helps you understand better.

Jacamar
0
 

Author Comment

by:JustinBGSU
ID: 8038077
Jacamar,

Thanks a ton, that worked for me.

Any idea how to write to the .txt file without having quotes and commas appear?
0
 
LVL 3

Expert Comment

by:Da_Weasel
ID: 8038090
There is a slight mistake in the code I posted above.  The Else statment should be an ElseIf statement.

Here is an explaination of what what wrong with your code:

In an IF statement if there is code directly following the THEN keyword or a line continuation characters _ then only that code is executed when the statement evaluates to TRUE.

Example 1:

If x = True Then DoSomething
Else DoSomethingElse
EndIf

is the same as:
If x = True Then
  DoSomething
Else
  DoSomethingElse
EndIf

Example 2:

If x = True Then DoSomething & _
  DoSomethingMore
Else DoSomethingElse & _
  DoSomethingMore
EndIf

is the same as:
If x = True Then
  DoSomething
  DoSomethingMore
Else
  DoSomethingElse
  DoSomethingMore
EndIf

I would suggest using the second form of each of the 2 above examples as there are not real benifits to using the first, and the first form can often create hard to find bugs.
0
 
LVL 3

Expert Comment

by:Da_Weasel
ID: 8038095
Use the PRINT statement instead of WRITE
0
 
LVL 2

Expert Comment

by:Jacamar
ID: 8039533
yep, da weasel is right.  Print will get rid of the quotations.  
0
 

Author Comment

by:JustinBGSU
ID: 8039613
Thanks a bunch to Jacamar and Da Weasel....

I'm sure I wouldn't have figured this out without you.  I really appreciate the help.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

764 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