PC Review


Reply
Thread Tools Rate Thread

Code termination resets public variable

 
 
rogge
Guest
Posts: n/a
 
      14th Jan 2009
A variable, boolRenameSheets, is declared in a module at the module (General)
level. Speudo Code is below with the important declarations...

boolRenameSheets is being Watched (Break When Value Changes); the code never
breaks after modPublicMacros.runSimulationQuestion has begun.

Thank you all in advance for helping me with this conundrum.


Here is the process...

A) Set boolRenameSheets = True (occurs when ribbon is first accessed (ie
open workbook) and when checkbox is ticked) this module the only place that
contains 'boolRenameSheets ='. elsewhere "if boolRenameSheets then" is
used... this make it very evident the my code does not change
boolRenameSheets.
B) ReDimensions (not-preserve by design) populates some arrays
C) Runs code in a DLL that uses the arrays
D) deletes sheets meeting a specified criteria
E) creates new sheets and populates cells on these sheets
F) MsgBox indicating the process completed (and also boolRenameSheets)

THIS IS WHAT HAPPENS:
0 - ribbonCallBacks.cbSetRenameSheets) Set boolRenameSheets = True using the
ribbon

1 - modPublicMacros.runSimulationQuestion) Run the special code...

2 - modSpecialCode.runSimulation) Display boolRenameSheets immediately
before code execution stops
boolRenameSheets = True

3 - Immediate Window) Use the immediate window to verify boolRenameSheets
immediately after step 2 finishes
? boolRenameSheets
False



_________________________________________________
'modPublicMacros

Option Compare Binary
Option Explicit
Option Base 0

Public boolPrintDerivatives As Boolean
Public boolRenameSheets As Boolean

Public Sub runSimulationQuestion
'Pseudo Code....
if msgBox() = vbYes Then modSpecialCode.runSimulation
End Sub

_________________________________________________
'ribbonCallBacks

Option Private Module
Option Compare Binary
Option Explicit
Option Base 0

'Callback for chkRenameSheets getPressed
Public Sub gpRenameSheets(ByVal control As IRibbonControl, ByRef returnedVal)
'Set default value to True
returnedVal = True
boolRenameSheets = True
End Sub

'Callback for chkRenameSheets onAction
Public Sub cbSetRenameSheets(ByVal control As IRibbonControl, ByVal pressed
As Boolean)
'Set value to checkbox value
boolRenameSheets = pressed
End Sub

_________________________________________________
'modSpecialCode

Option Private Module
Option Compare Binary
Option Explicit
Option Base 0

Public Sub runSimulation()
runSimulationPartA
End Sub


Private Sub runSimulation
deleteSheets
GetInput
runSimulationDLL
populateOutput
MsgBox boolRenameSheets & " complete" 'Shows true when
runSimulationPartA begins execution with boolRenameSheets = true
End Sub


Private Sub deleteSheets
'delete old sheets
End Sub


Private Sub GetInput
'populate arrays
End Sub


Private Sub runSimulationDLL
'Execute the dll
End Sub


Private Sub populateOutput
'create new sheets
End Sub


 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      14th Jan 2009
I don't know about the ribbon, but does any of your code use End (not End Sub,
End Function, End if), just plain old End.

This will reset those variables.

