Assigning Values To An Array Doesn’t Work In Included File In ASP (VBScript)

November 26th, 2008  | Categories: ASP

I have run into a lot of little issues with ASP that I can’t seem to find documentation on. I admit, I’m not 100% on .NET but I do know VBScript. The problem I ran into was with a configuration file I had set up so I can use constant variables throughout the website. I declare all my variables in my directory includes in a file named .

When I went to set up an array that I want to use throughout the website, cfg_media_types_array, declaration goes fine but assigning the array values throws an error.

Line 22:
Line 23: Dim cfg_media_types_array(4)
Line 24: cfg_media_types_array(1) = “CD”
Line 25: cfg_media_types_array(2) = “Floppy”
Line 26: cfg_media_types_array(3) = “DVD”

The error I receive is the Compilation Error BC30188: Declaration expected.

I’ve also tried different ways of implementing the cfg_media_types_array variable, whatever I could find on the internet. None of which would successfully compile.

Furthermore, I tried to assign the values of the array in a different scope (in different <% %> brackets). That wouldn’t work either.

Since strings have no problem being declared and assigned in my config file, I simply declared a strong with coma separated values.

Dim cfg_media_types_array As String = “CD,Floppy,DVD,Other”

When I need to use the string, I simply do a split.

' split the configuration media types string up to an array
Dim a = split(cfg_media_types_array, ",")
Dim b
' loop through the array
For Each b in a
          Response.Write("<option value=""" & b & """")
          If b = sw_media_type Then
                    Response.Write(" selected=""selected""")
          End If

          Response.Write(">" & b & "</option>" & VbCrLf)
  1. December 7th, 2009 at 12:03
    Reply | Quote | #1

    Since you are using an ASPX page, wouldn’t this be VB.NET, not VBScript?

    Your code example works just fine for me in VBScript.

    But in VB.NET you could either use the system array, like this:

    Dim cfg_media_types_array() As String = {“CD”, “Floppy”, “DVD”, “Other”}

    Or you could take advantage of the other collection classes from the framework such as ArrayList: