?
Solved

What is wrong with this array?

Posted on 2003-03-02
6
Medium Priority
?
135 Views
Last Modified: 2010-05-01
Dim BannedWords(2) As String
BannedWords = Array("word1", "word2", "word3")

When run, VB highlights BannedWords and says "Can't assign to an array"
0
Comment
Question by:bomax
[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
6 Comments
 
LVL 3

Expert Comment

by:DeAn
ID: 8052554
you dimensioned it with 2 elements and gave it 3
0
 
LVL 3

Expert Comment

by:DeAn
ID: 8052556
remove the 2
0
 
LVL 5

Accepted Solution

by:
Cimperiali earned 200 total points
ID: 8052584
From msdn:
Array Function
Returns a Variant containing an array.

That means: you cannot use it with a string array.
Moreover, you cannot make this directly array1= array2 unless both are variants
Thus, if you want to use the Array function, you have to code it this way:
Private Sub Command1_Click()
'Note the following array is not simply a variant, but also a non dimensioned one!
Dim bannedwords() As Variant
  bannedwords = Array("w1", "w2", "w3")
End Sub
0
Independent Software Vendors: 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!

 
LVL 70

Expert Comment

by:Éric Moreau
ID: 8052588
The right syntax is:

Dim BannedWords As variant
BannedWords = Array("word1", "word2", "word3")
0
 
LVL 3

Expert Comment

by:DeAn
ID: 8052596
sorry... disregard, those are incorrect :(
0
 

Author Comment

by:bomax
ID: 8052719
Thank you....and Dean -- no worries ;)
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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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
Course of the Month12 days, 8 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