Winsock Error '9': Subscript Out Of Range Please Help !
Hi I have found a lot of usefull help here and I was hoping that someone could help me with my VB Problem ? When I run my app i get this error message after logging in about 2 yahoo id's Runtime error '9': Subscript out of range
This seems to either be happening on Sock_Connect or Sock_DataArrival
This is the code for both:
Private Sub Sock_Connect(Index As Integer) Label3.Caption = "Status: Logging In" Sock(Index).SendData Data(YahooID(Index)) End Sub Private Sub Sock_DataArrival(Index As Integer, ByVal bytesTotal As Long) Dim Data As String Sock(Index).GetData Buffer(Index) Debug.Print Buffer(Index) If Mid(Buffer(Index), 12, 1) = "W" Then SessionKey(Index) = Mid(Buffer(Index), 17, 4) ChallengeString(Index) = Mid(Buffer(Index), 30 + Len(YahooID(Index)), Len(Buffer(Index)) - 29) ChallengeString(Index) = Replace(ChallengeString(Index), "À€13À€1À€", "") Call GetStrings(YahooID(Index), Password(Index), ChallengeString(Index), Crypt1(Index), Crypt2(Index), 1) Sock(Index).SendData Login(YahooID(Index), Crypt1(Index), Crypt2(Index), SessionKey(Index)) ElseIf Mid(Buffer(Index), 12, 1) = "T" Then Label3.Caption = "Status: Wrong ID/Pass." List1.AddItem YahooID(Index) & " Wrong ID/Pass" Sock(Index).Close ElseIf Mid(Buffer(Index), 12, 1) = "U" Then SessionKey(Index) = Mid(Buffer(Index), 17, 4) Label3.Caption = "Status: " & YahooID(Index) & " Logged In" Label7.Caption = Label7.Caption + 1 End If End Sub
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Excel Range In Variant Array, 'Subscript Out Of Range' Error
Morning Guru's
I have been having problems with this function for a few days now. I'd be most grateful if one of you could set me straight with this. Here is my code:
Code:
Private Function RemoveNulls(ByVal srcRange As Excel.Range, ByVal lastRow As Long)
MsgBox srcRange.Address
Dim i As Long
Dim xlVals() As Variant
xlVals = srcRange.Value
For i = LBound(xlVals) To UBound(xlVals)
If xlVals(i) = -9999 Then xlVals(i) = 0
Next i
srcRange.Value = xlVals
Set srcRange = Nothing
End Function
The compiller gives me the 'Subscript out of Range' error on the line:
If xlVals(i)=-9999 Then xlVals(i)=0
In-fact if I try to get a msgbox or something to display any value in the array, I get the same error. The Lbound and UBound functions are returning the expected values, therefore I believe that the array definately contains data!?
Any Ideas Amigo's?
Thanks
Subscript Out Of Range Error
I created an add-in that I sent to someone else's pc. The program works fine on my machine and when they pick something from user form menu, the subscript out of range error appears.
Does anyone have some ideas for a solution
Thanks
Error 9: Subscript Out Of Range.
I plan on writing a program that takes a combination of letters(e.g. a word), and displays all combinations of those letters. I'm still in early development (translation: 'I'm racking my brain trying to come up with an algorithim'), and I'm testing a few concepts. The problem is that I'm trying to split the letters from a textbox into a variable array. I then want to put them into an output box, arranged vertically. I can't figure out how to get it to split w/o a delimiter, so until I do, you have to put '/' between each charachter. But whenever I test the code, I get an error that MSDN didn't provide much help with.
Code:
Option Explicit
Option Base 1
Dim A() As String
Dim X As Integer
Dim Length As Integer
Private Sub cmdCombo_Click()
A() = Split(txtWord.Text, "/")
Length = Len(txtWord.Text)
For X = 1 To Length
txtout.Text = txtout.Text & A(X) & vbCrLf
Next X
End Sub
Thanks.
Help With My Subscript Out Of Range Error
Code:
Public Sub getDateArray()
ReDim dateArray(numberOfLines)
Dim txt, a
For i = 0 To UBound(arrRawData)
txt = arrRawData(i)
a = Split(txt)
'picDisplay.Print (a(0))
'picDisplay.Print (a(1))
'picDisplay.Print (a(2))
'picDisplay.Print (a(3))
dateArray(i) = a(0) 'first word
Next
End Sub
The problem is with this line:
Code:
dateArray(i) = a(0) 'first word
When I print the words eg:
Code:
picDisplay.Print (a(0))
picDisplay.Print (a(1))
picDisplay.Print (a(2))
picDisplay.Print (a(3))
Its working fine, but when I try to assign the substring to the new array Im getting this error.
Thanks
Help Subscript Out Of Range Error
Hi im a noob
I cant get past this error:
Option Explicit
Dim strFileName As String
Dim numberOfLines As Integer
Dim arrRawData() As String
Dim strLine As String
Dim i As Integer
Private Sub cmdStart_Click()
strFileName = "C:windowsdesktopTaskMyFile.dat"
numberOfLines = openInputFile(strFileName)
arrRawData = fillArray(numberOfLines)
For i = 0 To numberOfLines
picDisplay.Print (arrRawData(i))
i = i + 1
Next i
End Sub
Public Function openInputFile(strFileName As String) As Integer
Dim count As Integer
Dim i As Integer
Open strFileName For Input As #1
Do Until (EOF(1) = True)
Line Input #1, strLine
count = count + 1
Loop
Close #1
End Function
Public Function fillArray(count As Integer) As String()
i = 0
ReDim arrRawData(count)
Open strFileName For Input As #1
Do Until (EOF(1) = True)
Line Input #1, strLine
arrRawData(i) = strLine
i = i + 1
Loop
Close #1
End Function
Can you help?
Subscript Out Of Range (Error 9)
I hate this error. ;-)
This error occur when reading an array.
To test it I used debug.print to see what that did, and it prints out whats inside the array (index 1) and then halt with that error on that line, so it works, but then halt?
I know nothing.
Subscript Out Of Range Error
I'm trying to create a skateboarding game, and sometimes, when Skateboarder.Skill = 2, I boardslide, and get Subscript Out of Range. It highlights Select Case Result(n). Could it be my Rnd number is too high or too low? Could you look at it please and tell me if you see anything wrong. I've also attached my kickflip sub, that hasn't given any errors....yet.
Code:
Private Sub cmd_Boardslide_Click()
Dim Result() As Variant
Dim n As Integer
If cSkate Then
If tGB + 20000 < GetTickCount Then
cSkate = False
ElseIf tGB + 20000 > GetTickCount Then
MsgBox "You can't skate, wait a minute."
txt_Result.Text = ""
End If
End If
If cSkate = True Then Exit Sub
Select Case Skateboarder.Skill
Case 1
Result = Array("Almost got the B/S.", "Pretty wicked grind.", "It seems like your board is going to crack, take a break.")
n = Int(Rnd * 3) + 1
Case 2
Result = Array("Almost got the B/S.", "Pretty wicked grind.", "It seems like your board is going to crack, take a break.", "Boardsliding like that will get you sponsored!")
n = Int(Rnd * 4) + 1
Case 3
Result = Array("Almost got the B/S.", "Pretty wicked grind.", "It seems like your board is going to crack, take a break.", "Boardsliding like that will get you sponsored!", "Grrrrrrriiiiiiiinnnnnnnnddddddd.......")
n = Int(Rnd * 5) + 1
Case 4
Result = Array("Almost got the B/S.", "Pretty wicked grind.", "It seems like your board is going to crack, take a break.", "Boardsliding like that will get you sponsored!", "Grrrrrrriiiiiiiinnnnnnnnddddddd.......", "Your board went a little slow, you landed it, but you should wax up that rail.")
n = Int(Rnd * 6) + 1
Case 5
Result = Array("Almost got the B/S.", "Pretty wicked grind.", "It seems like your board is going to crack, take a break.", "Boardsliding like that will get you sponsored!", "Grrrrrrriiiiiiiinnnnnnnnddddddd.......", "Real smooth boardslide there.", "Your board went a little slow, you landed it, but you should wax up that rail.")
n = Int(Rnd * 7) + 1
Case 6
Result = Array("Almost got the B/S.", "Pretty wicked grind.", "It seems like your board is going to crack, take a break.", "Boardsliding like that will get you sponsored!", "Grrrrrrriiiiiiiinnnnnnnnddddddd.......", "Your board went a little slow, you landed it, but you should wax up that rail.", "Ouch! Keep your balance next time!", "Real smooth boardslide there.")
n = Int(Rnd * 8) + 1
Case 7
Result = Array("Almost got the B/S.", "Pretty wicked grind.", "It seems like your board is going to crack, take a break.", "Boardsliding like that will get you sponsored!", "Grrrrrrriiiiiiiinnnnnnnnddddddd.......", "Your board went a little slow, you landed it, but you should wax up that rail.", "Ouch! Keep your balance next time!", "You were just tearin' up the rails! Nice!", "Oh man, wow, I don't know, that was just so killer.", "Real smooth boardslide there.")
n = Int(Rnd * 9) + 1
End Select
Select Case Result(n)
Case "Almost got the B/S."
tLanded = tLanded - 1
Case "Pretty wicked grind."
tLanded = tLanded + 1
Case "It seems like your board is going to crack, take a break."
cSkate = True
tGB = GetTickCount
Case "Boardsliding like that will get you sponsored!"
tLanded = tLanded + 1
Case "Grrrrrrriiiiiiiinnnnnnnnddddddd......."
tLanded = tLanded + 1
Case "Your board went a little slow, you landed it, but you should wax up that rail."
tLanded = tLanded + 1
Case "You were just tearin' up the rails! Nice!"
tLanded = tLanded + 1
Case "Ouch! Keep your balance next time!"
tLanded = tLanded - 1
Case "Oh man, wow, I don't know, that was just so killer."
tLanded = tLanded + 1
Case "Real smooth boardslide there."
tLanded = tLanded + 1
End Select
txt_Result.Text = Result(n)
If tLanded < 0 Then tLanded = 0
Select Case tLanded
Case 10
If Skateboarder.Skill < 3 Then
Skateboarder.Skill = Skateboarder.Skill + 1
End If
If MsgBox("Nice job! Ten tricks in a row! Would you like to try your luck at a tournament?", vbYesNo) = vbYes Then
frmTournament.Show
Else
MsgBox "Alright, but in 10 more tricks your at the tournament!"
End If
Case 20
If Skateboarder.Skill < 4 Then
Skateboarder.Skill = Skateboarder.Skill + 1
End If
frmTournament.Show vbModal
Case 30
If Skateboarder.Skill < 5 Then
Skateboarder.Skill = Skateboarder.Skill + 1
End If
Skateboarder.Skill = Skateboarder.Skill + 1
frmTournament.Show vbModal
Case 40
If Skateboarder.Skill < 6 Then
Skateboarder.Skill = Skateboarder.Skill + 1
End If
Skateboarder.Skill = Skateboarder.Skill + 1
frmTournament.Show vbModal
Case 50
If Skateboarder.Skill < 7 Then
Skateboarder.Skill = Skateboarder.Skill + 1
End If
Skateboarder.Skill = Skateboarder.Skill + 1
frmTournament.Show vbModal
Case 60
If Skateboarder.Skill < 8 Then
Skateboarder.Skill = Skateboarder.Skill + 1
End If
Skateboarder.Skill = Skateboarder.Skill + 1
frmTournament.Show vbModal
Case 70
MsgBox "Alright now, you've landed a lot of tricks, its time for you to restart."
Skateboarder.Skill = 1
tLanded = 0
Sponsored = False
End Select
frmStats!lbl_StatsLanded.Caption = "Tricks Landed: " & tLanded
End Sub
Subscript Out Of Range Error?
i'm getting that error when i use the following code, i've got a listbox with 2 values, i'm trying to sum the second value (sale_price) of the listbox in a textbox? all the data is coming from an oracle db, any help v much appreciated.......
Dim ArrayOfString() As String
Dim nprice As String
While rs.EOF = False
lstStock.AddItem rs.Fields("stock_name").Value & vbTab & _
rs.Fields("sale_price").Value
ArrayOfString() = Split(lstStock.Text, vbTab)
nprice = CInt(ArrayOfString(1))
txttotal.Text = nprice
rs.MoveNext
Wend
Subscript Out Of Range Error.
hi all,
i am uploading my client that connects to a remote server mig33 , i can get the hash string and generate the hash and login but i get an error "subscript out of range" it's just that when i receive more than 38 bytes i get this error. i have been stuck at it for quite a while , i hope you can help me out with this .the protocols are defined here
Code:
http://www.devinsmith.net/articles/mig33/mig33.html
Getting Error Subscript Out Of Range
Anyone
Sending you the following code
Code:
Private Sub Form_load
ReDim Names$(1 To 1, 1 To 1)
ReDim age$(1 To 1)
Open "C:iodat.dat" For Input As #1
'For i% = 1 To c% 'UBound(Names$)
Do Until EOF(1)
i% = i% + 1
If i% > UBound(Names$) Then ReDim Preserve Names$(1 To i%, 1 To 1) '----- Getting error Subscript out of Range
If i% > UBound(age$) Then ReDim Preserve age$(1 To i%)
Input #1, Names$(i%, 1), age$(i%)
Loop
Text2.Text = Text2.Text + Names$(i%, 1) + " " + age$(i%) + vbCrLf$
'Next i%
Close #1
End Sub
Thanks
Samyo
Subscript Out Of Range Error
When I try and run the piece of code below a subscript out of range error appears. Could somebody please provide me with a possible solution as to how I can resolve this error. (The VB debug highlights the line s= Split (q(1), ")")
PLEASE HELP ME RESOLVE THIS by viewing the attachment
Subscript Out Of Range Error
I'm still working on this and have overcome some of the stumbling blocks but now I have a new one. Below is the code I'm using. The function accepts a string which is a list of elements separated by commas and stores the elements in an array of structures. The error I get is <subscript out of range> on the first bolded line. What's wrong? I really need to get past this I've been working on it for far too long. Please help
Code:
Private Sub ParseRec(ByVal CSVText As String, ByRef TextArray() As FormElement)
Dim intIndex As Integer
Dim intChar As Integer
Dim strColumnText As String
intChar = InStr(CSVText, ",")
Do While CSVText <> ""
Debug.Print CSVText
strColumnText = Left(CSVText, intChar - 1)
TextArray(intIndex).FieldId = strColumnText
CSVText = Mid(CSVText, intChar)
strColumnText = Left(CSVText, intChar - 1)
TextArray(intIndex).Control = strColumnText
CSVText = Mid(CSVText, intChar)
strColumnText = Left(CSVText, intChar - 1)
TextArray(intIndex).MaxLength = strColumnText
strColumnText = ""
intIndex = intIndex + 1
Loop
End Sub
Subscript Out Of Range Error
In this code, if DomainQuery is empty I get this error:
Run-time error '9':
Subscript out of range
Code:
DomainQuery = Split(TempDomainQuery, " ")
If Len(DomainQuery(0)) < 3 Or Len(DomainQuery(0)) > 63 Then
MsgBox "Domain names must be between 3 and 63 characters long.", vbExclamation + vbOKOnly, "Domain Name Error"
Exit Sub
End If
Any ideas what might be wrong?
Simon
Subscript Out Of Range Error
I am trying to put he content of a folder into an array, ut keep getting the same error message.
Can anyone help
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Sub Command1_Click()
Dim n As Integer
Dim fileList()
For n = LBound(fileList()) To UBound(fileList())
Debug.Print Str(n) & "" & fileList(n)
Next n
strMyFile = fileList(n)
strMyFile = "C:New Folder"
If Dir(strMyFile) = "" Then
MsgBox "File " & strMyFile & " does not exist"
Else
PrintIt = ShellExecute(Me.hwnd, "PRINT", strMyFile, "", "", -1)
End If
End Sub
Subscript Out Of Range Error
Private Sub List1_Scroll()
Dim B
B = Split(List1.Text, Space(100))
txtTitle.Text = B(0)
txtUrl.Text = B(1)
B(0) = ""
B(1) = ""
End Sub
Whats wrong with this code?
'subscript Out Of Range' Error
please can anyone tell me what a 'subscript out of range' error means with respect to Arrays.
i have created the following program to store a 5 persons first and last names
{code within a command box}
dim asnames(1 to 5 , 1 to 2) as string ' general declaration
dim icount as integer ' general declaration
for icount = 1 to 5
' to store the names in textboxes
text1.text = asnames(icount, 1) ' first name
text2.text = asnames(icount, 1) 'second name
next icount
{ my VB is very basic (as you may have discovered), is the above program ok. Once i have inputted all five people, i then whant to type in a firstname in a textbox, and then be given the corresponding surname in the other tetxbox.}
the code i use to do this is placed within another command box
asnames(icount , 1) = text1.text
asnames(icount , 2) = text2.text
i keep on getting the message 'subscript out of range' when i click the command box. I know the last bit of code is wrong. what would the correct code be to view a surname when i type in a first name..
Error Help: Subscript Out Of Range
i get the error on th following line label '16 how i fix it then how do i take this code and make it read info from a listbox and add it to excel?? THANKS
Dim xlsWorkBook As Excel.Workbook
Dim xlsWorkSheet As Excel.Worksheet
Set xlsWorkBook = GetObject("D:MoviePlayList VB est.xls")
Set xlsWorkSheet = xlsWorkBook.Worksheets("C")
xlsworksheet.cells(1,2).value = "test"
Subscript Out Of Range (Error 9)
I am having this "Subscript out of range (Error 9)" error immediately after starting my application. This is followed by a
MY.EXE caused an invalid page fault in module MSVBVM60.DLL at 0177:660d44b0
So far so good... The problem is, that this error appears olny with some MSWindows configurations and NOT with others on which is working perfeclty!!! Does this make any sense?
I have searched (and found) all the relevant articles about error 9 in MSDN.... Nothing of these is the case here... double-checked that...(by the way, I am suspecting contol panel's regional settings but I am not sure...)
Any ideas would be most helpful..thanks
Nikos
ps. My app uses DAO 3.6 and have been compiled using VB6SP3.
Subscript Out Of Range Error
Hey guys,
I recently wrote a VB script on my own machine, which worked fine with all the test data I put through it. However, I've transferred it over to a server and for some reason, Im receiving a Runtime error 9: Subscript out of range error.
Ive managed to track it down to the following section of code:
Code:
' Remove crap from end of ref
quoteref = Split(aref, "#")
quoteref(0) = Replace(quoteref(0), " ", "")
quoterefDB = quoteref(0)
' Place DOB in correct format
birthsplit = Split(birthdate, "-")
dob = birthsplit(0) & "/" & birthsplit(1) & "/" & birthsplit(2)
Any ideas? If anyone could help me out on this I'd be most grateful.
Subscript Out Of Range Error(381)
When I try to run my program it gives me this error"Subscript out of range(381).Can someone explain to me what it means.I'm usingb VB6 and Access database
SubScript Out Of Range Error
Hi,
I have a form that needs to display the records from a MysQl DB. The data is a list if Accommodation. I can add the data Ok but when time comes to display it I receive a "Subscript Out Of Range" error. If I delete the information in the db and then display the form it opens without any problem, obviously with no data though.
When I click on DEBUG, I continuously get taken to the form below with the same line highlighted. I have checked that all the fields in the DB match what is on the list. Can anyone advise me please.
(I have commented out some of the lines but it does not matter even if they are not commented out, still get the same error)
Public Sub populateAccommodation()
Set DataGrid1.DataSource = rsAccommodation
DataGrid1.Columns(0).Caption = "ID"
DataGrid1.Columns(0).Visible = False
DataGrid1.Columns(0).Width = 0
DataGrid1.Columns(1).Caption = "Accommodation No"
DataGrid1.Columns(1).Width = 2000
DataGrid1.Columns(1).Visible = True
DataGrid1.Columns(2).Caption = "Accommodation Name"
DataGrid1.Columns(2).Width = 2500
'DataGrid1.Columns(3).Caption = "Unit No"
'DataGrid1.Columns(3).Width = 800
'DataGrid1.Columns(4).Caption = "Description"
'DataGrid1.Columns(4).Width = 1500
'DataGrid1.Columns(5).Caption = "Physical Address ID"
'DataGrid1.Columns(5).Width = 1100
'DataGrid1.Columns(5).Visible = False
'DataGrid1.Columns(6).Caption = "Update User"
'DataGrid1.Columns(6).Width = 1500
'DataGrid1.Columns(7).Caption = "UpDate Time"
'DataGrid1.Columns(7).Width = 1500
'DataGrid1.Columns(7).Visible = False
'DataGrid1.Columns(8).Caption = "DefRatePP"
'DataGrid1.Columns(8).Width = 0
'DataGrid1.Columns(8).Visible = False
'DataGrid1.Columns(9).Caption = "DefRatePC"
'DataGrid1.Columns(9).Width = 0
'DataGrid1.Columns(9).Visible = False
'DataGrid1.Columns(10).Caption = "DefRatePI"
'DataGrid1.Columns(10).Width = 0
'DataGrid1.Columns(10).Visible = False
'DataGrid1.Columns(11).Caption = "DefRatePR"
'DataGrid1.Columns(11).Width = 1500
'DataGrid1.Columns(12).Caption = "RoomTypeClass"
'DataGrid1.Columns(12).Width = 0
'DataGrid1.Columns(12).Visible = False
'DataGrid1.Columns(13).Caption = "aid"
'DataGrid1.Columns(13).Width = 0
'DataGrid1.Columns(13).Visible = False
'DataGrid1.Columns(13).Caption = "DateInsert"
'DataGrid1.Columns(13).Width = 2000
'DataGrid1.Columns(14).Caption = "ownerid"
'DataGrid1.Columns(14).Width = 2000
'DataGrid1.Columns(14).Visible = False
End Sub
Subscript Out Of Range Error....
Hi everyone,
this is kind of a weird problem i'm having with this subscript error...i'm working on a database management program which has a login form, and an MDI form with two MDI child forms that load up after logging in. i have an error handler in the login button. when the error handling is turned off, i get no errors...but when i turn it on, it catches Error 9: subscript out of range. i can't figure out what's causing it and why it only happens when the handling is turned on. here's the login code and the error handler. when i get the error, i've been using break to get into the call stack and the only things there are the errorhandler and cmdLogin. here's the code:
Code:
'CMDLOGIN CODE
On Error GoTo ErrorLine:
Label1.Visible = True
Dim Name As String
Dim deniedAccess As Integer
Label1.Visible = True
DoEvents
'check if a username/password has been entered
If txtUserName = "" Then
Exit Sub
ElseIf txtPassword = "" Then
Exit Sub
End If
OpenConnection connLogin
'only get to this point if both a username and
'password have been entered.
SQL = "SELECT * FROM `tblUsers` WHERE [UserName] = '" & txtUserName.Text & "'"
OpenRecordset rsLogin, connLogin, SQL
If txtPassword = rsLogin.Fields("Password") Then
LoginSucceeded = True
Else
LoginSucceeded = False
End If
If LoginSucceeded = True Then
'username + password is correct!
i = 0
Permission = rsLogin!Permissions
Name = rsLogin!UserName
Company = rsLogin!Company
User = txtUserName.Text
a = InStr(1, User, " ")
firstInitial = Left(User, 1)
lastInitial = Mid(User, a + 1, 1)
ManagerInitials = firstInitial & lastInitial
isQMS = True
MDIForm1.Show
Unload Me
Else
If i < 3 Then
MsgBox ("Invalid UserName or Password")
txtUserName.Text = ""
txtPassword.Text = ""
txtUserName.SetFocus
CloseRecordset rsLogin
CloseConnection connLogin
i = i + 1
Else
MsgBox ("Too many attempts, please request assistance.")
Unload Me
End If
End If
ErrorLine:
If Err.Number Then
errNumber = Err.Number
errDesc = Err.Description
FormName = Me.Caption
Call ErrorHandler(errNumber, errDesc, FormName)
End If
'ERROR HANDLER CODE
Public Function ErrorHandler(Number As Long, Description As String, Form As String)
Select Case errNumber:
Case 3021:
MsgBox ("I'm sorry, there are no available leads at this time.")
Case Else:
MsgBox ("ErrorNumber " & errNumber & vbCrLf & "Error Description: " & errDesc & vbCrLf & "Please click OK and complete the bug report form.")
frmBug.Show
End Select
End Function
ok, that's the only stuff in the call stack...is it possible that something else is being called but is getting caught before it gets to the call stack? that doesn't seem to make much sense to me though...and i can't figure out why it's only happening with the error handler..? any help would be great, thanks!
-Ryan
Edited by - mrsmiley0221 on 7/7/2004 7:12:12 AM
Subscript Out Of Range Error.
Hi, I would like to check if a statement is going to return a "Subscript out of range" error before it is executed.
I have tried:
Code:If Not IsError(Blah) Then
Do Blah
End If
But this just returns a subscript out of range error when determining iserror.
I hope you can see what i'm trying to achieve.
Edited by - Capuchin on 4/24/2007 7:31:47 AM
Error Is 'subscript Out Of Range'
Dim fld As FieldObject
com.CommandText = "rptInvPaid"
com.CommandType = adCmdStoredProc
With rs
.CursorType = adOpenStatic
.CursorLocation = adOpenKeyset
.Source = "SELECT * FROM tblemployee"
Set .ActiveConnection = con
.Open
End With
Report.Database.SetDataSource rs, 3, 1
Set fld = Report.Section10.AddFieldObject("{rs.fields(0).value}", 0, 0)
Set CRViewer1.ReportSource = Report
CRViewer1.ViewReport
my problem is at
Report.Database.SetDataSource rs, 3, 1
has error 'subscript out of range'
i dont know how to set rs recordset datasource to crviewer
software used crystalreport 8.5,vb 6, sqlserver in server,using stored procedure in sql server in server
help me
Error: Subscript Out Of Range
I'm just trying to read a text file into an array and when I run it I get this error message. Here is the code:
private Sub Command1_Click()
Dim a$(100), b$(100)
Dim i as Integer
Open "C:WINDOWSProfilesDerflaDesktop
ewfnames.txt" for input as #1
i = 0
Do While Not EOF(1)
input #1, a$(i), b$(i)
i = i + 1
Loop
MsgBox i & "entries loaded."
Close #1
End Sub
What am I doing wrong. Please help.
Run Time Error 9: Subscript Out Of Range
Hello..i'm going nuts. I've read thru most of the posts in this forum and tried lotsa ways but cant seem to get my code working.
What i'm trying to do is copy some info from one workbook to another workbook using VB6. I know its something really easy but I keep getting this error "Run time error 9: Subscript out of range"
Below is my code:
I tried a few variations..
Sub Combine()
Dim oExcel As Excel.Application
Set oExcel = New Excel.Application
oExcel.Visible = True ' <-- *** Optional ***
oExcel.ScreenUpdating = False
oExcel.Workbooks.Open FileName:="D:VB_ExcelBook1.xls"
oExcel.Workbooks("Book1").Sheets(1).Copy _
After:=oExcel.Workbooks("Book2").Sheets(1)
oExcel.Workbooks("Book1").Close
oExcel.ScreenUpdating = True
End Sub
I keep getting the error on the line below:
oExcel.Workbooks("Book1").Sheets(1).Copy _
After:=oExcel.Workbooks("Book2").Sheets(1)
oExcel.Workbooks("Book1").Close
I also tried:
oExcel.Workbooks("Book1.xls").Sheets("Sheet1").Range("A1:B4").Copy
oExcel.Workbooks("Book2.xls").Sheets("Sheet1").Paste _
Destination:=oExcel.Workbooks("Book2.xls").Sheets("Sheet1").Range("A1: B4")
Please help... thanks..
MSFlexGrid Subscript Out Of Range Error
I have inherited an old piece of software where i work. there is an error in one piece of it.
The msFlexGrid is populated fine the first time i click a button on the forum, but when i click the exact same button the second time around i get a subscript out of range error.
Here is the procedure that populates the flexGrid. it is in this where the error is thrown:
Private Sub SetSummaryHeaders()
With grdAnalysisSummary
.TextArray(faIndex(0, COL_RMSID, SUMMARY_COLUMN_COUNT)) = "Customer ID"
.TextArray(faIndex(0, COL_ISONHOLD, SUMMARY_COLUMN_COUNT)) = "Is On Hold"
.TextArray(faIndex(0, COL_REVCUSTID, SUMMARY_COLUMN_COUNT)) = "MS Sales ID"
.TextArray(faIndex(0, COL_SUBSIDIARY, SUMMARY_COLUMN_COUNT)) = "Subsidiary"
.TextArray(faIndex(0, COL_CUSTOMERNAME, SUMMARY_COLUMN_COUNT)) = "Name"
.TextArray(faIndex(0, COL_RMVAMOUNT, SUMMARY_COLUMN_COUNT)) = "MS Sales Amount"
.TextArray(faIndex(0, COL_RMSAMOUNT, SUMMARY_COLUMN_COUNT)) = "RMS Amount"
.TextArray(faIndex(0, COL_DIFFERENCE, SUMMARY_COLUMN_COUNT)) = "Difference"
.TextArray(faIndex(0, COL_PERCENT, SUMMARY_COLUMN_COUNT)) = "Percentage"
End With
End Sub
in case you need it, the faIndex function is this one below:
Private Function faIndex(iRow As Integer, iCol As Integer, Optional NumberColumns) As Long
Static iNumColumns As Integer
If Not IsMissing(NumberColumns) Then
iNumColumns = NumberColumns
End If
faIndex = iRow * iNumColumns + iCol
End Function
i think if i could make the flexgrid = nothing each time it would sort out the problem. have you any ideas?
Run Time Error 9 - Subscript Out Of Range
Not sure what I'm doing wrong here, I've Dim User() as String and tried various ways to populate the array but getting nowhere
in the following code;
For i = 0 To 9
index = Combo1(i).ListIndex
If index <= 1 Then
index = 0
End If
CTemp = Combo1(i).List(index)
User(i) = CTemp
Next i
Each combo1(i).List(index) as valid data but the line User(i)=CTemp returns me the above error, any idea's where I'm going wrong
Many thanks
Runtime Error 9, Subscript Out Of Range...HELP
Here's my code..
Code:
Private Sub START_Click()
StopAll = False
Dim theSTATE As String
Dim thePROVINCE As String
Dim theAGE As String
Dim sp As New Parser
Dim PageNumber As String
PageNumber = "1"
theSTATE = USACombo.List(USACombo.ListIndex)
thePROVINCE = CANADAcombo.List(CANADAcombo.ListIndex)
theAGE = "18"
If Not USACombo.Text = "(choose one)" Then
theURL.Text = "http://www.blackplanet.com/user_search/results.html?find_member_details_form_submit=1&layout=§ion=&sex_ids%5B%5D=1&sex_ids%5B%5D=2&min_age=" & theAGE & "&max_age=" & theAGE & "&usa_state_id=" & theSTATE & "&usa_city=&usa_selected_tab=us_city_state_tab&native_country_id=USA&p=" & PageNumber
Inet1.Cancel
Inet1.Execute theURL.Text
theOUTPUT.Text = GrabInetSource
PAGES.Text = sp.Parse(theOUTPUT.Text, " ...", "</a></a>", True, True, 0)
Dim FinalPageNumber
FinalPageNumber = Split(PAGES.Text, ">")
PAGES.Text = FinalPageNumber(1)
Do Until PageNumber = FinalPageNumber(1) Or StopAll = True
theURL.Text = "http://www.blackplanet.com/user_search/results.html?find_member_details_form_submit=1&layout=§ion=&sex_ids%5B%5D=1&sex_ids%5B%5D=2&min_age=" & theAGE & "&max_age=" & theAGE & "&usa_state_id=" & theSTATE & "&usa_city=&usa_selected_tab=us_city_state_tab&native_country_id=USA&p=" & PageNumber
theURL.SelStart = Len(theURL)
theURL.SelLength = 1
Inet1.Cancel
Inet1.Execute theURL.Text
theOUTPUT.Text = GrabInetSource
theOUTPUT.Text = sp.Parse(theOUTPUT.Text, "<p><b class=""username""><a href=""http://www.blackplanet.com/", "/?find_member_details_", True, True, "1")
theOUTPUT.Text = Replace(theOUTPUT.Text, "p><b class=""username""><a href=""http://www.blackplanet.com/", "")
IDlist.Text = IDlist.Text & theOUTPUT.Text
PageNumber = PageNumber + 1
DoEvents
Loop
If PageNumber = FinalPageNumber(1) Then
theAGE = theAGE + 1
If theAGE = "19" Then
theAGE = "18"
theSTATE = USACombo.List(USACombo.ListIndex + 1)
End If
PageNumber = "1"
theURL.Text = "http://www.blackplanet.com/user_search/results.html?find_member_details_form_submit=1&layout=§ion=&sex_ids%5B%5D=1&sex_ids%5B%5D=2&min_age=" & theAGE & "&max_age=" & theAGE & "&usa_state_id=" & theSTATE & "&usa_city=&usa_selected_tab=us_city_state_tab&native_country_id=USA&p=" & PageNumber
theURL.SelStart = Len(theURL)
theURL.SelLength = 1
Inet1.Cancel
Inet1.Execute theURL.Text
theOUTPUT.Text = GrabInetSource
PAGES.Text = sp.Parse(theOUTPUT.Text, " ...", "</a></a>", True, True, 0)
Dim theFinalPageNumber
theFinalPageNumber = Split(PAGES.Text, ">")
PAGES.Text = theFinalPageNumber(1)
Do Until PageNumber = theFinalPageNumber(1) Or StopAll = True
theURL.Text = "http://www.blackplanet.com/user_search/results.html?find_member_details_form_submit=1&layout=§ion=&sex_ids%5B%5D=1&sex_ids%5B%5D=2&min_age=" & theAGE & "&max_age=" & theAGE & "&usa_state_id=" & theSTATE & "&usa_city=&usa_selected_tab=us_city_state_tab&native_country_id=USA&p=" & PageNumber
theURL.SelStart = Len(theURL)
theURL.SelLength = 1
Inet1.Cancel
Inet1.Execute theURL.Text
theOUTPUT.Text = GrabInetSource
theOUTPUT.Text = sp.Parse(theOUTPUT.Text, "<p><b class=""username""><a href=""http://www.blackplanet.com/", "/?find_member_details_", True, True, "1")
theOUTPUT.Text = Replace(theOUTPUT.Text, "p><b class=""username""><a href=""http://www.blackplanet.com/", "")
IDlist.Text = IDlist.Text & theOUTPUT.Text
PageNumber = PageNumber + 1
DoEvents
Loop
End If
End If
End Sub
When I run this, I get a runtime error 9 (subscript out of range) at this part.
Code:
PAGES.Text = theFinalPageNumber(1)
HELP!
Subscript Out Of Range Run Time Error 9
Hi,
I am getting this error( Runtime Error 9 Subscript out of range) when i try to click on the button, I am using VB6.0 with SQL Server2000. I am giving the code over here, can any body help me to get out of this.. appreciate your help
Thanks
Public Sub cmdLvl2Click(ByVal aIndex As Integer, ByVal aiButton As Integer)
‘If the time Interval of the tmrCreateProcess
'timer is set that means the task is in the que and that the finction is
'called successively.
If frmmain.tmrCreateProcess.Interval Then Exit Sub
If aiButton = 2 And objNav.OperationMode = gctEditor Then
'condition added by RL for #10320
'If aIndex < objNav.TaskButtons.Count Then
objNav.CurrentButtonId = objNav.TaskButtons.Item(aIndex + 1).ButtonID
Set cobjFrmTaskOp = New cTaskOpDisplay
cobjFrmTaskOp.Parent = Parent
cobjFrmTaskOp.EditTaskop
If Not (cobjFrmTaskOp Is Nothing) Then
Set cobjFrmTaskOp = Nothing
End If
Call RefreshButtons
'End If
Else
If aiButton = 1 And objNav.OperationMode = gctNavigator And _
objNav.TaskButtons.Item(aIndex).TaskId <> 0 Then
'set the global g_objmaindisplay object,
'The object is used by the tmrCreateProcess control to execute the clicked
'task.
Set g_objmaindisplay = Me
g_index = aIndex
frmmain.tmrCreateProcess.Interval = 100
'ExecuteBtnTask (aIndex)
' the above code commented ,since the same is being
'done by the tmrCreateProcess control
End If
End If
Screen.MousePointer = vbNormal
End Sub
This is the code i am getting the error here:
If aiButton = 1 And objNav.OperationMode = gctNavigator And _
objNav.TaskButtons.Item(aIndex).TaskId
Runtime Error 9 Subscript Out Of Range
Hi,
I am getting this error when i try to click on the button, I am using VB6.0 with SQL Server2000. I am giving the code over here, can any body help me to get out of this.. appreciate your help
Thanks
Public Sub cmdLvl2Click(ByVal aIndex As Integer, ByVal aiButton As Integer)
‘If the time Interval of the tmrCreateProcess
'timer is set that means the task is in the que and that the finction is
'called successively.
If frmmain.tmrCreateProcess.Interval Then Exit Sub
If aiButton = 2 And objNav.OperationMode = gctEditor Then
'condition added by RL for #10320
'If aIndex < objNav.TaskButtons.Count Then
objNav.CurrentButtonId = objNav.TaskButtons.Item(aIndex + 1).ButtonID
Set cobjFrmTaskOp = New cTaskOpDisplay
cobjFrmTaskOp.Parent = Parent
cobjFrmTaskOp.EditTaskop
If Not (cobjFrmTaskOp Is Nothing) Then
Set cobjFrmTaskOp = Nothing
End If
Call RefreshButtons
'End If
Else
If aiButton = 1 And objNav.OperationMode = gctNavigator And _
objNav.TaskButtons.Item(aIndex + 1).TaskId <> 0 Then
'set the global g_objmaindisplay object,
'The object is used by the tmrCreateProcess control to execute the clicked
'task.
Set g_objmaindisplay = Me
g_index = aIndex
frmmain.tmrCreateProcess.Interval = 100
'ExecuteBtnTask (aIndex)
' the above code commented ,since the same is being
'done by the tmrCreateProcess control
End If
End If
Screen.MousePointer = vbNormal
End Sub
I am getting the error here:
If aiButton = 1 And objNav.OperationMode = gctNavigator And _
objNav.TaskButtons.Item(aIndex + 1).TaskId
Run Time Error '9' Subscript Out Of Range
Help :P Can anyone Explain me why does this happen and how can i correct this?
Module
Code:
Option Explicit
Public Type CodigoPostal
CPID As Integer
CodPos As Integer
Arr As Integer
Local As String
End Type
Public sConn As String
Form
Code:
Option Explicit
Private MyConn As ADODB.Connection
Dim RecIndex As Integer
Dim CodPos() As CodigoPostal
Private Sub cmdIntroduz_Click()
Dim rs As New ADODB.Recordset, sql As String
sql = "SELECT NomeEmpresa, RamoActividade, Morada, Localidade," _
& "CodPostal, Telefone, Email, Site, ResponsavelInf, ResponsavelFor, Ncomp, Nempregados " _
& "FROM T_Ident"
'On Error Resume Next
MyConn.Open
rs.Open sql, MyConn, adOpenKeyset, adLockOptimistic, adCmdText
rs.AddNew
rs!NomeEmpresa = txtNomeEmpresa.Text
rs!RamoActividade = txtRamoActividade.Text
rs!Morada = txtMorada.Text
rs!Localidade = txtLocalidade.Text
rs!CodPostal = txtCodPostal(0).Text
rs!Telefone = txtTelefone.Text
rs!Email = txtEmail.Text
rs!Site = txtSite.Text
rs!ResponsavelInf = txtResponsavelInf.Text
rs!ResponsavelFor = txtResponsavelFor.Text
rs!NComp = txtNcomp.Text
rs!NEmpregados = txtNempregados.Text
rs.Update
MyConn.Close
Set rs = Nothing
End Sub
Private Sub cmdLimpar_Click()
Limpa
End Sub
Private Sub cmdSair_Click()
Unload Me
End
End Sub
Private Sub Form_Load()
Dim CP As New ADODB.Recordset, sqlCP As String
On Error Resume Next
RecIndex = 0
cmbCP.Text = ""
cmbArr.Text = ""
sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "crm_verA.mdb" & ";Persist Security Info=False"
sqlCP = "SELECT ID, CodPostal, Arruamento, Localidade FROM T_CodPostal"
Set MyConn = New ADODB.Connection
MyConn.ConnectionString = sConn
MyConn.Open
CP.Open sqlCP, MyConn, adOpenKeyset, adLockOptimistic, adCmdText
With CP
.MoveLast
If .RecordCount > 0 Then
RecIndex = .RecordCount
ReDim CodPos(RecIndex)
.MoveFirst
RecIndex = 0
While Not .EOF
CodPos(RecIndex).CPID = !ID
CodPos(RecIndex).CodPos = !CodPostal
CodPos(RecIndex).Arr = !Arruamento
CodPos(RecIndex).Local = !Localidade
cmbCP.AddItem !CodPostal
cmbArr.AddItem !Arruamento
.MoveNext
RecIndex = RecIndex + 1
Wend
End If
End With
MyConn.Close
Set CP = Nothing
End Sub
Private Sub cmbCP_Change()
Dim ctr As String
ctr = "entra"
RecIndex = 0
Do
[color=Orange] If cmbCP.Text = CStr(CodPos(RecIndex).CodPos) Then[/color]
txtLocalidade.Text = CodPos(RecIndex).Local
ctr = "sai"
End If
RecIndex = RecIndex + 1
Loop While ctr = "entra"
End Sub
The Error happens in the orange section
Thanks
Edit by mkoslof: Added line break in order to make viewing the post easier. Thanks
Subscript Out Of Range, Runtime Error '9'
Ahh! My FTP client app seems to finish most all files just fine, and then for some reason it finishes the transfer after the download, and at 100 percent tells me subscript error, out of range and points to this line of code:
ReDim Data2((Size Mod BUFFERSIZE) - 1) As Byte
Could it have something to do with the size of the file? I really have no clue, I'm pretty sure I have tested it with larger >700MB files, this was only 60MB.. What's going on here? Its now doing this with a 46MB file and a 60MB file, there are no write problems in the folder..
Array Error Subscript Out Of Range!!
Public udtListeClient() As TypeInfoClient 'in the Module
ReDim udtListeClient(iNbClient + conJumpClient) As TypeInfoClient
conJumpClient = 100 it a constant
iNbClient = 0
iNbClientBefore=0
and after a while
iNbClient = 100 so i redim preserve and get the error??
If (iNbClient - iNbClientBefore) > 100 Then
ReDim Preserve udtListeClient(iNbClient + conJumpClient) 'Error appear here
iNbClientBefore = iNbClient
End If
Run-time error '9':
Subscript out of range
anyone know why i get that error?!?
SubScript Out Of Range Runtime Error 9
I get this a lot everytime i'm bitblitting tiles to my picturebox
and i was wondering if there is a cure for this.
It happens when i accidentally try to blit a tile beyond the borders
of a picturebox. I believe the real cause of this is because my map
array is set to a certain size and when i go beyond that, i get that
error.
Is there something i can do to keep the mouse inside the picturebox
when i'm blitting tiles?
Subscript Out Of Range Error With This Function.. Any Help?
Im getting a subscript out of range error with my function. I probably don't have the redim function correct but i'm not sure. Any help?
Code:
Public Function GetFilesInDir(strPath As String, Optional strExt As String = "*.*") As String()
Dim i As Integer
Dim strFile As String
Dim fileList() As String
strFile = Dir$(strPath & strExt)
Do While strFile <> ""
fileList(i) = strFile
strFile = Dir$
i = i + 1
ReDim Preserve fileList(i)
Loop
ReDim Preserve fileList(i - 1)
GetFilesInDir = fileList
End Function
Run Time Error '9' SubScript Out Of Range
I am working with VB6. I am tring to increment a listbox record 1,2,3 ect. this is for a application that I tring to create. When it gets to the #7 record it gives the error message (Run Time Error '9' SubScript out of range)
Here is the code:
End If
Code:
TxtLastName_AfterUpdate.Value = ""
TxtSchoolName_Afte Wrestlers(wrestlerno, 1) = firstname
Wrestlers(wrestlerno, 2) = lastname
Wrestlers(wrestlerno, 2) = schoolname
Wrestlers(wrestlerno, 2) = wrestlerclass
If wrestlerno = 600 Then
Exit Sub
End If
txtWrestlerNo_AfterUpdate.Value = wrestlerno + 1
If wrestlerno(txtWrestlerNo_AfterUpdate.Value, 1) <> "" Then
Exit Sub
End If
TxtFirstName_AfterUpdate.Value = ""
rUpdate.Value = ""
TxtWrestlerClass_AfterUpdate.Value = ""
Exit Sub
Subscript Out Of Range Error? - Help Needed
Hi,
I am trying to calculate the total from an array using the following code;
Private Sub cmdtotal_Click()
Dim i As Integer
Total = 0
For i = 0 To UBound(customer)
Total = Total + customer(i).customeramount
Next i
Totallbl.Caption = Total
End Sub
It erros on - "Total = Total + customer(i).customeramount"
There is also a module which holds records for each array item, for customer name and customer amount.
Please help!
Mark.
Run-time Error '9' - Subscript Out Of Range
Hi, I get an error that says:
Run-time error '9'
Subscript out of range
The error hapends within a "for" loop. And the loop values are used.
Like:
***
For i = 1 to 100
For j = 1 to 100
if j = i + 2 then
end if
next
next
***
But that is not the actual code.
So why do this error happen?
How can I correct it?
How can I prevent if from happening again?
If you need more information about the error then just let me know.
thanks in advance
Julian
Run-time Error 9, Subscript Out Of Range
This is driving me crazy!
It seems like many of you have run into dll trouble before judging by the number of posts on the topic. So why should I be any different?
After using the P&W wizard and installing my application on a test win98 system, I received and error. Scanning the posts I realized I needed MDAC 2.5. So I installed that on my test pc and reinstalled the app. Now I'm receiving a run-time error 3706 when the app goes to access my Access 97 database. Again, looking through the forum I find where I may need to use Microsoft.Jet.OLEDB.4.0 instead of 3.5.1. Well, when I change my connections string(s) to 4.0 I now get the above mentioned Subscript out of range error. This is driving me mad, mad I tell you! Offending code below:
Code:
myConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\Server6holdDYNATEX97_DYN_CPS.mdb"
myConn.Open
'Open the Recordset and load the DataGrid1
rsTemp.Open "SELECT * FROM tblTemp", myConn, adOpenKeyset, adLockOptimistic
Set DataGrid1.DataSource = rsTemp
'Format the columns of the datagrid to make them look pretty.
DataGrid1.Columns(0).Width = 1000
DataGrid1.Columns(0).Visible = False
DataGrid1.Columns(1).Width = 1100
DataGrid1.Columns(1).Locked = True
DataGrid1.Columns(2).Width = 3500 'THIS IS THE LINE WITH THE ERROR
DataGrid1.Columns(2).Locked = True
DataGrid1.Columns(3).Width = 1000
DataGrid1.Columns(3).Locked = True
DataGrid1.Columns(3).NumberFormat = "$0.00"
DataGrid1.Columns(4).Width = 1000
DataGrid1.Columns(4).NumberFormat = "$0.00"
Your advice is much appreciated. Thanks!
braney
Parameter Error (subscript Out Of Range)
hi ,
i am making a report using crystal report 9 in visual basic 6
i have to pass parameter to the report for it
i have a made a parameter field in report named "par1"
its data type is NUMBER(its the only parameter in the report).
when i am passing parameter value from the form its giving me SUBSCRIPT OUT OF RANGE error 9.
my code of passing the parameter is:
CrystalReport1.ParameterFields(0) = "par1;" & i & ";True"
" i " is numeric variable taking input from the textbox through this code:
i= Val(Right(Text1.Text, (Len(Text1.Text) - 1)))
i couldnt figure out whats wrong with the code .
i also want to select only records which lie in between two dates , date1 and date2.I want to take these two dates input from Textbox ...please also tell me how to do it .
thanks in advance
Intermittent Error - Subscript Out Of Range
I realize this almost surely is related to array manipulation, but could it also be related to string processing ? I've had a lot of problems with the USB communication with the 50KiloVolt power supply, and I do have to process strings rec'd from it almost every 50 seconds or so...If I'm going to look anywhere, that is the logical place to start, but I don't know if string manipulation can cause this Subscript out of range error.
Also, there aren't too many arrays in this program, but the program is large, and it runs a piece of equipment 24/7, but the error seems very intermittent, like it occurs once every few days or so, and could be any time of day. The program does not contain any dynamic arrays.
I'm having a hard time zeroing in on exactly what the program is doing when the error occurs, although I do have an error/progress logging program running. When the error occurs, the last log entry seems correct, and then everything comes to a screeching halt.
It seems like I need to insert some On Error Goto type routine, and then gracefully handle the error from there, but I don't know where to insert this statement. Does it absolutely HAVE to be on the very next line of code after the error occurs ? That would be hard to do...I have no idea out of 50 functions or so where the error is coming from.
Very Strange 'Subscript Out Of Range Error 9' In VB 6--Thanks!
Hello,
This is a subroutine that will load and read a sequential file into
two arrays. The first is called .Tags() and the second .Values. Tags
is a 1D array while Values is a 2D array; both of the user type
'Present_Sch()'. Present_Sch() has already been redimensioned at this
point to include more than the variable 'Mod_ID'.
The strange thing is, I get the 'Subscript out of range error 9' when I try to
redimension preserve .Values() but not .Tags(). If I don't use
preserve, everything runs, but I don't get the data of course. Why
would preserve for .Tags() but not .Values()? When this subroutine
runs, it is the first time these arrays are being initialized and
filled.
I have done F8 debugging to make sure everything seems right. I have also tried using the full path to the arrays (i.e. Present_Sch.Values(....), etc.) as this is sometimes finicky, but I get the same error. What's going on?
Thanks in advance for any help you can give!
-Dan
Here's the code....
Code:
Public Type SCHEDULE_TYPE
Randomized As Boolean
nRepititions As Integer
Module_Association As Integer
FilePath As String
Is_Loaded As Boolean
Tags() As String
Values() As Single
End Type
Public Present_Sch() As SCHEDULE_TYPE
Private Sub Load_Schedule(ByVal Mod_ID As Integer)
Dim i%, j%
Dim FID%
Screen.MousePointer = 11
ReDim Present_Sch(Mod_ID).Tags(1 To 100) As String 'MAKE THE
ARRAYS BIG ENOUGH
ReDim Present_Sch(Mod_ID).Values(1 To 100, 1 To 1000) As Single
With Present_Sch(Mod_ID)
FID = FreeFile
Open .FilePath For Input As #FID
Lock #FID
Do
i = i + 1
Input #FID, .Tags(i)
Loop Until IsNumeric(.Tags(i))
.Values(1, 1) = CSng(.Tags(i))
ReDim Preserve .Tags(1 To i - 1) As String '<<NO ERROR HERE
i = 1 'OFFSET FOR FIRST NUMERIC VALUE
j = 0
Do
j = j + 1
Do
i = i + 1
Input #FID, .Values(i, j)
Loop Until i = UBound(.Tags)
i = i + 1
.Values(i, j) = .nRepititions
i = 0
Loop Until EOF(FID)
ReDim Preserve .Values(1 To UBound(.Tags) + 1, 1 To j) As Single '<< ERROR HERE
.Is_Loaded = True
Unlock #FID
Close #FID
End With
Screen.MousePointer = 0
End Sub
Runtime Error 9 Subscript Out Of Range HELP
Hey there, creating a hangman project in VB6 where upon running i get runtime error 9: subscript out of range.
I've never encountered this before and the other post (the runescape guy) didn't really help much. What is going wrong?
Code:
Option Explicit
Const stralpha As String = "abcdefghijklmnopqrstuvwxyz" 'alphabet
Const connumw As Integer = 8 '# of words
Const conhung As Integer = 8 'see above
Const conleftc As Integer = 270 'spacing
Dim strwordbank() As String 'word bank
Dim intChoice As Integer 'reference to current hidden word
Dim intlength As Integer 'length of hidden word
Dim intnumpicked As Integer 'correct guesses
Dim blngameover As Boolean ' is game still active
Dim intnextstep As Integer 'reference to next step of hanging
Private Sub cmdexit_Click()
End 'exit program
End Sub
Private Sub cmdnew_Click()
Dim i As Integer
NewGame
Chooseword 'select a word from array
End Sub
Private Sub Form_Click()
' clicked on form
If blngameover = True Then
MsgBox "Game Over!"
Else
MsgBox "You've clicked a blank space, try again!" 'tell to hit a letter
End If
End Sub
Private Sub Form_Load()
Dim i As Integer
blngameover = False
NewGame
Chooseword
For i = 1 To 25 'load aplhabet array
Load lblalphabet(i) 'load array
lblalphabet(i).Left = lblalphabet(i).Left + i * conleftc 'move next array element to the right of last one
lblalphabet(i).Caption = Mid(stralpha, i + 1, 1) 'pick next letter in alphabet
lblalphabet(i).Visible = True 'show element
Next i 'loop until all 26 letters are visible
ReDim strwordbank(connumw) ' loading words into array
strwordbank(0) = "osphrey"
strwordbank(1) = "eagle"
strwordbank(2) = "hawk"
strwordbank(3) = "pigeon"
strwordbank(4) = "cormrant"
strwordbank(5) = "emu"
strwordbank(6) = "crane"
End Sub
Private Sub NewGame()
Dim i As Integer
blngameover = False
intnextstep = 0
intnumpicked = 0
lblmessage.Caption = "Click a letter to guess" 'instructions
For i = 1 To 25 'load aplhabet array
Load lblalphabet(i) 'load array
lblalphabet(i).Left = lblalphabet(i).Left + i * conleftc 'move next array element to the right of last one
lblalphabet(i).Caption = Mid(stralpha, i + 1, 1) 'pick next letter in alphabet
lblalphabet(i).Visible = True 'show element
Next i
End Sub
Private Sub Chooseword()
Dim strcap As String
Dim i As Integer
Randomize
intChoice = Int(connumw * Rnd)
intlength = Len(strwordbank(intChoice))
strcap = ""
For i = 1 To intlength
strcap = strcap & "-"
Next i
lblhiddenplace.Caption = strcap
End Sub
Private Sub lblalphabet_Click(Index As Integer)
Dim strletter As String 'letter player clicked
Dim blnnomatch As Boolean 'to check if a match was made
Dim i As Integer 'control for for...next loop
strletter = lblalphabet(Index).Caption 'strletter is now the letter that the player guessed
If blngameover = True Then
MsgBox "Game Over!"
Else
lblalphabet(Index).Visible = False 'check letters in chosen word against guess
For i = 1 To intlength
strletter = Mid(strwordbank(intChoice), i, 1)
If strletter = lblalphabet(Index).Caption Then
lblhiddenplace.Caption = Left(lblhiddenplace.Caption, i - 1) & strletter & Right(lblhiddenplace.Caption, intlength - i) 'correct guess, and showing it
blnnomatch = False
intnumpicked = intnumpicked + 1
Else
blnnomatch = True
End If
Next i
If intnumpicked = intlength Then
lblmessage.Caption = "You Win!"
blngameover = True
If blnnomatch = True Then 'wrong guess
imgscene.Picture = pichang(intnextstep).Picture
intnextstep = intnextstep + 1
End If
If intnextstep = conhung Then
lblmessage.Caption = "You lose! :("
blngameover = True
lblhiddenplace.Caption = strwordbank(intChoice)
End If
End If
End If
End Sub
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.
Runtime Error '9': Subscript Out Of Range
Hi i have made a little application for a game i play which tells me how many players there are in each server.
the game has 120 worlds. but 121 buttons . world 116 isnt used at all.
My problem is i run my program with world 116 in it, i get this error Runtime error '9': subscript out of range.an it points this part of the code which is in red font colour .
VB Code:
Private Function worldplayerslist()Dim worlds(121) As String, temp() As String, temp2 As String, temp3 As String, temp4 As StringOn Error GoTo skip2Text2.Text = Inet1.OpenURL("http://runescape.com/serverlist.ws?plugin=0&lores.x=163&lores.y=74")DoEventsFor num = 1 To 121 On Error GoTo offline [color=Red]temp2 = Left(Split(Text2.Text, "World " & num & "<")(1), 30)[/color] temp3 = InStr(1, temp2, "Players") temp4 = InStr(1, temp2, "empty") If (temp4 > 0) Then temp2 = "OFFLINE" Else If (temp3 > 0) Then temp2 = Split(Split(temp2, " Players")(0), "<td>")(1) Else temp2 = "Full" End If End If Text1(num - 1).Text = temp2 GoTo skipoffline: Text1(num - 1).Text = "Offline"skip:Next numskip2:End Function Private Sub Form_Load()frmWait.ShowMe.ShowfrmWait.ZOrder 0Me.ZOrder 1Timer1.Enabled = FalseCall worldplayerslistUnload frmWaitFor g = 0 To 105 Text1(g).Locked = TrueNext gmnuStart.Enabled = TruemnuStop.Enabled = FalseEnd Sub Private Sub mnuExit_Click()If Timer1.Enabled = True Then MsgBox "You must first disable the automatic refresh.", vbCritical, "Hold It Right There!"Else Unload MeEnd IfEnd Sub Private Sub mnuRefresh_Click()Timer1.Enabled = FalsemnuStart.Enabled = TruemnuStop.Enabled = FalsefrmWait.ShowMe.ShowfrmWait.ZOrder 0Me.ZOrder 1Timer1.Enabled = FalseCall worldplayerslistUnload frmWaitEnd Sub Private Sub mnuSet_Click()If Timer1.Enabled = True Then MsgBox "You must first disable the automatic refresh.", vbCritical, "Hold It Right There!" GoTo skip2End IffrmSet.Showskip2:End Sub Private Sub mnuStop_Click()Timer1.Enabled = FalsemnuStart.Enabled = TruemnuStop.Enabled = FalseEnd Sub Private Sub mnuStart_Click()Timer1.Enabled = TruemnuStart.Enabled = FalsemnuStop.Enabled = TrueEnd Sub Private Sub Timer1_Timer()Call worldplayerslistEnd Sub
Please could some one explain what i have done wrong?
Many thanks
Sheepy
Runtime Error '381' Subscript Out Of Range
i always have this error when im adding something to my flexgrid...
VB Code:
Private Sub cmdPromoAdd_Click()With grdPromo .TextMatrix(iRowCtr, 1) = txtPromoID.Text .TextMatrix(iRowCtr, 2) = txtPromoName.Text .AddItem "" iRowCtr = iRowCtr + 1End WithEnd Sub Private Sub cmdProdAdd_Click()With grdProd .TextMatrix(iRowCtr, 1) = txtProductID.Text .TextMatrix(iRowCtr, 2) = txtProdName.Text .AddItem "" iRowCtr = iRowCtr + 1End WithEnd Sub
always highlights on my textmatrix's what could be the problem?
|