rogge wrote:
>
> A variable, boolRenameSheets, is declared in a module at the module (General)
> level. Speudo Code is below with the important declarations...
>
> boolRenameSheets is being Watched (Break When Value Changes); the code never
> breaks after modPublicMacros.runSimulationQuestion has begun.
>
> Thank you all in advance for helping me with this conundrum.
>
> Here is the process...
>
> A) Set boolRenameSheets = True (occurs when ribbon is first accessed (ie
> open workbook) and when checkbox is ticked) this module the only place that
> contains 'boolRenameSheets ='. elsewhere "if boolRenameSheets then" is
> used... this make it very evident the my code does not change
> boolRenameSheets.
> B) ReDimensions (not-preserve by design) populates some arrays
> C) Runs code in a DLL that uses the arrays
> D) deletes sheets meeting a specified criteria
> E) creates new sheets and populates cells on these sheets
> F) MsgBox indicating the process completed (and also boolRenameSheets)
>
> THIS IS WHAT HAPPENS:
> 0 - ribbonCallBacks.cbSetRenameSheets) Set boolRenameSheets = True using the
> ribbon
>
> 1 - modPublicMacros.runSimulationQuestion) Run the special code...
>
> 2 - modSpecialCode.runSimulation) Display boolRenameSheets immediately
> before code execution stops
> boolRenameSheets = True
>
> 3 - Immediate Window) Use the immediate window to verify boolRenameSheets
> immediately after step 2 finishes
> ? boolRenameSheets
> False
>
> _________________________________________________
> 'modPublicMacros
>
> Option Compare Binary
> Option Explicit
> Option Base 0
>
> Public boolPrintDerivatives As Boolean
> Public boolRenameSheets As Boolean
>
> Public Sub runSimulationQuestion
> 'Pseudo Code....
> if msgBox() = vbYes Then modSpecialCode.runSimulation
> End Sub
>
> _________________________________________________
> 'ribbonCallBacks
>
> Option Private Module
> Option Compare Binary
> Option Explicit
> Option Base 0
>
> 'Callback for chkRenameSheets getPressed
> Public Sub gpRenameSheets(ByVal control As IRibbonControl, ByRef returnedVal)
> 'Set default value to True
> returnedVal = True
> boolRenameSheets = True
> End Sub
>
> 'Callback for chkRenameSheets onAction
> Public Sub cbSetRenameSheets(ByVal control As IRibbonControl, ByVal pressed
> As Boolean)
> 'Set value to checkbox value
> boolRenameSheets = pressed
> End Sub
>
> _________________________________________________
> 'modSpecialCode
>
> Option Private Module
> Option Compare Binary
> Option Explicit
> Option Base 0
>
> Public Sub runSimulation()
> runSimulationPartA
> End Sub
>
> Private Sub runSimulation
> deleteSheets
> GetInput
> runSimulationDLL
> populateOutput
> MsgBox boolRenameSheets & " complete" 'Shows true when
> runSimulationPartA begins execution with boolRenameSheets = true
> End Sub
>
> Private Sub deleteSheets
> 'delete old sheets
> End Sub
>
> Private Sub GetInput
> 'populate arrays
> End Sub
>
> Private Sub runSimulationDLL
> 'Execute the dll
> End Sub
>
> Private Sub populateOutput
> 'create new sheets
> End Sub


--

Dave Peterson
 
Reply With Quote
 
rogge
Guest
Posts: n/a
 
      14th Jan 2009
No instances of "End" exist. (no one here had tough of that, thank you for
this tip).

Here is the last part of "Private Sub runSimulation"
....
....
....
' Clear variables declared by solomonrunSPSLFeed
xlCalcType = Empty

' Error handler
On Error GoTo 0: MsgBox "A) " & boolRenameSheets & vbTab &
boolPrintDerivatives: Exit Sub

runSPSL_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
runSPSL of Module modSpyroSPSL", vbCritical + vbOKOnly, "Error"

End Sub


When the whole process begins with boolRenameSheets set to True, the message
box shows:
"A) True"

So I *know* that boolRenameSheets has kept the value up until this dialog
box is displayed. After "OK" is clicked; boolRenameSheets returns false in
the immediate window.


(Can one access the check box i have in the ribbon? maybe I can get its
value rather than use boolRenameSheets.)



"Dave Peterson" wrote:

> I don't know about the ribbon, but does any of your code use End (not End Sub,
> End Function, End if), just plain old End.
>
> This will reset those variables.
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      14th Jan 2009
I don't know anything about the ribbon.

Maybe someone else will jump in.

