Results 1 to 8 of 8

Thread: String array problem

  1. #1

    Thread Starter
    Banned Michael_Kamen's Avatar
    Join Date
    May 2001
    Location
    The Netherlands
    Posts
    1,180

    Angry String array problem

    Hi,

    I have an app which searches for all the MS Agent Characters on the pc and stores their names in an array, so I can load them later.
    I have this code to add them to the array but it's not working:
    The array AgentNames has been declared in General Declarations
    Code:
    Dim FSO As FileSystemObject
        Dim FSOFolder As Folder
        Dim FSOFile As File
        Dim sPath As String
            
        On Local Error Resume Next
        Set FSO = New FileSystemObject
        
        ' Load Characters into array
        sPath = FSO.GetSpecialFolder(WindowsFolder) & "\MSAgent\Chars\"
        If FSO.FolderExists(sPath) Then
            Set FSOFolder = FSO.GetFolder(sPath)
            lCount = 0
            For Each FSOFile In FSOFolder.Files
            ReDim Preserve AgentNames(UBound(AgentNames) + 1) As String
            AgentNames(lCount) = FSOFile.Name
            lCount = lCount + 1
            Next
        Else
            MsgBox "Error while loading characters!", vbOKOnly + vbCritical, "Error"
            Unload Me
        End If
    When I want to scroll through the names with 'AgentNames(scrollindex), it gives an error.

    Does anyone know what I should do?

    Tnx in advance,

    MK

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    where exactly are you getting the error and what error is it?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3

    Thread Starter
    Banned Michael_Kamen's Avatar
    Join Date
    May 2001
    Location
    The Netherlands
    Posts
    1,180
    I use this to scroll through the array:
    CharScroll is a public Int
    Code:
    If CharScroll < lCount Then
    CharScroll = CharScroll + 1
    Else
    CharScroll = 0
    End If
    Then I use this code to load the Agent:

    Code:
       Set Assistant = Nothing
       CoreAgent.Characters.Unload ("Assistant")
       CoreAgent.Characters.Load "Assistant", AgentNames(CharScroll)
       Set Assistant = CoreAgent.Characters("Assistant")
       Assistant.LanguageID = &H409
       Assistant.Show
    Then at the line 'CoreAgent.Characters.Load "Assistant",AgentNames(CharScroll) VB gives the error: "Subscript out of range"

    What am I doing wrong?

  4. #4
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Make Sure CharScroll is not going above the max of AgentNames.

    One way to tell what the max of AgentNames is is to print it's ubound. "Debug.Print Ubound(AgentNames) & " - " & CharScroll"

    Make sure that CharScroll never goes above the Ubound(AgentNames)
    My evil laugh has a squeak in it.

    kristopherwilson.com

  5. #5

    Thread Starter
    Banned Michael_Kamen's Avatar
    Join Date
    May 2001
    Location
    The Netherlands
    Posts
    1,180
    It's not possible for CharScroll to exceed the max of AgentNames.
    The max of AgentNames = LCount and CharScroll cannot exceed LCount.

    And the error already occurs after I've scrolled 1 time.
    In Form_Load I set ScrollChar to 0, so the error already occurs when ScrollChar is 1, and LCount is 2(On my PC)

    So i think the problem has something to do with the declaration of my Array, but I cannot find anything!

    But tnx for your time and efforts!

  6. #6
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    Do you have
    Dim Variable (0 to [upperbound]) as sometype

    ??

    Or simply
    Dim Variable as sometype
    or
    Dim Variable() as sometype

    ??
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  7. #7

    Thread Starter
    Banned Michael_Kamen's Avatar
    Join Date
    May 2001
    Location
    The Netherlands
    Posts
    1,180
    I've declared in General Declarations as:

    Dim AgentNames() as string

    Since I don't know how much MS Agent Characters there are installed on the PC when my app loads, I cannot give it a length yet..........

  8. #8
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    You still need to give it a length, then use another variable to track how many indexes you are using.

    I usually end up creating a TYPE for these sort of cases.

    Public Type MyType
    indexes as integer
    myarray(1 to 255) as integer
    end type

    dim myvar as mytype
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width