This is driving me crazy, I am by no means a pro at this, but I am trying to figure out why this error is popping up, please help, I feel like it is simple..
I am going to post the code and bold and underline the line that is throwing the error - sub addVariations(pOptionGroupDescrip, pOptionDescrip, pPriceToAdd, pPercentageToAdd, pIdProduct)
-
-
dim rstemp, pIndex
-
-
if pOptionGroupDescrip<>"" then
-
-
arrayOptions =split(pOptionDescrip,",")
-
arrayPrices =split(pPriceToAdd,",")
-
arrayPercentage =split(pPercentageToAdd,",")
-
-
' verification
-
if arrayOptions(0)="" then
-
response.redirect "comersus_backoffice_message.asp?message="& Server.Urlencode("If you need variations please fill every variation in order")
-
end if
-
-
' add option group
-
mySQL="INSERT INTO optionsGroups (optionGroupDesc, type) VALUES ('" &pOptionGroupDescrip & "','D')"
-
call updateDatabase(mySQL, rstemp, "itemFunctions.asp")
-
-
' retrieve optionGroupId
-
-
mySQL="SELECT MAX(idOptionGroup) AS maxIdOptionGroup FROM optionsGroups WHERE optionGroupDesc='" & pOptionGroupDescrip& "'"
-
call getFromDatabase(mySQL, rstemp, "itemFunctions.asp")
-
-
if rstemp.eof then
-
response.redirect "comersus_backoffice_message.asp?message="& Server.Urlencode("Cannot get option group ID")
-
end if
-
-
pIdOptionGroup=rstemp("maxIdOptionGroup")
-
-
' add options
- for f=0 to 3
-
-
if arrayOptions(f)<>"" and (arrayPrices(f) <> "" or arrayPercentage(f) <> "") then
-
mySQL="INSERT INTO options (optionDescrip, priceToAdd, percentageToAdd) VALUES ('" & arrayOptions(f) & "'," & arrayPrices(f)& "," & arrayPercentage(f) & ")"
-
-
call updateDatabase(mySQL, rstemp, "itemFunctions.asp")
-
-
' get idOption
-
-
mySQL="SELECT MAX(idOption) AS maxIdOption FROM options WHERE optionDescrip='" & arrayOptions(f) & "'"
-
-
call getFromDatabase(mySQL, rstemp, "itemFunctions.asp")
-
-
if rstemp.eof then
-
response.redirect "comersus_backoffice_message.asp?message="& Server.Urlencode("Cannot get option ID")
-
end if
-
-
pIdOption=rstemp("maxIdOption")
-
-
' assign to group
-
mySQL="INSERT INTO options_optionsGroups (idOption, idOptionGroup) VALUES (" & pIdOption & "," & pIdOptionGroup & ")"
-
-
call updateDatabase(mySQL, rstemp, "itemFunctions.asp")
-
-
end if
-
-
next
-
-
' assign group to product
-
mySQL="INSERT INTO optionsGroups_products (idOptionGroup, idProduct) VALUES (" & pIdOptionGroup & "," & pIdProduct & ")"
-
-
call updateDatabase(mySQL, rstemp, "itemFunctions.asp")
-
-
end if ' filled
-
-
end sub
-
-
-
sub loadProductVariations(pIdProduct, arrayOptions1, arrayOptions2, pHiddenIdOptions, pOptionDescrip1, pOptionDescrip2, pIdOptionGroup1, pIdOptionGroup2)
-
-
dim rstemp
-
-
' retrieve option groups
-
-
mySQL="SELECT optionsGroups.idOptionGroup, optionGroupDesc FROM optionsGroups_products, optionsGroups WHERE optionsGroups.idOptionGroup=optionsGroups_products.idOptionGroup AND idProduct=" &pIdProduct
-
call getFromDatabase(mySQL, rstemp, "getOptions")
-
-
pIdOptionGroup1=0
-
pIdOptionGroup2=0
-
-
do while not rstemp.eof
-
-
if pIdOptionGroup1=0 then
-
pOptionDescrip1=rstemp("optionGroupDesc")
-
pIdOptionGroup1=rstemp("idOptionGroup")
-
else
-
pOptionDescrip2=rstemp("optionGroupDesc")
-
pIdOptionGroup2=rstemp("idOptionGroup")
-
end if
-
-
rstemp.movenext
-
loop
-
-
' fill option arrays with default values
-
for f=0 to 3
-
arrayOptions1(0,f)=""
-
arrayOptions1(1,f)=0
-
arrayOptions1(2,f)=0
-
arrayOptions1(3,f)=0
-
arrayOptions2(0,f)=""
-
arrayOptions2(1,f)=0
-
arrayOptions2(2,f)=0
-
next
-
-
-
' retrieve options
-
pHiddenIdOptions=""
-
-
if pIdOptionGroup1<>0 then
-
-
mySQL="SELECT optionDescrip, priceToAdd, percentageToAdd, options.idOption FROM options, options_optionsGroups WHERE idOptionGroup=" & pIdOptionGroup1 & " AND options.idOption=options_optionsGroups.idOption"
-
call getFromDatabase(mySQL, rstemp, "getOptions")
-
f=0
-
-
do while not rstemp.eof
-
arrayOptions1(0,f) = trim(rstemp("optionDescrip"))
-
arrayOptions1(1,f) = rstemp("priceToAdd")
-
arrayOptions1(2,f) = rstemp("percentageToAdd")
-
pHiddenIdOptions = pHiddenIdOptions & rstemp("idOption") &","
-
f=f+2
-
rstemp.movenext
-
loop
-
-
end if
-
-
if pIdOptionGroup2<>0 then
-
-
mySQL="SELECT optionDescrip, priceToAdd, percentageToAdd, options.idOption FROM options, options_optionsGroups WHERE idOptionGroup=" & pIdOptionGroup2 & " AND options.idOption=options_optionsGroups.idOption"
-
call getFromDatabase(mySQL, rstemp, "getOptions")
-
-
f=0
-
do while not rstemp.eof
-
arrayOptions2(0,f) = trim(rstemp("optionDescrip"))
-
arrayOptions2(1,f) = rstemp("priceToAdd")
-
arrayOptions2(2,f) = rstemp("percentageToAdd")
-
pHiddenIdOptions = pHiddenIdOptions & rstemp("idOption") &","
-
f=f+2
-
rstemp.movenext
-
loop
-
-
end if
-
-
end sub
2 1956
Hi. Sorry, but 144 lines of code is too much to try to review for potential errors without being able to use the full debugging environment that VBA provides.
The error message is telling you that you are trying to access an array element with an index value that lies outside of the declared range for that array. I would doubt that the error is arising on your highlighted line, the innocuous for loop at line 32, even though you appear to be using an undeclared variable f as the loop index. An error could occur here if at some stage you have changed the value of for counter f from within the loop to a value lying outside of its preset range of 0-3, but this does not jump out from looking at the code.
It also does not help us that the code you post has no declarations for your arrays either.
I would suggest that you are going to have to be systematic about debugging. Set a breakpoint at the start of your routine and step through the code line by line, using the local variable watch facilities of VBA to check the values of all variables as you go. You should check particularly that the value of your array index variable f stays within the declared index range for the arrays concerned.
You may wish to read the series of short articles by our expert site admin NeoPa on Debugging in VBA for further guidance.
-Stewart
ps at lines 58 and 104 you list 'next' instead of 'next f' - better to be explicit and specify what the loop variable being incremented actually is, so use next f there instead.
Further to the previous post, it appears that you are either using undeclared variables routinely or you have globals defined elsewhere. You can use the compiler to prevent errors such as the use of undeclared variables by setting
OPTION EXPLICIT
at the top of your code.
Look particularly at where (or if) you are defining loop variable f. It appears in your sub called from your main procedure, and in your main procedure. If it is global in scope you really will have a problem, as its value in the calling routine will be overwritten by the sub when you call it.
-Stewart
Sign in to post your reply or Sign up for a free account.
Similar topics
by: andy.rich |
last post by:
I am getting the following error and I do not know why. Can anyone
help?
--------------------------------------------------------
this is what appears on the screen...
|
by: Richard Delorme |
last post by:
The n869 draft says:
J.2 Undefined behavior
The behavior is undefined in the following
circumstances:
-- An array subscript is out of range, even if an object
is ...
|
by: VB Programmer |
last post by:
I'm acutally using VB6, not VB.NET, but I couldn't find the newsgroup for
version 6....
I need help for something that should be simple. I keep getting a
"subscript out of range" error and...
|
by: Pedro Graca |
last post by:
I run into a strange warning (for me) today (I was trying to improve
the score of the UVA #10018 Programming Challenge).
$ gcc -W -Wall -std=c89 -pedantic -O2 10018-clc.c -o 10018-clc...
|
by: wennerd |
last post by:
I am getting a Subscript out of range after executing the following command
Set oRstPick = connTemp.Execute(sSQL)
It is a simple query:
sSQL = "SELECT idCategory, categoryDesc, idParentCategory...
|
by: josh |
last post by:
Hi I've a dubt!
when we have overloaded functions the compiler chooses the right
being based on the argument lists...but when we have two subscript
overloaded functions it resolves them being...
|
by: Andy |
last post by:
Hi all,
I started developing a little app on my Mac using XCode some month
ago. The app is running fine on my mac like a sharm. Now I am nearly
ready and yesterday I moved the whole source code...
|
by: subramanian100in |
last post by:
For vector and deque, the 'at( )' member function throws out_of_range
exception if the argument to the 'at( )' function is not in range. But
the subscript operator does not throw this exception...
|
by: Han |
last post by:
when I exe my project in vs.net2005,I got the error following:
Debug Assertion Failed!
Program:........
File:c:\program files\microsoft visual studio 8\vc\include\vector
Line:756
...
|
by: brandon01 |
last post by:
Keep getting "subscript out of range" any idea why? This function is looped btw.. Thx...
Private Sub getBday()
bDay = List1.List(nextBday)
bDayArr = Split(bDay, " - ")
Text1.Text =...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |