Solved

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

Posted on 2014-01-24
4
223 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 63

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 63

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

752 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