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 3430956
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:16:01+00:00 2026-05-18T07:16:01+00:00

I am trying to make an array of hashtables. I don’t know if this

  • 0

I am trying to make an array of hashtables. I don’t know if this is the best solution, in PHP I would just do a multi-dim array, but it’s not so easy in .NET. I am pretty new o VB, so if there is a better solution for this please explain.

I have 2 emails fields for a contact, and a contact can have many. I just want to load in the first two on the edit page for editing, whatever they may be.

Private Sub loadPrimaryContactEmails(ByVal db As CRMDataDataContext, ByVal contactID As Guid)
        Dim q = (From ce In db.ContactEmails Where ce.ContactID = contactID Select ce).Take(2)
        Dim Emails As Array
        Dim count = 0
        For Each email In q
            Emails(count) = New Hashtable
            Emails(count).Add("email", email.Email)
            Emails(count).Add("label", email.Label)
            Emails(count).Add("id", email.ContactEmailID)
            count = count + 1
        Next
        txtPCEmail1.Text = Emails(0).Item("email")
        txtPCEmail1Label.Text = Emails(0).Item("label")
        lblEmail1ID.Text = Emails(0).Item("id")

        txtPCEmail2.Text = Emails(1).Item("email")
        txtPCEmail2Label.Text = Emails(1).Item("label")
        lblEmail2ID.Text = Emails(1).Item("id")
    End Sub

I get the error the first time I try to reference my array:

txtPCEmail1.Text = Emails(0).Item("email")

The error is:

Object variable or With block variable not set.

It builds, so I thought it might work. I can’t just loop through my datasource because I have to explicitly set textbox fields. Is there a better way to go about doing this? Or is there a way to make an array of hashtables work?

EDIT – here is the good code:
So I went w/ the HybridDictionary…

Private Sub loadPrimaryContactEmails(ByVal db As CRMDataDataContext, ByVal contactID As Guid)
        Dim q = (From ce In db.ContactEmails Where ce.ContactID = contactID Select ce).Take(2)
        Dim Emails As New HybridDictionary()
        Dim count = 1
        For Each email In q
            Emails.Add("email" + NCStr(count), email.Email)
            Emails.Add("label" + NCStr(count), email.Label)
            Emails.Add("id" + NCStr(count), email.ContactEmailID)
            count = count + 1
        Next
        txtPCEmail1.Text = Emails("email1")
        txtPCEmail1Label.Text = Emails("label1")
        lblEmail1ID.Text = Emails("id1")

        txtPCEmail2.Text = Emails("email2")
        txtPCEmail2Label.Text = Emails("label2")
        lblEmail2ID.Text = Emails("id2")
    End Sub

SO yeah, kind of a hack, but I don’t feel like I should have to making special methods just to load some data into a dictionary or array or whatever.

  • 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-18T07:16:01+00:00Added an answer on May 18, 2026 at 7:16 am

    Yes Phil is right you haven’t specified the Initial Size of the Array.

    And as suggested by him Use generic list or I would recommend

    “System.Collections.Specialized.StringCollection” Class or “System.Collections.Specialized.HybridDictionary” class

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was trying to make an array-based linear list, then I compiled this: char
I'm trying to make an array from all the GET-variables passed to a PHP
I'm trying to make will_paginate's :order to work with this array: @posts = current_user.subscribed_tags.map(&:posts).flatten.paginate(:page
I'm trying to make an array of zip codes. array = [07001, 07920] This
I'm trying to make an array of vectors like this: Vector<String>[] wordList = new
I am trying to make an array of strings and then pluck a random
I'm trying to make a dynamic array in C# but I get an annoying
I'm writing some error checking and trying to make use of an boolean array
I'm trying to subclass Array in ruby to make it randomize its elements when
Trying to make a simple program to catalogue books. Something like this, for example:

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.