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

  • Home
  • SEARCH
  • 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 9231591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:06:33+00:00 2026-06-18T06:06:33+00:00

I am trying to write a VBScript which will read a text file and

  • 0

I am trying to write a VBScript which will read a text file and build a dictionary which contains lists. Let me explain with an example:

The input file would be a simple text file of the sort:

Male,Peter
Male,Chris
Male,Stewie
Male,Brian
Female,Lois
Female,Meg

When I run my script, I would like a dictionary with the first column as the key, and the second column as the values

{'Male':['Peter,Chris,Stewie,Brian']}
{'Female':['Lois,Meg']}

The lack of dynamic arrays or lists in VBScript is making this a real pain. Any suggestion how I might tackle this?

Cheers

  • 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-06-18T06:06:34+00:00Added an answer on June 18, 2026 at 6:06 am

    Just to say, I’m not compete with posted answers for repo-point 😉
    If you can convert my post to comment, feel free to do that.

    I like Ansgar’s idea (+1) as it based on single Dictionary and that seems to me quite enough to get back easy what is stored inside.

    The need of .Exists may come in use in 2 cases – (a) if we don’t know how many genders we have, and (b) if we don’t know how they looks like (pronunciation). The rest is similar to Ansgar’s idea.

    Option Explicit
    
    Const cGender = 0
    Const cName = 1
    
    Dim sGender, sName, sLine
    Dim oFSO, oFile, oDict
    Dim arrLine
    
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    Set oDict = CreateObject("Scripting.Dictionary")
    Set oFile = oFSO.OpenTextFile("persons_list.txt")
    
    Do Until oFile.AtEndOfStream
        sLine = oFile.ReadLine
        If Len(sLine) Then
            arrLine = Split(sLine, ",")
            sGender = arrLine(cGender)
            sName = arrLine(cName)
    
            If Not oDict.Exists(sGender) Then
                oDict.Add sGender, CreateObject("System.Collections.ArrayList")
            End If
    
            oDict(sGender).Add sName
        End If
    Loop
    
    oFile.Close
    Set oFile = Nothing
    Set oFSO = Nothing
    
    WScript.Echo "Genders:" & oDict.Count, vbNewLine & Join(oDict.Keys)
    
    Dim sKey
    For Each sKey In oDict
        WScript.Echo sKey, oDict(sKey).Count, vbNewLine & Join(oDict(sKey).ToArray())
    Next
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to write a couple of functions that will encrypt or decrypt a file
VBScript does delivers an Illegal Argument message when trying to write the text shown
Trying to write a byte[] to a file, which i think is working correctly
I've been trying write an application which will be able to connect to a
I am new to VBScript. I am trying to write a function that will
I am trying to write a vbscript utility that will add or remove several
I'm trying to write a VBScript that will export and import the code modules
My current knowledge: If you are trying to write text files in vbscript /
Trying to write app for service technicians that will display open service calls within
I'm trying to read xml file from vbs script. Xml is encoded in utf-8

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.