This action will reset your project, proceed anyway? (2003)

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15641
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

This action will reset your project, proceed anyway? (2003)

Post by ChrisGreaves »

Code: Select all

Sub test()
    Dim strHorses() As String ' Build an array of "In Form" trainers
    Dim strJockeys() As String ' Build an array of "In Form" trainers
    Dim strTrainers() As String ' Build an array of "In Form" trainers
    MsgBox "pausing"
End Sub
I stumbled across this in Excel2003 and verified it in Word2003.
It is probably of academic interest only, but may prove a bit of a time-saver for some.

Paste the code into a module and run it. Ho-hum.

Now set a Breakpoint on the MsgBox statement.
Run the macro; it stops on the MsgBox.
Place a ReDim strHorses(0) statement immediately before the MsgBox by
(1) Using ENTER to create a new line
(2) Double-clicking "strHorses" and Ctrl-C
(3) Typing "ReDim ", then Ctrl-V to paste in, then typing "(0)"
You now have a ReDim statement for the first array.
No sweat!

Now try to place a ReDim strJockeys(0) statement immediately before the MsgBox by
(4) Selecting the ReDim strHorses(0) statement
(5) Copy/Pasting it immediately before the MsgBox

I get the infamous alert message.

This has annoyed me ever since I learned I had to use ReDim statement to initialize arrays.
In the past I've shrugged, and rerun the application which, harvesting data from the web, could consume 45 minutes of my life.
He who plants a seed, plants life.

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: This action will reset your project, proceed anyway? (20

Post by HansV »

Neither action causes the code to be reset for me in Office 2010. Apparently VBA 7.0 handles it differently.
Best wishes,
Hans

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15641
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: This action will reset your project, proceed anyway? (20

Post by ChrisGreaves »

HansV wrote:Neither action causes the code to be reset for me in Office 2010. Apparently VBA 7.0 handles it differently.
Oh Hans! You're just like all the rest: trying to drag me into the present (grin).

It's good to know it has been changed. It puzzled me deeply why inserting a statement ahead of code that is running should cause a reset.
A change in a constant or a fixed-dimension array i could accept, but a statement that is built for dynamic change, no.
He who plants a seed, plants life.

User avatar
VegasNath
5StarLounger
Posts: 1185
Joined: 24 Jan 2010, 12:02
Location: Wales, UK.

Re: This action will reset your project, proceed anyway? (20

Post by VegasNath »

yabut, all that aside..... Who's gonna win today's 2:45?
:wales: Nathan :uk:
There's no place like home.....

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15641
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: This action will reset your project, proceed anyway? (20

Post by ChrisGreaves »

VegasNath wrote:yabut, all that aside..... Who's gonna win today's 2:45?
That'll cost ya! :laugh:
He who plants a seed, plants life.

User avatar
VegasNath
5StarLounger
Posts: 1185
Joined: 24 Jan 2010, 12:02
Location: Wales, UK.

Re: This action will reset your project, proceed anyway? (20

Post by VegasNath »

well mebbe.... As a tester, who wins the 2:15? :evilgrin:
:wales: Nathan :uk:
There's no place like home.....

User avatar
Don Wells
5StarLounger
Posts: 689
Joined: 27 Jan 2010, 16:45
Location: Ottawa, Ontario, Canada

Re: This action will reset your project, proceed anyway? (20

Post by Don Wells »

Hi Chris
    I don't think that this is a version issue.    Like you, I am running Office 2003.    Like Hans, I find that neither action causes the code to be reset.
Regards
Don