Solved

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

Posted on 2014-01-24
4
214 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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…

776 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