?
Solved

VBSCRIPT - dim and redim?

Posted on 2006-06-29
12
Medium Priority
?
1,672 Views
Last Modified: 2012-05-05
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
Comment
Question by:paulwhelan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
12 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 17008046
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
 

Author Comment

by:paulwhelan
ID: 17008373
Hey!

I still get the same error even with


Dim erroneousWebsites()

Thanks
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 17008402
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:paulwhelan
ID: 17008470
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
 
LVL 5

Expert Comment

by:lunchbyte
ID: 17011165
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
 
LVL 13

Accepted Solution

by:
jmundsack earned 80 total points
ID: 17011602
The +1 is in the wrong spot.  Move it outside the paren:

ReDim Preserve erroneousWebsites(UBound(erroneousWebsites) + 1)
0
 
LVL 5

Expert Comment

by:lunchbyte
ID: 17011642
LOL. I made the same mistake. That damn copy and paste.
0
 
LVL 5

Expert Comment

by:lunchbyte
ID: 17011651
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
 
LVL 13

Expert Comment

by:jmundsack
ID: 17294823
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month12 days, 15 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question