Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Runtime error 9

Status
Not open for further replies.

artadmin

MIS
Oct 3, 2002
17
US
I have a VB app that executes a DOS command which generates a text file.

The code then reads the text file and proceeds.

The DOS command executes correctly, then I get a RT error 9, subscript out of range.
If I immediately run the executable again, the program is proceeds normally.


Also, how do you "clean up" after your program terminates?

Thanks.
 
You don't clean up after your progam terminates, you do that before it terminates. Cleaning up is releasing any pointers, handles and such you might have collected during the execution of your program, unloading all forms etc. etc.

There's no way anyone can help you on the first issue, unless you post some relevant code and indicate the line at which the error occurs.

Greetings,
Rick
 
Below are the two lines that I think are causing me trouble.

sFileContents will equal one string of text, seperated by " ". I cannot predict the number of entries this string will contain. The string will contain numbers and letters, if that helps.

I haven't used any dim or redim statements. This is what I think is causing the problem.


sFileContents = Pack(ReadFileContents(TempFile))

StrArray = Split(sFileContents, " ", -1)

In short:
I need an array.
I don't know how long it needs to be.
I need it to contain text.
 
cant see that being the problem! (but u might try adding Dim strArray() as string)

Subscript out of range (Error 9)

are you looping through all the strArray elements?

what happens when u single step the code... does it stop at these lines!!

NB " " and -1 are the default deliminator and count for the split statement

good luck

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
The Great Date Debate Thread222-368305
File Formats Galore @ or
 
I used the Dim statement, but I still get the error.
But I found the problem later on. I know that the 2nd value of my array is always going to be the one I want. The split works fine. The next line is

Session = StrArray(2)

this causes the error.

I have: Dim Session as string in my global declarations.
 
Looks like I had to Redim the array with the Preserve command after I split my string


. . .thanks.
 
have you tried
msgBox str(ubound(StrArray))
before
Session = StrArray(2)
?
 
>I know that the 2nd value of my array is always going to be the one I want

the second value of the strArray is

Session = StrArray(1)

and not

Session = StrArray(2)

because arrays are 0 based unless u have set

option base 1

good luck!

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
The Great Date Debate Thread222-368305
File Formats Galore @ or
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top