473,397 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Subscript out of range: 'f'

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

Expand|Select|Wrap|Line Numbers
  1. sub addVariations(pOptionGroupDescrip, pOptionDescrip, pPriceToAdd, pPercentageToAdd, pIdProduct)
  2.  
  3.  dim rstemp, pIndex  
  4.  
  5.  if pOptionGroupDescrip<>"" then
  6.  
  7.   arrayOptions      =split(pOptionDescrip,",")
  8.   arrayPrices       =split(pPriceToAdd,",")         
  9.   arrayPercentage       =split(pPercentageToAdd,",")         
  10.  
  11.   ' verification
  12.   if arrayOptions(0)="" then
  13.     response.redirect "comersus_backoffice_message.asp?message="& Server.Urlencode("If you need variations please fill every variation in order")
  14.   end if
  15.  
  16.    '  add option group 
  17.    mySQL="INSERT INTO optionsGroups (optionGroupDesc, type) VALUES ('" &pOptionGroupDescrip & "','D')"
  18.    call  updateDatabase(mySQL, rstemp, "itemFunctions.asp")  
  19.  
  20.    ' retrieve optionGroupId
  21.  
  22.    mySQL="SELECT MAX(idOptionGroup) AS maxIdOptionGroup FROM optionsGroups WHERE optionGroupDesc='" & pOptionGroupDescrip& "'"
  23.    call  getFromDatabase(mySQL, rstemp, "itemFunctions.asp") 
  24.  
  25.    if rstemp.eof then        
  26.      response.redirect "comersus_backoffice_message.asp?message="& Server.Urlencode("Cannot get option group ID")
  27.    end if  
  28.  
  29.    pIdOptionGroup=rstemp("maxIdOptionGroup")       
  30.  
  31.    ' add options
  32. for f=0 to 3
  33.  
  34.    if arrayOptions(f)<>"" and (arrayPrices(f) <> "" or arrayPercentage(f) <> "") then
  35.        mySQL="INSERT INTO options (optionDescrip, priceToAdd, percentageToAdd) VALUES ('" & arrayOptions(f) & "'," & arrayPrices(f)& "," & arrayPercentage(f) & ")"     
  36.  
  37.         call  updateDatabase(mySQL, rstemp, "itemFunctions.asp")  
  38.  
  39.         ' get idOption
  40.  
  41.         mySQL="SELECT MAX(idOption) AS maxIdOption FROM options WHERE optionDescrip='" & arrayOptions(f) & "'"
  42.  
  43.         call  getFromDatabase(mySQL, rstemp, "itemFunctions.asp") 
  44.  
  45.         if rstemp.eof then        
  46.              response.redirect "comersus_backoffice_message.asp?message="& Server.Urlencode("Cannot get option ID")
  47.         end if     
  48.  
  49.         pIdOption=rstemp("maxIdOption")   
  50.  
  51.         ' assign to group
  52.         mySQL="INSERT INTO options_optionsGroups (idOption, idOptionGroup) VALUES (" & pIdOption & "," & pIdOptionGroup & ")"
  53.  
  54.         call  updateDatabase(mySQL, rstemp, "itemFunctions.asp")  
  55.  
  56.    end if
  57.  
  58.    next
  59.  
  60.    ' assign group to product
  61.     mySQL="INSERT INTO optionsGroups_products (idOptionGroup, idProduct) VALUES (" & pIdOptionGroup & "," & pIdProduct & ")"
  62.  
  63.     call  updateDatabase(mySQL, rstemp, "itemFunctions.asp")  
  64.  
  65.   end if ' filled
  66.  
  67. end sub
  68.  
  69.  
  70. sub loadProductVariations(pIdProduct, arrayOptions1, arrayOptions2, pHiddenIdOptions, pOptionDescrip1, pOptionDescrip2, pIdOptionGroup1, pIdOptionGroup2)
  71.  
  72.   dim rstemp
  73.  
  74.   ' retrieve option groups
  75.  
  76.   mySQL="SELECT optionsGroups.idOptionGroup, optionGroupDesc FROM optionsGroups_products, optionsGroups WHERE optionsGroups.idOptionGroup=optionsGroups_products.idOptionGroup AND idProduct=" &pIdProduct
  77.   call getFromDatabase(mySQL, rstemp, "getOptions") 
  78.  
  79.   pIdOptionGroup1=0
  80.   pIdOptionGroup2=0  
  81.  
  82.   do while not rstemp.eof 
  83.  
  84.     if pIdOptionGroup1=0 then
  85.       pOptionDescrip1=rstemp("optionGroupDesc")
  86.       pIdOptionGroup1=rstemp("idOptionGroup")
  87.     else
  88.       pOptionDescrip2=rstemp("optionGroupDesc")
  89.       pIdOptionGroup2=rstemp("idOptionGroup")
  90.     end if
  91.  
  92.   rstemp.movenext
  93.   loop  
  94.  
  95.   ' fill option arrays with default values
  96.   for f=0 to 3
  97.    arrayOptions1(0,f)=""
  98.    arrayOptions1(1,f)=0
  99.    arrayOptions1(2,f)=0
  100.    arrayOptions1(3,f)=0
  101.    arrayOptions2(0,f)=""
  102.    arrayOptions2(1,f)=0   
  103.    arrayOptions2(2,f)=0
  104.   next
  105.  
  106.  
  107.   ' retrieve options
  108.   pHiddenIdOptions=""
  109.  
  110.   if pIdOptionGroup1<>0 then
  111.  
  112.    mySQL="SELECT optionDescrip, priceToAdd, percentageToAdd, options.idOption FROM options, options_optionsGroups WHERE idOptionGroup=" & pIdOptionGroup1 & " AND options.idOption=options_optionsGroups.idOption"
  113.    call getFromDatabase(mySQL, rstemp, "getOptions") 
  114.    f=0
  115.  
  116.    do while not rstemp.eof
  117.      arrayOptions1(0,f)    = trim(rstemp("optionDescrip"))
  118.      arrayOptions1(1,f)    = rstemp("priceToAdd")
  119.      arrayOptions1(2,f)    = rstemp("percentageToAdd")
  120.      pHiddenIdOptions    = pHiddenIdOptions & rstemp("idOption") &"," 
  121.     f=f+2
  122.    rstemp.movenext
  123.    loop   
  124.  
  125.   end if
  126.  
  127.   if pIdOptionGroup2<>0 then
  128.  
  129.    mySQL="SELECT optionDescrip, priceToAdd, percentageToAdd, options.idOption FROM options, options_optionsGroups WHERE idOptionGroup=" & pIdOptionGroup2 & " AND options.idOption=options_optionsGroups.idOption"
  130.    call getFromDatabase(mySQL, rstemp, "getOptions") 
  131.  
  132.    f=0
  133.    do while not rstemp.eof
  134.      arrayOptions2(0,f)    = trim(rstemp("optionDescrip"))
  135.      arrayOptions2(1,f)    = rstemp("priceToAdd")
  136.      arrayOptions2(2,f)    = rstemp("percentageToAdd")
  137.      pHiddenIdOptions    = pHiddenIdOptions & rstemp("idOption") &"," 
  138.     f=f+2
  139.    rstemp.movenext
  140.    loop   
  141.  
  142.   end if
  143.  
  144. end sub
Aug 29 '08 #1
2 1956
Stewart Ross
2,545 Expert Mod 2GB
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.
Aug 29 '08 #2
Stewart Ross
2,545 Expert Mod 2GB
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
Aug 29 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

20
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...
5
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 ...
8
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...
51
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...
0
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...
6
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...
6
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...
2
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...
4
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 ...
6
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 =...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.