[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

VBSCRIPT - dim and redim?

Posted on 2006-06-29
12
Medium Priority
?
1,679 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

656 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