Runtime Error 9 in VB App

Posted on 2004-11-12
Last Modified: 2012-08-14
i have a VB6 program, which imports data from text files into a MS SQL DB.
i can run this program from inside vb6 on any computer without an error.
if i compile the exe and run it on Windows Server 2003, it  stops with "Runtime Error 9" end ends.
how can i find, which code is causing the error?
or is it an OS issue or something else?
Question by:WeHe
    LVL 52

    Accepted Solution

    Its quite possibly a Server 2003 related issue.  There are lots of changes/new features in 2003 that can effect the way some things work.  

    Error number 9 is "Subscript out of range", so you need to start by looking at anywhere in your app that you use arrays (specifically looping through arrays)

    Hope this helps.
    LVL 76

    Assisted Solution

    Subscript out of range is a common run-time error.

    It could mean that you are now using external data to index an array, and that the number is not what was expected.

    If you are certain that  you are always testing your data for sanity, then I suggest a trace log. There is a logging facility in VB, but it doesn't work in design mode, so I use a simple procedure. It starts a new one each day for easier management.

    Sub WriteLog(Text As String)
        Dim f As Integer
        Dim strFileName As String
        strFileName = "abc" & Format$(Now, "MMy") & ".log"
        Text = Format$(Now, "HH:nn:ss") & " " & Text
        Debug.Print Text
        f = FreeFile
        Open App.Path & "\" & strFileName For Append As #f
            Print #f, Text
        Close #f
    End Sub

    As a start, try putting calls in at the top of each sub and function. That way you'll narrow it to down to a particular procedure.


    Sub MyProc(Par1 as string)

    Writelog "Procedure: MyProc. Parameter Par1=" & Par1

    End Sub
    LVL 10

    Assisted Solution

    It could be that the app cannot find the text files on the server machine or a file is empty. My guess is that it loads arrays when processing the files and then in turn loops through the arrays processing them.
    LVL 48

    Assisted Solution

    please post code
    LVL 11

    Author Comment

    When i have found the part, where the error is caused, i will post it.
    atm i have to work on our wins for a while.
    LVL 11

    Author Comment

    i don't know why, but now the app is running without any error.
    thank you for your comments

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now