Declaring and Initialising an array of

WingYip
WingYip used Ask the Experts™
on
Hi

Is there a quicker method to code the following.  I was looking at the List datatype but could not get it to work.

       Dim customFields(8) As CampaignMonitor.SubscriberCustomField
        customFields(0) = New CampaignMonitor.SubscriberCustomField
        customFields(0).Key = "UserID"
        customFields(0).Value = oUser.ProviderUserKey.ToString
        customFields(1) = New CampaignMonitor.SubscriberCustomField
        customFields(1).Key = "Title"
        customFields(1).Value = Me.cboTitle.SelectedItem.Value
        customFields(2) = New CampaignMonitor.SubscriberCustomField
        customFields(2).Key = "Firstname"
        customFields(2).Value = Trim(Me.txtFirstname.Text)
        customFields(3) = New CampaignMonitor.SubscriberCustomField
        customFields(3).Key = "Surname"
        customFields(3).Value = Trim(Me.txtSurname.Text)
        customFields(4) = New CampaignMonitor.SubscriberCustomField
        customFields(4).Key = "TRPEmail"
        customFields(4).Value = Me.chkTRPEmail.Checked
        customFields(5) = New CampaignMonitor.SubscriberCustomField
        customFields(5).Key = "industry_status"
        customFields(5).Value = Me.cboIndustryStatus.SelectedItem.Value
        customFields(6) = New CampaignMonitor.SubscriberCustomField
        customFields(6).Key = "organisation"
        customFields(6).Value = Me.txtCompany.Text
        customFields(7) = New CampaignMonitor.SubscriberCustomField
        customFields(7).Key = "MemberType"
        customFields(7).Value = MemberType

Thanks

Wing
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009
Commented:
Not really...you still have to instantiate each instance when using an Array or a List.

One thing that would shorten the code would be if CampaignMonitor.SubscriberCustomField had a Constructor that accepted the two values and assigned them internally.

Then you could do:

        Dim customFields As New List(Of CampaignMonitor.SubscriberCustomField)
        customFields.Add(New CampaignMonitor.SubscriberCustomField("UserID", oUser.ProviderUserKey.ToString))
        customFields.Add(New CampaignMonitor.SubscriberCustomField("Title", Me.cboTitle.SelectedItem.Value))
        customFields.Add(New CampaignMonitor.SubscriberCustomField("Firstname", Trim(Me.txtFirstname.Text))
        ' etc...

Author

Commented:
Thanks

Wing

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial