Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
subscript out of range error
#1
Code:
REDIM addressarray(numofrecs1,3)
addresscounter=0
For i=1 to numofrecs1
   GET #1 i,address
    lastnametemp1$=MID$(address.lastname,1,spp)
    lastnametemp2$=MID$(startingpoint$,1,spp)

    IF startingpoint$="a" + SPACE$(length-1) then '*** Search All Names
         addresscounter=addresscounter+1
         addressarray$(addresscounter,1)=address.lastname
         addressarray$(addresscounter,2)=address.firstname
         addressarray$(addresscounter,3)=STR$(i)
    END IF

    IF lastnametemp1$=lastnametemp2$ THEN  '*** Search Specific
         addresscounter=addresscounter+1
         addressarray$(addresscounter,1)=address.lastname
         addressarray$(addresscounter,2)=address.firstname
         addressarray$(addresscounter,3)=STR(i)
    END IF


*****  Problem

While in the first if statement (Search the entire file) works fine as long as numofrecs1 is only 10 or less.  If more then 10 then I get a subscript out of range error when I get to the 11th record on the addressarray$(addresscounter,1)=address.lastname statement
Reply
#2
jgr,

The problem comes from your not DIMentioning the size of "numofrecsl". So QB uses the default of 10.
If you wish to go larger(greater) than 10 you will need to DIMmention "numofrecsl to a greater size.
If you are not sure of what that size will be then there are ways to handle this, but for right now I suggest you set it to 100.
***** EXAMPLE *****
DIM numofrecsl (100)
REDIM addressarry (numofrecsl,3)
'rest of your program goes here
This should give you plenty of memory set aside for your project.

I hope this helps. :wink:
adsherm
Reply
#3
numofrecs1 is set to the number of records in the file. Thus I wanted to set the array size to the same. So if the numofrecs1=12 then why can't you just say dim xxxx$(numofrecs1,3) ??? Or are you not allowed to use variables in the dim and redim?? If not then I will just dim it to something that I know will be large enough.

Thanks
Reply
#4
ok I found one problem that I had

the redim statement was wrong

it was redim addressarray(numofrecs1,3)
but shoud be redim addressarray$(numofrecs1,3)


but now I get the error message array already dimensioned on the redim statement.
Reply
#5
put a DIM arrayname(0) at the beginning of your code, then you can REDIM to your heart's content.
Reply
#6
at the beginning of the program

option base 1
dim addressarray$(10,3)


in the body of the program

redim addressarray$(100,3)

and I get array already dimensioned error
Reply
#7
oops. my bad. make that first DIM a REDIM.
Reply
#8
Thanks Meg, works fine now. Not sure if really understand why to use redim when first defining the array. Thanks again
Reply
#9
O.k. I think I found the problem.
With using the number of records as 12, the first time thru it should say:
DIM numofrecs1 (12): DIM addressarray$(numofrecs1,3)
Since numofrecs1 = 12, this is the same as:
DIM addressarray$(12,3)
This means you have 12 records with 3 parts to each record.
(I just added that for those who may be reading this, but don't really understand.)
After that you should have:
REDIM numofrecs1(100) :REDIM addressarray$(numofrecs,3)
However, you really don't need to raise it to 100 since you already know how many files you have, so the REDIM numofrecs1 isn't really needed, but the REDIM addressarray$(numofrecs1,3) would still be.
What Meg suggested was a good one. That way you can REDIM it as needed.

( I usually add 1 more to the count for a "cushion". So it would be 13 rather than 12, but that's my own doing as it's not really needed.)

Sorry for the "numofresl" in my first reply.
That's really what I thought it said. :oops:
adsherm
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)