Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Saving / Reading dynamic arrays to / from disk

I have a dynamic array goShareInfo, which contains a dynamic array of
Type PriceInfo. In order for me to be able to save/read the array
properly, I have to save the dimensions of goShareInfo and set up the
array next time in the LoadShares procedure when I reload the
spreadsheet. Why do I have to do this when each element of IndexStruct
also contains an array of PriceInfo, but I don't have to do the same for
these - the arrays seem to get set up automatically.

I am using Office 2003 and if try and reload the array on the fly excel
just hangs

Type PriceInfo
ShareDate As Date
SharePrice As Double
End Type

Type IndexStruct
Index As String
Epic As String
FailureCount As Long
ShareName As String
zzNumDisp As Integer
ShareDets() As PriceInfo
End Type

Public goShareInfo() As IndexStruct



Sub LoadShares()

Dim liFile As Integer
Dim liNumShares As Long
Dim lsPath As String


lsPath = ThisWorkbook.Path & "\" & cSaveFile
liFile = FreeFile
Open lsPath For Binary As liFile
Get liFile, , liNumShares
ReDim goShareInfo(liNumShares)
Get liFile, , goShareInfo
Close liFile

End Sub


Sub SaveShares()

Dim liFile As Integer
Dim liNumShares As Long
Dim lsPath As String


lsPath = ThisWorkbook.Path & "\" & cSaveFile
If Dir(lsPath) < "" Then Kill (lsPath)
liFile = FreeFile
Open lsPath For Binary As liFile
liNumShares = UBound(goShareInfo)
Put liFile, , liNumShares
Put liFile, , goShareInfo
Close liFile

End Sub
--
Mike News
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Saving / Reading dynamic arrays to / from disk

In message
at 00:35:27 on Sun, 9 Sep 2007, Mike
S wrote
I have a dynamic array goShareInfo, which contains a dynamic array of
Type PriceInfo. In order for me to be able to save/read the array
properly, I have to save the dimensions of goShareInfo and set up the
array next time in the LoadShares procedure when I reload the
spreadsheet. Why do I have to do this when each element of IndexStruct
also contains an array of PriceInfo, but I don't have to do the same for
these - the arrays seem to get set up automatically.

I am using Office 2003 and if try and reload the array on the fly excel
just hangs

Type PriceInfo
ShareDate As Date
SharePrice As Double
End Type

Type IndexStruct
Index As String
Epic As String
FailureCount As Long
ShareName As String
zzNumDisp As Integer
ShareDets() As PriceInfo
End Type

Public goShareInfo() As IndexStruct



Sub LoadShares()

Dim liFile As Integer
Dim liNumShares As Long
Dim lsPath As String


lsPath = ThisWorkbook.Path & "\" & cSaveFile
liFile = FreeFile
Open lsPath For Binary As liFile
Get liFile, , liNumShares
ReDim goShareInfo(liNumShares)
Get liFile, , goShareInfo
Close liFile

End Sub


Sub SaveShares()

Dim liFile As Integer
Dim liNumShares As Long
Dim lsPath As String


lsPath = ThisWorkbook.Path & "\" & cSaveFile
If Dir(lsPath) < "" Then Kill (lsPath)
liFile = FreeFile
Open lsPath For Binary As liFile
liNumShares = UBound(goShareInfo)
Put liFile, , liNumShares
Put liFile, , goShareInfo
Close liFile

End Sub

I've played around with this and been more patient. What is happening
is that memory usage is gradually rising, up to the point where I get an
"Out Of Memory" error. goShareInfo had 102 elements and each could
contain up to 5 years worth of ShareDets rows i.e. typically 1260 rows.

I reduced the number of ShareDets records to about 1 years worth (i.e.
252 records) for the same 102 shares, and a similar thing was
happening. Memory usage would shoot up over a 30-60 second period, but
eventually I would get control of the program back. The array is
correctly set up with the 102 rows in goShareInfo, the contents are all
OK look, and the memory usage would stay at its high level

By dimensioning the goShareInfo array up front, the data loads in less
than a second and memory usage hardly alters. So why is this the case?
--
Mike News
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Saving / Reading dynamic arrays to / from disk

In message
at 18:50:51 on Tue, 11 Sep 2007, Mike
S wrote
By dimensioning the goShareInfo array up front, the data loads in less
than a second and memory usage hardly alters. So why is this the case?

Sorry I was lying. The array must have been initialised when I was
playing around with it

In my example of reading liNumShares (whose value is 102), and then
using ReDim goShares(liNumShares), this causes the memory usage to go
up. However if I manually RedDim goShares(102) this works fine.

Very strange indeed
--
Mike News
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Saving / Reading dynamic arrays to / from disk

In message
at 20:55:27 on Thu, 13 Sep 2007, Mike
S wrote
Sorry I was lying. The array must have been initialised when I was
playing around with it

In my example of reading liNumShares (whose value is 102), and then
using ReDim goShares(liNumShares), this causes the memory usage to go
up. However if I manually RedDim goShares(102) this works fine.

Very strange indeed

I think I've found the solution to this now
--
Mike News
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Saving / Reading dynamic arrays to / from disk

In message
at 17:55:16 on Fri, 14 Sep 2007, Mike
S wrote
In message
at 20:55:27 on Thu, 13 Sep 2007, Mike
wrote
Sorry I was lying. The array must have been initialised when I was
playing around with it

In my example of reading liNumShares (whose value is 102), and then
using ReDim goShares(liNumShares), this causes the memory usage to go
up. However if I manually RedDim goShares(102) this works fine.

Very strange indeed

I think I've found the solution to this now

Soln to upgrade to patch to SP2 wasn't correct. I changed my num vars
from Long's to Integer's even though UBound returns a type long - this
seems to be what does the trick, although I haven't tried it enough
times to give me confidence yet
--
Mike News


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
Saving an array or class to disk Wired Hosting News Excel Programming 0 March 24th 06 10:54 PM
Saving onto Floppy Disk woodbunny Excel Worksheet Functions 1 August 17th 05 03:43 PM
Saving to disk Karen Excel Discussion (Misc queries) 2 January 7th 05 07:13 PM
Saving embedded object to disk cbhanes Excel Programming 0 May 10th 04 04:02 PM
Picture in Web Page (saving to disk) S. Stilwell Excel Programming 0 July 14th 03 11:29 PM


All times are GMT +1. The time now is 05:48 PM.

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

About Us

"It's about Microsoft Excel"