Help with memory/resource use

J

Jacob.Bruxer

Hi,
I'm pretty new to Visual Basic and was wondering if anyone could give
some general advise on how to conserve memory when running a Visual
Basic program that I've created. I keep getting a "Win32 exception was
unhandled" error, and I'm pretty sure resource usage is the problem.
This might be way too general of a question, so I'll try to explain
what it is I'm trying to do as briefly as I can.

Basically, my program reads a text file that's about 30 kb in size, and
about 450 lines long. Each line contains 8 comma delimited variables.
I use the System.IO.StreamReader tool to do this, and read each line
seperately and store each line in a String array. I then create
another array called "variable(7)" (one space for each comma seperated
value). I have a For loop that then changes the text in a combo box
and a number of text boxes to be read later. Looks something like this
(Note: j = total number of lines + approx. 450):

Dim variable(7) As String

For i = 1 To j
variable = Split(ReaderText(i), ",")
cboxSecType.Text = variable(0)
txtMannings.Text = variable(1)
txtLength.Text = variable(2)
txtSlope.Text = variable(3)
txtPeakFlow.Text = variable(4)
txtTimeToPeak.Text = variable(5)
txtNSAVE.Text = variable(6)
Call WriteMultiInput()
ProgressBar.Value = ProgressBar.Value + 1
Next i

The string array variable(7) is only created once, but the values in
variable(7) change as I'd like them to each time through the For loop.
The function Call WriteMultiInput() shown above in the For loop
basically writes and saves a new textfile for each loop using the
variables above plus a number of others, some of which change
automatically depending on the variables that are initially read. Each
of the text files written is pretty small - about 3 to 5 kb in size.
There are a number of other variables that are saved when writing each
new text file.

Overall my program works as I want it to. It runs and writes the text
files exactly as I'd like it to up to a certain point (approximately 50
text files, approx. 3-5 kb per file, total of about 205 kb). But it
stops around 50 and I'd like to get it to the 450 I'm trying to read.

So, I hope that wasn't too long-winded, but if you're still with me,
any thoughts?
 
T

tomb

A couple of thoughts:
In each loop, the text boxes are changed. At the end, you'll have the
final loop values. What is the point of changing them all the way through?

You don't show the initialization of the progress bar - does it allow
for the correct number of lines?

Ignoring that, there doesn't seem to be anyting in this loop that would
cause a problem - maybe the real issue is in WriteMultiInput().

I would recommend putting a try-catch block around the loop, and also in
the WriteMultiInput() method, and put a breakpoint in the catch
statement. Something may show up that way.

Tom
 
J

Jacob.Bruxer

Sorry, I initialize the progress bar and set the maximum value before
starting the For loop, I just didn't include it in my post.
Also, the sub WriteMultiInput() is called every time through the For
loop, so the text boxes change every time in the For Loop, and each
time WriteMultiInput() is called, it uses the values in each text box
at that instant of time (ie. during the For loop) to write a new text
file. During the next loop, the values change, WriteMultiInput() is
called again, and it again uses the new values to create another new
text file. That's why they change all the way through. The loop is
supposed to go on until variables from all 450 lines initially read
from the initial text file are used, but for some reason it gets the
Win32 error after 53 loops every time.
Also, WriteMultiInput() is a sub that writes the final text file, but
within this sub there are a number of other subs that are also called,
which output values that are also used in WriteMultiInput() in addition
to those from the For Loop I showed. Note that the Win32 error occurs
in one of these other subs, but again, not until the 53rd time through
the loop.
Boy this must sound confusing, I hope I'm making myself somewhat clear.
 
T

tomb

If the error is in another sub, how can we help without seeing what
those other subs are doing?

T
 
J

jacob.bruxer

I have far too much code in far too many subs to post it all online. I
was hoping that from what I have said I'd be able to get some general
information on what might be causing the problem and then be able to
search all my code myself and fix the problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top