Results 1 to 13 of 13

Thread: combining arrays

  1. #1

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    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:
    1. intmon = Format(strx, "mm")
    2. intyr = Format(strx, "yy")
    3.  
    4. Open "O:\ER2002\Inetlog\" & intyr & "\" & intmon & "\" & intmon & "e.htm" For Input As #1
    5.     rtb1.LoadFile "O:\ER2002\Inetlog\" & intyr & "\" & intmon & "\" & intmon & "e.htm"
    6. Close #1
    7.     arrmon = Split(rtb1, "</a></div>")
    8. i = UBound(arrmon, 1)
    9.  
    10. intmon = Format(Now, "mm")
    11. intyr = Format(Now, "yy")
    12.  
    13. Open "O:\ER2002\Inetlog\" & intyr & "\" & intmon & "\" & intmon & "e.htm" For Input As #1
    14.     rtb1.LoadFile "O:\ER2002\Inetlog\" & intyr & "\" & intmon & "\" & intmon & "e.htm"
    15. Close #1
    16.     arrmon2 = Split(rtb1, "</a></div>")
    17.    
    18. For x = 0 To UBound(arrmon2, 1)
    19.      arrmon(i) = arrmon2(x)
    20.      i = i + 1
    21. Next x
    Last edited by ober0330; Jun 27th, 2002 at 12:50 PM.

  2. #2
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819
    VB Code:
    1. redim arrmon(Ubound(arrmon2))
    2. For i = Lbound(arrmon2) To UBound(arrmon2)
    3.      arrmon(i) = arrmon2(i)
    4. Next i

  3. #3
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819
    actually, you can probably just assign the array in one line.

    arrmon = arrmon2

  4. #4
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904
    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.

  5. #5

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    ok, I thought there was something wrong with that.

    here's what I've done:

    VB Code:
    1. ReDim arrmon(UBound(arrmon) + UBound(arrmon2))
    2. For x = 0 To UBound(arrmon2, 1)
    3.      arrmon(i) = arrmon2(x)
    4.      i = i + 1
    5. 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!?!

  6. #6

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    scratch that... my

    VB Code:
    1. strx = Now -1
    2. intmon = Format(strx, "mm")

    is giving me the wrong date (this month).... !?

  7. #7
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904
    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

  8. #8
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    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:
    1. strx = DateAdd("n", -1, Now)
    2. intmon = Format(strx, "mm")


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  9. #9

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    actually i just did:

    VB Code:
    1. strx = Now - 30
    2. 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?

  10. #10
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    I've just noticed something. Your code will replace the last variable in the first array. To prevent that, use:

    VB Code:
    1. intmon = Format(strx, "mm")
    2. intyr = Format(strx, "yy")
    3.  
    4. Open "O:\ER2002\Inetlog\" & intyr & "\" & intmon & "\" & intmon & "e.htm" For Input As #1
    5.     rtb1.LoadFile "O:\ER2002\Inetlog\" & intyr & "\" & intmon & "\" & intmon & "e.htm"
    6. Close #1
    7. arrmon = Split(rtb1, "</a></div>")
    8. i = UBound(arrmon, 1) + 1
    9.  
    10. intmon = Format(Now, "mm")
    11. intyr = Format(Now, "yy")
    12.  
    13. Open "O:\ER2002\Inetlog\" & intyr & "\" & intmon & "\" & intmon & "e.htm" For Input As #1
    14.     rtb1.LoadFile "O:\ER2002\Inetlog\" & intyr & "\" & intmon & "\" & intmon & "e.htm"
    15. Close #1
    16.     arrmon2 = Split(rtb1, "</a></div>")
    17.    
    18. ReDim Preserve arrmon(UBound(arrmon) + UBound(arrmon2) + 1)
    19. For x = 0 To UBound(arrmon2, 1)
    20.      arrmon(i) = arrmon2(x)
    21.      i = i + 1
    22. Next x


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  11. #11
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    Originally posted by ober5861
    actually i just did:

    VB Code:
    1. strx = Now - 30
    2. 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 .

  12. #12

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    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.

  13. #13
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    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:
    1. strx = DateAdd("[b]m[/b]", -1, Now)
    2. 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
  •  



Click Here to Expand Forum to Full Width