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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:37:03+00:00 2026-05-27T16:37:03+00:00

I defined the following type: Public Type settings key As String german As String

  • 0

I defined the following type:

Public Type settings
    key As String
    german As String
    french As String
End Type

How does the correct code look like to define an array with ~100 literal entries?

Someting like:

Dim translations as Array() = {
   (key="send", german="Senden", french="Enregistrer"),
   (key="directory", german="Verzeichnis", french="Liste"),
   ...
  • 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-27T16:37:04+00:00Added an answer on May 27, 2026 at 4:37 pm

    There’s no nice syntax for that in VBA. If you really need to init an array of a user-defined type, you can use a couple of helper functions to do it like this:

    Public Type settings
        key As String
        german As String
        french As String
    End Type
    
    Private Function NewTranslation(key As String, german As String, french As String) As settings
        NewTranslation.key = key
        NewTranslation.german = german
        NewTranslation.french = french
    End Function
    
    Private Sub AddTranslation(translations() As settings, value As settings)
        Dim u As Integer
        u = -1
        On Error Resume Next ' ubound raises an error if the array is not dimensioned yet
        u = UBound(translations)
        On Error GoTo 0
        ReDim Preserve translations(0 To u + 1) As settings
        translations(u + 1) = value
    End Sub
    
    Public Sub Main()
        Dim translations() As settings
        AddTranslation translations, NewTranslation("send", "Senden", "Enregister")
        AddTranslation translations, NewTranslation("directory", "Verzeichnis", "Liste")
        ' and so on
    End Sub
    

    A nicer way to do this particular problem would be a Collection (map) object using the language code and the original text as the key:

    Private translations As New Collection
    
    Public Sub Main()
        With translations
            .Add "Senden", "de:send"
            .Add "Enregister", "fr:send"
            .Add "Verzeichnis", "de:directory"
            .Add "Liste", "fr:directory"
        End With
    
        MsgBox GetTranslation("de", "send")
    End Sub
    
    Public Function GetTranslation(language As String, s As String)
        GetTranslation = s ' default to original text if no translation is available
        On Error Resume Next
        GetTranslation = translations(language + ":" + s)
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a legacy VB6 application that has the following structure defined: Public Type
In Excel 2007 I have the following very simple code in VBA: Public Type
I have a following class defined @JsonTypeName(PhotoSetUpdater) public class PhotoSetUpdater { @JsonProperty(Title) private String
If I have defined the following types: type category = Noun | Verb |
So I have the following user defined type in my oracle database: CREATE OR
I've defined the following view: <CollectionViewSource x:Key=PatientsView Source={Binding Source={x:Static Application.Current}, Path=Patients}/> Where Patient is
I have defined the following Interface [ServiceContract] public interface IHealthProducts { [OperationContract()] ResponseClass OrderSelfSignedHealthCertificate();
Let's say I have defined the following class: public abstract class Event { public
A Java method call may be parameterized like in the following code: class Test
How come java doesn't allow the following generic return type: public <T extends Enum<T>

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.