How JustAnswer Works:

  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.

Ask Zabo04 Your Own Question

Zabo04
Zabo04, Programming Enthusiast
Category: Programming
Satisfied Customers: 283
Experience:  C/C++, python, perl, excel, matlab/octave, java, and R experience. Genetic algorithm, vision, GUIs.
58597962
Type Your Programming Question Here...
Zabo04 is online now
A new question is answered every 9 seconds

IterationCounter is declared Publically and As Integer at

Customer Question

IterationCounter is declared Publically and As Integer at the start of the program
Procedure 1 starts by updating the counter with
IterationCounter = IterationCounter +1
If IterationCounter < 50, Then Call Procedure2 Else Call Procedure3
This conditional get a syntax error (without analysis) and the program quits
Can you help? Palmer.
Submitted: 1 year ago.
Category: Programming
Expert:  Zabo04 replied 1 year ago.

After the line "Call Procedure3" you need and "End If".

Customer: replied 1 year ago.
That does NOT change the result. When I run the compiler, it still returns the code in red. (Red is my option to highlight bad code.) So, in other words, the result is identical with or without the End If. To be sure you and I are on the same page, here is the exact syntax again:If IterationCounter < 360 Then Call EarlyPlot Else Call Plot.Note: in my original statement of the problem I used Procedure2 and Procedure3.To emphasize again, this is Excel 2010 running under Windows 7 64bit.Thanks. Palmer.
Expert:  Zabo04 replied 1 year ago.

Okay, regardless you need an End If for VBA code.

Expert:  Zabo04 replied 1 year ago.

This code works for me:

Sub Test1()

IterationCount = 52

If IterationCount < 50 Then
EarlyPlot
Else
Plot
End If
End Sub

Sub EarlyPlot()
Range("A1").Value = "Early Plot"
End Sub

Sub Plot()
Range("A1").Value = "Plot"
End Sub

Expert:  Zabo04 replied 1 year ago.

Sub Test1()

IterationCount = 52

If IterationCount < 50 Then
EarlyPlot
Else
Plot
End If

End Sub

Sub EarlyPlot()
Range("A1").Value = "Early Plot"
End Sub

Sub Plot()
Range("A1").Value = "Plot"
End Sub

Expert:  Zabo04 replied 1 year ago.

Okay Justanswer will hold returns but not spaces or tabs, so the alignment is not pretty, but that code runs. Basically, End If and drop the call. Now are all of your procedures/subs in the same worksheet?

Customer: replied 1 year ago.
OK let's table it until Tuesday because I cannot make a realistic test until I again have streaming stock market data.However, I am remain doubtful. If I put in the End If, the compiler then responds by wanting a rearrangement of my single line into a block with the If at the top and then it converts the Else phrase to a highlighted "Else:" before the Call procedure. And it does that automatically. Could it be that I have a non-standard set up under Options for my VBA? Or that we are talking about different versions of Excel and VBA? Thanks again. Palmer.
Expert:  Zabo04 replied 1 year ago.

If then else end if is straight VBA and version irrelevant.

Expert:  Zabo04 replied 1 year ago.

Get rid of the keyword call, you don't need it. Check where your procedures are defined, they may be out of scope.

Expert:  Zabo04 replied 1 year ago.

I copied and pasted out of Excel VBA, and it ran and changes the cell value. I can send you a .xlsm file.

Expert:  Zabo04 replied 1 year ago.

Here is the link, everything is in sheet1: http://www.mediafire.com/view/7ygkk4uuya18wfn/if_test.xlsm

Customer: replied 1 year ago.
OK Zabo04 Please note the following works and IS NOT according to your guidance. Perhaps instead of being so dogmatic you should learn something from your customers, maybe you guys should pay me. Here is the code that works: If IterationCounter < X Then Call Procedure1 Else Call Procedure2. The whole reason it would not compile was that I was trying to modify a program which had been open and which had On.Time statements still active. As soon as I closed the entire application of Excel and thereby cleared all of the relevant RAM, and then reopened Excel and reloaded the files, then the program compiled and today I tested it with real streaming data. Therefore, the next time you have a prepaid client do not try to hammer him, instead try humility and issue the caution about pre-existing On. Time statements. I decline to rate you. Thank you. Palmer Hinsdale
Expert:  Zabo04 replied 1 year ago.

I apologize for your answer not being in accordance with my guidance. I would ask you to consider that what I provided does run on my machine while your provided code did not run. Per Microsoft's technotes End If is the correct usage of the if then conditional flow. You provided with only four lines of code, which did not have any time statements, so I had no way of knowing you were using them. I have only the information you give me to solve your problem. Also, I did not "hammer you", I was clear and direct in what was compiling on my machine. You may proceed with ratings as you wish, you are the customer, but in the future it would be of great help for you to be more interactive and provide more information, or a sample of the actual code. I did provide code, you did not. Personally, pre-paid or not makes no difference to me. I have a higher acceptance rate than the average expert on this site by a factor of 2 and I have a statistically significant higher percent of repeat customers. I will make note of your username so I do not answer you in the future.

Expert:  Zabo04 replied 1 year ago.

Because I do listen to my customers, here is a screenshot of the compile error without the End If when I tried to run it without as you say works. I noticed there was no End If in what you provided, not based on doctrine, but based on the fact that after a stint of Python or C++ between VBA projects I try to use semi-colons and forget the End If and get the error regularly.

Customer: replied 1 year ago.
Look, I have used Excel VBA for years, but I am not so arrogant to assert that I know everything, because what I do know for sure is that no person has a monopoly on brains, and people who think they could be so afflicted (I am talking about you) are the very persons who do not have a monopoly on brains. I made it work my way and it rejects your way; you can make it work your way. Under those circumstances, I wonder if the fact that I am running Excel 2010 on Windows 7 64 bit could be the clue. You may be sure that I will never use JustAnswer again, so you will never be burdened by having to deal with me. Just for your info, the prior time that I used JustAnswer, the answer turned out to be a question of 64bit vs 32bit. Thank you for your attempt to help me; it was of no value. And, I will not play your game of trying to enhance the statistically significance of your ratings. Thank you, ***** *****