rogge wrote:
>
> No instances of "End" exist. (no one here had tough of that, thank you for
> this tip).
>
> Here is the last part of "Private Sub runSimulation"
> ...
> ...
> ...
> ' Clear variables declared by solomonrunSPSLFeed
> xlCalcType = Empty
>
> ' Error handler
> On Error GoTo 0: MsgBox "A) " & boolRenameSheets & vbTab &
> boolPrintDerivatives: Exit Sub
>
> runSPSL_Error:
> MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
> runSPSL of Module modSpyroSPSL", vbCritical + vbOKOnly, "Error"
>
> End Sub
>
> When the whole process begins with boolRenameSheets set to True, the message
> box shows:
> "A) True"
>
> So I *know* that boolRenameSheets has kept the value up until this dialog
> box is displayed. After "OK" is clicked; boolRenameSheets returns false in
> the immediate window.
>
> (Can one access the check box i have in the ribbon? maybe I can get its
> value rather than use boolRenameSheets.)
>
> "Dave Peterson" wrote:
>
> > I don't know about the ribbon, but does any of your code use End (not End Sub,
> > End Function, End if), just plain old End.
> >
> > This will reset those variables.
> >


--

Dave Peterson
 
Reply With Quote
 
rogge
Guest
Posts: n/a
 
      16th Jan 2009
As i study this issue today, my "fix" to the non-trappable "<application
error>" still occurs. This is my fix..

For i = wkbActive.Worksheets.Count To 1 Step -1
If (wkbActive.Worksheets(i).CodeName Like strDeleteSheet & "*") Then
Debug.Print "before " & boolRenameSheets
wkbActive.Worksheets(i).Delete
Debug.Print "after " & boolRenameSheets
End If
Next i

Ok, this is NOT where boolRenameSheets is reset. I ran the code
back-to-back after setting boolRenameSheets to True... Here is the output
from the code.

before True
after True
before False
(watch causes break)
after False

The watch causes code to break on the line: Debug.Print "after " &
boolRenameSheets as indicated above. HOWEVER, the value did not change.

Does this help any one help me? <shakes his cloudy head>


"Dave Peterson" wrote:

> I don't know anything about the ribbon.
>
> Maybe someone else will jump in.
>
> rogge wrote:
> >
> > No instances of "End" exist. (no one here had tough of that, thank you for
> > this tip).
> >
> > Here is the last part of "Private Sub runSimulation"
> > ...
> > ...
> > ...
> > ' Clear variables declared by solomonrunSPSLFeed
> > xlCalcType = Empty
> >
> > ' Error handler
> > On Error GoTo 0: MsgBox "A) " & boolRenameSheets & vbTab &
> > boolPrintDerivatives: Exit Sub
> >
> > runSPSL_Error:
> > MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
> > runSPSL of Module modSpyroSPSL", vbCritical + vbOKOnly, "Error"
> >
> > End Sub
> >
> > When the whole process begins with boolRenameSheets set to True, the message
> > box shows:
> > "A) True"
> >
> > So I *know* that boolRenameSheets has kept the value up until this dialog
> > box is displayed. After "OK" is clicked; boolRenameSheets returns false in
> > the immediate window.
> >
> > (Can one access the check box i have in the ribbon? maybe I can get its
> > value rather than use boolRenameSheets.)
> >
> > "Dave Peterson" wrote:
> >
> > > I don't know about the ribbon, but does any of your code use End (not End Sub,
> > > End Function, End if), just plain old End.
> > >
> > > This will reset those variables.
> > >

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Private Network Resets To Public =?Utf-8?B?VGhpc19Jc19Ccmlhbg==?= Windows Vista Networking 0 4th Mar 2007 09:12 AM
Re: Change public VBA variable from form VBScript code Sue Mosher [MVP-Outlook] Microsoft Outlook VBA Programming 0 20th Dec 2006 01:15 PM
Re: Change public VBA variable from form VBScript code Sue Mosher [MVP-Outlook] Microsoft Outlook Form Programming 0 20th Dec 2006 01:14 PM
NEWBIE - Accessing a public variable that is stored in another form's vb code Dave Microsoft Dot NET Compact Framework 1 18th Jan 2005 08:55 PM
Initializing a Public variable from code. Manuel Canas Microsoft ADO .NET 3 9th Sep 2004 07:04 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:27 AM.