Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6090141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:10:48+00:00 2026-05-23T12:10:48+00:00

My problem can be illustrated in the following example code, which sets up a

  • 0

My problem can be illustrated in the following example code, which sets up a data array of friends, each of which can have several phone numbers:

Class clsPhoneNo
  Dim strType
  Dim strNumber
End Class

Class clsPerson
  Dim strName
  Dim aclsPhoneNo()
End Class

Dim clsFriends()
ReDim clsFriends(3)
Set clsFriend(0) = New Person
clsFriend(0).strName = "Fred"
Set clsFriends(0).aclsPhoneNo(0) = New clsPhoneNo
ReDim clsFriend(0).aclsPhoneNo(2)
Set clsFriend(0).aclsPhoneNo(0).strType = "Home"
Set clsFriend(0).aclsPhoneNo(0) = "01234567890"
Set clsFriend(0).aclsPhoneNo(1).strType = "Work"
Set clsFriend(0).aclsPhoneNo(1) = "09876543210"

However, VBScript says

Microsoft VBScript compilation error: Expected end of statement

Before the . on the second ReDim statement

I need to have the aclsPhoneNo element variable length as my code isn’t really an address book, but this is a simple example demonstrating the issue.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:10:49+00:00Added an answer on May 23, 2026 at 12:10 pm

    Arrays are the wrong data structure to solve this problem. They are the weapon of choice in other languages, they are not in VBScript, for they are notoriously inflexible.

    Consider using Dictionaries instead. And drop the Hungarian.

    Dim phoneBook: Set phoneBook = New ObjectList
    
    With phoneBook.Append(New Person)
      .Name = "fred"
      .AddPhoneNo "Home", "01234567890"
      .AddPhoneNo "Work", "09876543210"
    End with
    
    Dim pers: Set pers = phoneBook.Item(1)
    
    For Each id In pers.PhoneNos.List
      Set num = pers.PhoneNos.List(id)
      WScript.Echo pers.Name & " #" & id & ": " & _
                   num.Number & " (" & num.Label & ")"
    Next
    
    ' ------------------------------------------------------
    Class ObjectList
      Public List
    
      Sub Class_Initialize()
        Set List = CreateObject("Scripting.Dictionary")
      End Sub
    
      Sub Class_Terminate()
        Set List = Nothing
      End Sub
    
      Function Append(Anything) 
        List.Add CStr(List.Count + 1), Anything 
        Set Append = Anything
      End Function
    
      Function Item(id) 
        If List.Exists(CStr(id)) Then
          Set Item = List(CStr(id))
        Else
          Set Item = Nothing
        End If
      End Function
    End Class
    
    ' ------------------------------------------------------
    Class PhoneNo
      Public Label
      Public Number
    End Class
    
    ' ------------------------------------------------------
    Class Person
      Public Name
      Public PhoneNos
    
      Sub Class_Initialize()
        Set PhoneNos = New ObjectList
      End Sub
    
      Function AddPhoneNo(Label, Number)
        Set AddPhoneNo = New PhoneNo
        With PhoneNos.Append(AddPhoneNo)
          .Label  = Label
          .Number = Number
        End With
      End Function
    End Class 
    

    Note that I made use of a few VB features here

    • You can use functions and classes before they are defined in the script, so put all your plumbing at the bottom.
    • You can have Public and Private class variables
    • Classes have an Initiate and a Terminate event that you can react to
    • Function names are variable declarations. No need to declare a temporary return variable in a function, you can use the function name for that.
    • The With block can save you a temporary variable as well.
    • Even though the dictionary is comparatively convenient, it can still benefit from convenience wrapper, so I created one.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.