[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1687
  • Last Modified:

VBSCRIPT - dim and redim?

Hi

I try to do this to keep an array with 'erroneous website names'

Dim erroneousWebsites(0)

While ...

ReDim Preserve erroneousWebsites(UBound(erroneousWebsites + 1))
    erroneousWebsites(UBound(erroneousWebsites)) = Trim(CStr(website_rows.fields("website").value))


Wend

but I get

Syntax error - type mismatch on the line

ReDim Preserve erroneousWebsites(UBound(erroneousWebsites + 1))
0
paulwhelan
Asked:
paulwhelan
  • 3
  • 2
  • 2
  • +1
1 Solution
 
TimCotteeCommented:
Hi paulwhelan,

You have to initially Dim the array with no elements:

Dim erroneousWebsites()

If you specify bounds in the initial declaration then it is fixed length and cannot be redimensioned.

Tim Cottee
0
 
paulwhelanAuthor Commented:
Hey!

I still get the same error even with


Dim erroneousWebsites()

Thanks
0
 
TimCotteeCommented:
paulwhelan,

Ok, that is probably because when it is declared initially it has no length and therefore UBound() is meaningless.
Try

If Len(Join(erroneousWebsites)) = 0 Then
    ReDim Preserve erroneousWebsites(1)
Else
    ReDim Preserve erroneousWebsites(UBound(erroneousWebsites + 1))
End If

To avoid this.


Tim
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
paulwhelanAuthor Commented:
Thanks Tim

That gives me an error at

ReDim Preserve erroneousWebsites(UBound(erroneousWebsites + 1))

---------------

If Len(Join(erroneousWebsites)) = 0 Then
      ReDim Preserve erroneousWebsites(1)
    Else
      ReDim Preserve erroneousWebsites(UBound(erroneousWebsites + 1))
    End If
0
 
lunchbyteCommented:
Here is what I do


Dim erroneousWebsites()

Then before I use it add more it it, I set it to zero and just ignore index zero.

redim
Dim erroneousWebsites(0)

YOUR LOOP or whatever
   ReDim Preserve erroneousWebsites(UBound(erroneousWebsites + 1))

   erroneousWebsites(UBound(erroneousWebsites)) = "YOUR VALUE"

END LOOP
0
 
jmundsackCommented:
The +1 is in the wrong spot.  Move it outside the paren:

ReDim Preserve erroneousWebsites(UBound(erroneousWebsites) + 1)
0
 
lunchbyteCommented:
LOL. I made the same mistake. That damn copy and paste.
0
 
lunchbyteCommented:
CORRECT ONE

Dim erroneousWebsites()

Then before I use it add more it it, I set it to zero and just ignore index zero.

redim
Dim erroneousWebsites(0)

YOUR LOOP or whatever
   ReDim Preserve erroneousWebsites(UBound(erroneousWebsites) + 1)

   erroneousWebsites(UBound(erroneousWebsites)) = "YOUR VALUE"

END LOOP
0
 
jmundsackCommented:
The reason for the error in the ORIGINAL QUESTION...

"Syntax error - type mismatch on the line
ReDim Preserve erroneousWebsites(UBound(erroneousWebsites + 1))"

...is because the + 1 is inside the parens, and I was the first to point this out.

TimCottee is also correct that if you want to ReDim you need to Dim without bounds initially.

But for 20 points it's hardly worth fighting about LOL.  Flip a coin?
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now