-
Dec 3rd, 2007, 09:53 AM
#1
Thread Starter
New Member
Runtime Error '9': Subscript out of range
I have run into this persistent problem with a project. I can compile just fine, I can even run the project without a problem. However, when I make the executable and then run the executable i get the error, "Runtime Error '9': Subscript out of range".
I have literally removed all the code, components, references, modules, etc. and still get the error on a bare bones nothing proejct. Very strange to say the least.
I started a new project and started to import everything from scratch again. I am now at a point in which I have 2 modules, 1 class, and 1 form along with a data environment in the project.
Once again, I can compile and run the program without a problem at all. Making the executable and then running the executable fails with the aformentioned error code.
Taking out the line of code the creates the instance of the class gets rid of the error.
"Set gEmailSettings = New Email_Settings"
I am really stumped. I don't understand the error at all and all the code is pretty basic at the moment.
Any ideas would be greatly appreciated.
-
Dec 3rd, 2007, 10:16 AM
#2
Re: Runtime Error '9': Subscript out of range
Welcome to the forums.
Try to do a "Run With Full Compile" from the IDE....it should blow up on the line causing the error.
-
Dec 3rd, 2007, 07:13 PM
#3
Thread Starter
New Member
Re: Runtime Error '9': Subscript out of range
I had been running it from the ide with full compile. I get no error at all.
-
Dec 3rd, 2007, 08:52 PM
#4
Re: Runtime Error '9': Subscript out of range
As far as I know you can only get this error from a few different things.
Code:
Dim C As Collection, V
Set C = New Collection
C.Add 1
V = C.Item(2)
Collections are not that common so I guess it's a array subscript problem.
Your first post suggests that the class is at fault....
How about posting your project
-
Dec 3rd, 2007, 09:48 PM
#5
Thread Starter
New Member
Re: Runtime Error '9': Subscript out of range
All of this code works just fine during debugging and will work just fine with a full compile as well. It is only the executable that fails.
I do have a couple of arrays in the class module.
Code:
Private Function ParseCLA()
Dim tArray() As String ' Temporary String array to hold all parsed arguments
' Use the split function to parse out all arguments into an array
tArray() = Split(Command, ";")
' Takes the first 3 arguments and assigns them to the global variables
gSpinLoc = tArray(0)
gCurrentUser = tArray(1)
gCurrentBrokerID = tArray(2)
End Function
I have a private type for the module as well that is used in an array:
Code:
Private Type AccountSettings
sHostName As String ' Holds the full hostname URL
sEADD As String ' Email address of the account
sRPort As Integer ' Port to retrieve email on. Standard is 143
sUseSSL As Boolean ' SSL is required or not
sUName As String ' Username for the account
sPass As String ' Password for the account
sAccountName As String ' Friendly name of the account
sFullName As String ' Full Name of the user
sPlainTextPass As Boolean ' If a plain text password should be used
End Type
This is the code that uses the type in an array:
Code:
Private Function GetPrimaryEmailSettings()
Dim tRST As ADODB.Recordset ' Temporary recordset to obtain email settings
Dim tErr As Integer ' Holds custom error code
Dim tNum As Integer ' Temporary variable to move through the recordset
' Set the error code to 0
tErr = 0
' Open the connection to SArtData.mdb
DCON.SARTDATA.Open
' Determine how many email accounts exist
Set tRST = DCON.SARTDATA.Execute("SELECT Count(*) As Amount FROM [EMAIL-ACCOUNTS]")
' If no email accounts exist then trigger an error and terminate the program,
' otherwise initiate the gESA() array to contain the number of accounts found
If tRST!Amount <= 0 Then
tErr = 1
GoTo PrimaryAccountError
Else
ReDim gESA(1 To tRST!Amount) As AccountSettings
End If
' Grab just the Primary Account
Set tRST = DCON.SARTDATA.Execute("SELECT * FROM [EMAIL-ACCOUNTS] WHERE PRIMARYACCOUNT = -1")
' If no Primary Account exists then trigger an error and terminate the program
If tRST.EOF = True Then
tErr = 2
GoTo PrimaryAccountError
End If
' Set the first element in gESA() to the primary account settings
gESA(1).sEADD = tRST!Email_Address
gESA(1).sHostName = tRST!Host_Incoming
gESA(1).sPass = tRST!Email_Password
gESA(1).sRPort = tRST!Port_Incoming
gESA(1).sUName = tRST!User_Name
gESA(1).sUseSSL = tRST!SSL_IN
gESA(1).sAccountName = tRST!Account_Name
gESA(1).sPlainTextPass = tRST!PlainTextPass
gESA(1).sFullName = tRST!Full_Name
' Grab all the secondary accounts
Set tRST = DCON.SARTDATA.Execute("SELECT * FROM [EMAIL-ACCOUNTS] WHERE PRIMARYACCOUNT = 0")
' Loop through the accounts and set the gESA()
If tRST.EOF = False Then tRST.MoveFirst
tNum = 2 ' This is set to 2 since it is the beginning of the secondary accounts in gESA()
Do While Not tRST.EOF
gESA(tNum).sEADD = tRST!Email_Address
gESA(tNum).sHostName = tRST!Host_Incoming
gESA(tNum).sPass = tRST!Email_Password
gESA(tNum).sRPort = tRST!Port_Incoming
gESA(tNum).sUName = tRST!User_Name
gESA(tNum).sUseSSL = tRST!SSL_IN
gESA(tNum).sAccountName = tRST!Account_Name
gESA(tNum).sPlainTextPass = tRST!PlainTextPass
gESA(tNum).sFullName = tRST!Full_Name
tNum = tNum + 1
tRST.MoveNext
Loop
' Close the data connection and set the recordset object to nothing
DCON.SARTDATA.Close
Set tRST = Nothing
Exit Function
' Custom error. Will inform the user if no accounts exist or if a primary account does not exist.
PrimaryAccountError:
If tErr = 1 Then
RaiseEvent AccountError(1)
End If
If tErr = 2 Then
RaiseEvent AccountError(2)
End If
End Function
-
Dec 7th, 2007, 10:04 PM
#6
Re: Runtime Error '9': Subscript out of range
Originally Posted by ed207
All of this code works just fine during debugging and will work just fine with a full compile as well. It is only the executable that fails.
I do have a couple of arrays in the class module.
Code:
Private Function ParseCLA()
Dim tArray() As String ' Temporary String array to hold all parsed arguments
' Use the split function to parse out all arguments into an array
tArray() = Split(Command, ";")
' Takes the first 3 arguments and assigns them to the global variables
gSpinLoc = tArray(0)
gCurrentUser = tArray(1)
gCurrentBrokerID = tArray(2)
End Function
As milk pointed out:
and with your directive such that tArray() = Split(Command, ";")
and then immediately after you say :
gSpinLoc = tArray(0)
gCurrentUser = tArray(1)
gCurrentBrokerID = tArray(2)
You never check the ubound of tArray().
I would suggest that wherever you assign a variable to a value of an array that you've created by the split function, that you check first if its ubound is at least that of the maximum index that you intend to be available.
-Lou
Last edited by NotLKH; Dec 8th, 2007 at 09:33 AM.
-
Dec 17th, 2007, 08:13 AM
#7
Thread Starter
New Member
Re: Runtime Error '9': Subscript out of range
Sorry for the long reply. I appreciate your help. I included a check to see if Command was null, then checked the ubound of the array. Any problems is "supposed" to raise an event. That however, is not working and the subject of another post......
-
Dec 4th, 2007, 01:59 AM
#8
Re: Runtime Error '9': Subscript out of range
Do you have any command line arguments in your app that are pre-set in the IDE? When you run the compiled exe you also need to pass those arguments or it will error.
Create a shortcut to your compiled exe and set the arguments in the properties of the shortcut.
"C:\SomePath\MyEXE.exe" ;Arg1 ;Arg2
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
-
Dec 4th, 2007, 05:02 AM
#9
Re: Runtime Error '9': Subscript out of range
That would seem logical, the code assumes there will always be three command line arguments passed. It should really check first.
-
Dec 4th, 2007, 05:29 AM
#10
Re: Runtime Error '9': Subscript out of range
Yup, a check would have prevented the errors and some kind of notification to the user that arguments were not being passed would have saved allot of time on this issue.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
-
Dec 17th, 2007, 10:59 AM
#11
Re: Runtime Error '9': Subscript out of range
Well Command$ will never be Null as it would be vbNullstring.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
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
|