Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming,microsoft.public.excel.worksheet.functions
|
|||
|
|||
Help Me - Array Failure
Hi John,
My next guess then is that your array is fine and it's your watch that's set wrong. When you add the array as a watch expression, make sure that (All Procedures) is selected in the Procedure dropdown of the Context section. If you add a watch expression from a specific procedure, then by default, the watch will only be defined while code executing within that procedure, even if the expression you're watching is global. -- Rob Bovey, MCSE, MCSD, Excel MVP Application Professionals http://www.appspro.com/ * Please post all replies to this newsgroup * * I delete all unsolicited e-mail responses * "John T Ingato" wrote in message ... Being new to Visual Basic all of the code is in one module exactly as is shown below. The functions work fine, as I watch the "Watch" window. For example, the variable MyStores(10) reflects the values being assigned to it. All is well until the LoadMyStores procedure ends. Then the watch window states the value is "out of context". Since it was declared outside of any function, I figured they would retain their values. Even when the array is declared as Public, the values disappear "Rob Bovey" wrote in message ... Hi John, It's not clear from your posting how this code is arranged in modules, but from your description it sounds as if your array declaration is the problem. Variables declared at the top of code modules with the keyword Dim have module-level scope (similar to static in C). Variables declared at the top of code modules using the Public keyword have global scope (similar to defining a variable in one file and then using extern to declare the variable to other files in C). Try changing your array declaration to: Public MyStores(Max) As Stores -- Rob Bovey, MCSE, MCSD, Excel MVP Application Professionals http://www.appspro.com/ * Please post all replies to this newsgroup * * I delete all unsolicited e-mail responses * "John T Ingato" wrote in message ... I am new to VB, coming from C. Perhaps had I stated with VB, I would be catching on sooner. I am trying to fill an array of a user-defined data types, which as you can see, is basic customer info. I am trying to pull this information from another workbook. I wrote the function to open the said workbook, copy its info into the array display the first five array member ( for Checking) and close the original file. It all works fine until I return to the calling function, when apparently the array falls out of scope. I defined the array outside of and procedure, so I thought it would be a global scope item. Where should I put this declaration? Please I am going bald!!! Any other suggetion would be welcome also. Here is the code I have so far: -------------------------------------------------------------------------- -- ---- Option Base 1 Public Type Stores StoreNum As Integer StoreName As String Market As Integer ServiceRep As String End Type Const Max = 60 Dim MyStores(Max) As Stores ' Here is what I thought was a Global Scoped Variable -------------------------------------------------------------------------- -- ---- Sub LoadMyStores() Dim i As Integer For i = 1 To 60 If IsNull(Workbooks("replist.xls") _ .Worksheets("stores").Range("A" & i + 1)) Then Exit For MyStores(i).StoreNum = Workbooks("replist.xls") _ .Worksheets("stores").Range("A" & i + 1) MyStores(i).StoreName = Workbooks("replist.xls") _ .Worksheets("stores").Range("B" & i + 1) MyStores(i).Market = Workbooks("replist.xls") _ .Worksheets("stores").Range("C" & i + 1) MyStores(i).ServiceRep = Workbooks("replist.xls") _ .Worksheets("stores").Range("D" & i + 1) Next i For i = 1 To 5 MsgBox (MyStores(i).StoreNum & " " & MyStores(i).StoreName _ & ", in Market " & MyStores(i).Market & " is serviced by " & MyStores(i).ServiceRep) Next i End Sub -------------------------------------------------------------------------- -- ---- Sub SetList() ' ' Workbooks.Open Filename:="C:\Program Files\FieldTracker\replist.xls" Application.WindowState = xlMinimized LoadMyStores Workbooks("replist.xls").Close End Sub -------------------------------------------------------------------------- -- ---- Sub Main() Call SetList ' call to another function to initialize storelist array End Sub -------------------------------------------------------------------------- -- ---- Please Please help me thru this madness! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Catastophic Failure | Excel Discussion (Misc queries) | |||
vlookup failure & ctrl-f failure? | Excel Discussion (Misc queries) | |||
failure of web query | Excel Discussion (Misc queries) | |||
AutoFilter Failure | Excel Worksheet Functions | |||
xls file failure | Excel Discussion (Misc queries) |