Click here to Skip to main content
15,118,865 members
Articles / Programming Languages / Visual Basic
Posted 26 Jul 2015


5 bookmarked

Arrays Generator

Rate me:
Please Sign up or sign in to vote.
4.81/5 (12 votes)
26 Jul 2015CPOL2 min read
Generate your arrays using a GUI tool

Image 1


Image 2

This project is a simple application that'll make you able to generate your arrays (long or short ones) in a better and easier way.


While I was creating an application that contains a lot of arrays to highlight some specific words, I felt bored and tired by writing codes and symbols again and again, so I decided to create this project to help me to generate long arrays to save time and strength.

Using the Code

The project uses many loops to:

  • Generate a table
  • Add items to ContextMenuStrip
  • Generate the array code depending on your settings

So let's explain it part by part.

First, you have to declare some variables that'll contain your settings.


private string arrayName { get; set; }
     private string arrayType { get; set; }
     private decimal arraySize { get; set; }
     private TextBox array = new TextBox();
     private string language { get; set; }


Private Property arrayName() As String
           Return m_arrayName
       End Get
       Set(value As String)
           m_arrayName = value
       End Set
   End Property
   Private m_arrayName As String
   Private Property arrayType() As String
           Return m_arrayType
       End Get
       Set(value As String)
           m_arrayType = value
       End Set
   End Property
   Private m_arrayType As String
   Private Property arraySize() As Decimal
           Return m_arraySize
       End Get
       Set(value As Decimal)
           m_arraySize = value
       End Set
   End Property
   Private m_arraySize As Decimal
   Private array As New TextBox()
   Private Property language() As String
           Return m_language
       End Get
       Set(value As String)
           m_language = value
       End Set
   End Property
   Private m_language As String

Generate a Table

The table you'll generate depends on the settings you entered (example: number of columns):

Image 3

As I said from the beginning that the project contains many loops, one of them is the one that we'll use to generate the table and the ContextMenuStrip items:

Image 4


arrayName = an.Text;
           arraySize = number.Value;
           arrayType = type.Text;
           language = lan.Text;

           for (int i = 0; i < arraySize; i++)
               arrays.Columns.Add(i.ToString(), arrayName + "[" + i + "]");
               cm.Items.Add("Go to "+arrayName+"[" + i + "]",


arrayName = an.Text
   arraySize = number.Value
   arrayType = type.Text
   language = lan.Text

   For i As Integer = 0 To arraySize - 1
       arrays.Columns.Add(i.ToString(), arrayName + "[" + i.ToString() + "]")
       cm.Items.Add("Go to " + arrayName + "[" + i.ToString() + "]",

As you can notice that the code will simply add columns into the datagridview controller and items (including its image) to the right click popup menu.

As a user, all you have to do is to fill the cells, then generate the code. :)

BUT wait, you are a developer and you want to understand how it works!
Trust me it's too easy, you only have to manipulate strings, and use some if statements. Take a look at a simple code:


 if (language == "")
                    if (arrayType == "string")
                        code.Text = "dim " + arrayName + " as string() = {";
                        for (int i = 0; i < arrays.Columns.Count; i++)
                            string cellValue = arrays.Rows[0].Cells[i].Value.ToString();
                            code.AppendText(symbole + cellValue + symbole + ",");
                        code.Text = code.Text.Replace(",}", "};");


If language = "" Then
                If arrayType = "string" Then
                    code.Text = "dim " + arrayName + " as string() = {"
                    For i As Integer = 0 To arrays.Columns.Count - 1
                        Dim cellValue As String = arrays.Rows(0).Cells(i).Value.ToString()
                        code.AppendText((symbole & cellValue) + symbole + ",")
                    code.Text = code.Text.Replace(",}", "}")
                End If
End If

The result is as follows:

Image 5


  • You can create your custom generator basing it on this one.
  • I did not add syntax highlighting because I wanted it to be as simple as possible.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Alaa Ben Fatma
France France
No Biography provided

Comments and Discussions

SuggestionT4 Pin
Dave Elliott27-Jul-15 7:23
MemberDave Elliott27-Jul-15 7:23 
SuggestionMissing images Pin
Wendelius26-Jul-15 9:48
mveWendelius26-Jul-15 9:48 
GeneralRe: Missing images Pin
Alaa Ben Fatma26-Jul-15 9:59
professionalAlaa Ben Fatma26-Jul-15 9:59 
GeneralMy vote of 5 Pin
Mohamed Aziz Lahbecha26-Jul-15 9:45
MemberMohamed Aziz Lahbecha26-Jul-15 9:45 
GeneralRe: My vote of 5 Pin
Alaa Ben Fatma26-Jul-15 9:59
professionalAlaa Ben Fatma26-Jul-15 9:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.