|
-
Mar 6th, 2002, 04:21 PM
#1
Thread Starter
Banned
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
-
Mar 6th, 2002, 04:24 PM
#2
Stuck in the 80s
where exactly are you getting the error and what error is it?
-
Mar 6th, 2002, 04:49 PM
#3
Thread Starter
Banned
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?
-
Mar 6th, 2002, 04:55 PM
#4
Stuck in the 80s
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)
-
Mar 6th, 2002, 05:07 PM
#5
Thread Starter
Banned
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!
-
Mar 6th, 2002, 05:13 PM
#6
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)
-
Mar 6th, 2002, 05:26 PM
#7
Thread Starter
Banned
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..........
-
Mar 6th, 2002, 05:59 PM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|