Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

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

What is wrong with this array?

Dim BannedWords(2) As String
BannedWords = Array("word1", "word2", "word3")

When run, VB highlights BannedWords and says "Can't assign to an array"
0
bomax
Asked:
bomax
1 Solution
 
DeAnCommented:
you dimensioned it with 2 elements and gave it 3
0
 
DeAnCommented:
remove the 2
0
 
CimperialiCommented:
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!

 
Éric MoreauSenior .Net ConsultantCommented:
The right syntax is:

Dim BannedWords As variant
BannedWords = Array("word1", "word2", "word3")
0
 
DeAnCommented:
sorry... disregard, those are incorrect :(
0
 
bomaxAuthor Commented:
Thank you....and Dean -- no worries ;)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now