Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default Strange macro behavior - result is correct every other time

Hello,
I am stumped. I have a large VBA program with about 8 subroutines and
maybe 50-70 variables. The program itself is too complicated to
explain, however as a gross approximation, it works about like this:

Private Sub Main_Clicl()
for x = 1 to 1000
if x^2+10x+25 = 100 then
exit sub
next
cells(1,1)=x
End Sub

So, the program would search for an answer. Anyway, let's just say
that for this example, when I click on a button on the screen, I get
an answer in cells(1,1). So, I click it one time and I get the
correct answer; I click a second time and I get an incorrect answer.
I click again, and I get the right answer. And this pattern
continues.

I am not using any static variables. All my variables are global.
Can someone please explain what might be happening.

thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Strange macro behavior - result is correct every other time

Hi Andrew,

Can only offer a suggestion. Impossible to answer without interrogating your
code.

How does the answer get found. Are you using find and if so have you got the
After parameter set to active cell then activating a cell at the end of the
find and the second click of your button is finding a second after the first
occurrence.

It above is the reason then post the bit of code with the find and it can be
fixed. Generally if you want to find the first occurrence then the After
parameter should point to the last cell of the range being searched.

--
Regards,

OssieMac


"Andrew" wrote:

Hello,
I am stumped. I have a large VBA program with about 8 subroutines and
maybe 50-70 variables. The program itself is too complicated to
explain, however as a gross approximation, it works about like this:

Private Sub Main_Clicl()
for x = 1 to 1000
if x^2+10x+25 = 100 then
exit sub
next
cells(1,1)=x
End Sub

So, the program would search for an answer. Anyway, let's just say
that for this example, when I click on a button on the screen, I get
an answer in cells(1,1). So, I click it one time and I get the
correct answer; I click a second time and I get an incorrect answer.
I click again, and I get the right answer. And this pattern
continues.

I am not using any static variables. All my variables are global.
Can someone please explain what might be happening.

thanks

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 298
Default Strange macro behavior - result is correct every other time

Maybe a better example might help. The code you posted wouldn't give an
"answer": did you mean "exit for" and not "exit sub" ?

Since the code you have is too complex to explain, can you reduce it to a
smaller version which has the same problem ? Without that it's unlikely
anyone could guess the cause of your problem.

You specifically mention that you're not using static variables, but you
*are* using global variables, which wouldn't lose their values without
resetting the environment with "Stop" or some other method. Why don't you
suspect your globals ?

Tim


"Andrew" wrote in message
...
Hello,
I am stumped. I have a large VBA program with about 8 subroutines and
maybe 50-70 variables. The program itself is too complicated to
explain, however as a gross approximation, it works about like this:

Private Sub Main_Clicl()
for x = 1 to 1000
if x^2+10x+25 = 100 then
exit sub
next
cells(1,1)=x
End Sub

So, the program would search for an answer. Anyway, let's just say
that for this example, when I click on a button on the screen, I get
an answer in cells(1,1). So, I click it one time and I get the
correct answer; I click a second time and I get an incorrect answer.
I click again, and I get the right answer. And this pattern
continues.

I am not using any static variables. All my variables are global.
Can someone please explain what might be happening.

thanks



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Strange macro behavior - result is correct every other time

On May 19, 12:54*am, "Tim Williams" wrote:
Maybe a better example might help. *The code you posted wouldn't give an
"answer": did you mean "exit for" and not "exit sub" ?

Since the code you have is too complex to explain, can you reduce it to a
smaller version which has the same problem ? *Without that it's unlikely
anyone could guess the cause of your problem.

You specifically mention that you're not using static variables, but you
*are* using global variables, which wouldn't lose their values without
resetting the environment with "Stop" or some other method. *Why don't you
suspect your globals ?

Tim

"Andrew" wrote in message

...

Hello,
I am stumped. *I have a large VBA program with about 8 subroutines and
maybe 50-70 variables. *The program itself is too complicated to
explain, however as a gross approximation, it works about like this:


Private Sub Main_Clicl()
for x = 1 to 1000
if x^2+10x+25 = 100 then
exit sub
next
cells(1,1)=x
End Sub


So, the program would search for an answer. *Anyway, let's just say
that for this example, when I click on a button on the screen, I get
an answer in cells(1,1). *So, I click it one time and I get the
correct answer; I click a second time and I get an incorrect answer.
I click again, and I get the right answer. *And this pattern
continues.


I am not using any static variables. *All my variables are global.
Can someone please explain what might be happening.


thanks


Guys,
I wish I could submit the code, but I have 8 subroutines and several
hundred lines of code. I have run some output tests to verify that my
variables are all 0 prior to the function calls. I don't think there
is an easy answer here. I will have to dig line by line to find the
culprit.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange behavior with old macro now throws error with "Application owlnevada Excel Programming 2 March 31st 09 06:19 PM
Sum Time - strange result (site & cpearson researched) proverbs Excel Worksheet Functions 4 May 14th 07 12:19 PM
Excel 2007 (Beta) - strange behavior of macro AndrĂ¡s Excel Programming 6 November 10th 06 06:08 PM
Strange Personal Macro Workbook Behavior stretch Excel Discussion (Misc queries) 4 August 4th 05 07:39 PM
Strange macro behavior! davegb Excel Programming 9 May 20th 05 10:50 PM


All times are GMT +1. The time now is 07:23 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"