Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 811
Default 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
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
Catastophic Failure Soccer boy[_2_] Excel Discussion (Misc queries) 2 March 3rd 09 03:51 PM
vlookup failure & ctrl-f failure? joemeshuggah Excel Discussion (Misc queries) 4 December 22nd 08 07:22 PM
failure of web query Dr Alok Modi MD Excel Discussion (Misc queries) 0 February 21st 08 12:06 PM
AutoFilter Failure Narlyb Excel Worksheet Functions 1 December 28th 05 05:53 PM
xls file failure lendapilot Excel Discussion (Misc queries) 5 January 17th 05 10:37 PM


All times are GMT +1. The time now is 11:56 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"