|
-
Jun 27th, 2002, 12:42 PM
#1
Thread Starter
Frenzied Member
combining arrays
I have two arrays that are created with the following code and then attempted to be concatenated with the last for loop. However it gives a "subscript out of range" error after only one iteration!? help!?
VB Code:
intmon = Format(strx, "mm")
intyr = Format(strx, "yy")
Open "O:\ER2002\Inetlog\" & intyr & "\" & intmon & "\" & intmon & "e.htm" For Input As #1
rtb1.LoadFile "O:\ER2002\Inetlog\" & intyr & "\" & intmon & "\" & intmon & "e.htm"
Close #1
arrmon = Split(rtb1, "</a></div>")
i = UBound(arrmon, 1)
intmon = Format(Now, "mm")
intyr = Format(Now, "yy")
Open "O:\ER2002\Inetlog\" & intyr & "\" & intmon & "\" & intmon & "e.htm" For Input As #1
rtb1.LoadFile "O:\ER2002\Inetlog\" & intyr & "\" & intmon & "\" & intmon & "e.htm"
Close #1
arrmon2 = Split(rtb1, "</a></div>")
For x = 0 To UBound(arrmon2, 1)
arrmon(i) = arrmon2(x)
i = i + 1
Next x
Last edited by ober0330; Jun 27th, 2002 at 12:50 PM.
-
Jun 27th, 2002, 01:11 PM
#2
PowerPoster
VB Code:
redim arrmon(Ubound(arrmon2))
For i = Lbound(arrmon2) To UBound(arrmon2)
arrmon(i) = arrmon2(i)
Next i
-
Jun 27th, 2002, 01:12 PM
#3
PowerPoster
actually, you can probably just assign the array in one line.
arrmon = arrmon2
-
Jun 27th, 2002, 01:19 PM
#4
PowerPoster
well since you start off the index at the upper bound of the array, you'd pretty much expect to get an index error after one iteration, huh?
you need to redim the array before attempting to concatenate the 2nd one onto the end of it. Otherwise your code is fine.
cafeenman seems to have mistaken you question for how to reassign one array to another, not concatenate as you asked.
-
Jun 27th, 2002, 01:32 PM
#5
Thread Starter
Frenzied Member
ok, I thought there was something wrong with that.
here's what I've done:
VB Code:
ReDim arrmon(UBound(arrmon) + UBound(arrmon2))
For x = 0 To UBound(arrmon2, 1)
arrmon(i) = arrmon2(x)
i = i + 1
Next x
However, when I do that, it makes all of the initial array nothing. I've tried using "Preserve", but that appears to simply put the second array in the new array twice!?!
-
Jun 27th, 2002, 01:37 PM
#6
Thread Starter
Frenzied Member
scratch that... my
VB Code:
strx = Now -1
intmon = Format(strx, "mm")
is giving me the wrong date (this month).... !?
-
Jun 27th, 2002, 01:38 PM
#7
PowerPoster
hm ... your code looks good to me, but I'm don't use redim. there must be something we're missing, obviously.
you could always just make a large 3rd array and move the 1st then the 2nd into it. that's inelegant, but memory's cheap
-
Jun 27th, 2002, 01:40 PM
#8
Frenzied Member
Code analysis:
Set the value of var "strx" to TODAY - 1 DAY
Get the month
So unless if it's the first of the month (which is not the case), it would return this month. Try this instead:
VB Code:
strx = DateAdd("n", -1, Now)
intmon = Format(strx, "mm")
MicroBasic
Dragon Shadow Trainer
There is no good or evil in the world...only programmers and fools .
-
Jun 27th, 2002, 01:50 PM
#9
Thread Starter
Frenzied Member
actually i just did:
VB Code:
strx = Now - 30
intmon = Format(strx, "mm")
That works fine now. I'm still having problems with the arrays tho.
The first array[portion] /edit in the concatenated array comes up as empty elements, and there's a few extra elements on the end of the concatenated array(which I can deal with).
anyone?
-
Jun 27th, 2002, 01:51 PM
#10
Frenzied Member
I've just noticed something. Your code will replace the last variable in the first array. To prevent that, use:
VB Code:
intmon = Format(strx, "mm")
intyr = Format(strx, "yy")
Open "O:\ER2002\Inetlog\" & intyr & "\" & intmon & "\" & intmon & "e.htm" For Input As #1
rtb1.LoadFile "O:\ER2002\Inetlog\" & intyr & "\" & intmon & "\" & intmon & "e.htm"
Close #1
arrmon = Split(rtb1, "</a></div>")
i = UBound(arrmon, 1) + 1
intmon = Format(Now, "mm")
intyr = Format(Now, "yy")
Open "O:\ER2002\Inetlog\" & intyr & "\" & intmon & "\" & intmon & "e.htm" For Input As #1
rtb1.LoadFile "O:\ER2002\Inetlog\" & intyr & "\" & intmon & "\" & intmon & "e.htm"
Close #1
arrmon2 = Split(rtb1, "</a></div>")
ReDim Preserve arrmon(UBound(arrmon) + UBound(arrmon2) + 1)
For x = 0 To UBound(arrmon2, 1)
arrmon(i) = arrmon2(x)
i = i + 1
Next x
MicroBasic
Dragon Shadow Trainer
There is no good or evil in the world...only programmers and fools .
-
Jun 27th, 2002, 01:55 PM
#11
Frenzied Member
Originally posted by ober5861
actually i just did:
VB Code:
strx = Now - 30
intmon = Format(strx, "mm")
NO! That is NOT RIGHT! Set your computer date to July 31, 2002 and see if that code works. It will warp back to July 1, which is still July!!!
Also, if you set your calender to March 1 and use that code, it will return January, NOT February!!!
MicroBasic
Dragon Shadow Trainer
There is no good or evil in the world...only programmers and fools .
-
Jun 27th, 2002, 01:59 PM
#12
Thread Starter
Frenzied Member
i just saw that myself 
and I knew about the problem with the 30 days, I was going to fix that later. I just wanted to get the array catonation to work.
It works perfectly now. Thank you all.
-
Jun 27th, 2002, 02:26 PM
#13
Frenzied Member
PMbyober5861
hey, thanks for your help, but a piece of code you gave me doesn't work like you said:
strx = DateAdd("n", -1, Now)
That still returns the current month!?!
You PMed me concerning my code. OK, here's the modified code:
VB Code:
strx = DateAdd("[b]m[/b]", -1, Now)
intmon = Format(strx, "mm")
Iactuallychangedtheminutesinsteadofthemonth...Iamstupid...:(
MicroBasic
Dragon Shadow Trainer
There is no good or evil in the world...only programmers and fools .
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
|