Solved

Populate a bidemensional array in VB.Net 2012 (code posted)

Posted on 2014-01-24
4
208 Views
Last Modified: 2014-01-30
Hi,
I am trying to populate an array but I cann't make it work...
I have a 'message' string with the following text (spaces between every word):
"AWVLI QIQVT QOSQO ELGCV IIQWD LCUQE EOENN WWOAO LTDNU QTGAW TSMDO QTLAO QSDCH PQQIQ DQQTQ OOTUD BNIQH BHHTD UTEET FDUEA UMORE SQEQE MLTME TIREC LICAI QATUN QRALT ENEIN RKG"

In my code, firstly, I have to remove spaces from the above text. Then, I have to save the resulting 143 letters into my array called 'nuevo_array' (11rows x 13columns matrix).

The resulting array should contain the following:
AWVLIQIQVTQOS
QOELGCVIIQWDL
CUQEEOENNWWOA
OLTDNUQTGAWTS
MDOQTLAOQSDCH
PQQIQDQQTQOOT
UDBNIQHBHHTDU
TEETFDUEAUMOR
ESQEQEMLTMETI
RECLICAIQATUN
QRALTENEINRKG

    Private Sub btnAnalizar_Click(sender As Object, e As EventArgs) Handles btnAnalizar.Click
        Dim message As String = txtTextoOriginal.Text
        Dim b As String() = message.Split(" ".ToCharArray)

        Dim total_letras As Integer = message.Length '143 letters
        lblLetras.Text = total_letras

        Dim x As Integer = 12
        Dim y As Integer = 10
        Dim nuevo_array(x, y) As String

        For i = 0 To x
            For j = 0 To y
                nuevo_array(x, y) = b.substring(0, 1)
            Next
        Next

    End Sub

Open in new window

0
Comment
Question by:José Perez
  • 2
  • 2
4 Comments
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 250 total points
ID: 39807677
Hi oscargarin;

Try it like this.

Private Sub btnAnalizar_Click(sender As Object, e As EventArgs) Handles btnAnalizar.Click

     ' Remove all spaces characters from the message
     Dim message As String = txtTextoOriginal.Text.Replace(" ", "")

     Dim total_letras As Integer = message.Length '143 letters
     lblLetras.Text = total_letras

     Dim x As Integer = 12
     Dim y As Integer = 10
     ' Use a char array seeming each character is one array element
     Dim nuevo_array(x, y) As Char
     ' Use to index into the message string
     Dim idx As Integer = 0

     For i = 0 To x
         For j = 0 To y
             nuevo_array(i, j) = message(idx)
             ' Position to next character in the message string
             idx += 1
         Next
     Next

End Sub

Open in new window

0
 
LVL 2

Author Closing Comment

by:José Perez
ID: 39821905
Sorry I was late.... the answer is perfect!
Thanks a lot.
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 39821923
Not a problem, glad I was able to help.
0
 
LVL 2

Author Comment

by:José Perez
ID: 39821940
:)
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now