Solved

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

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
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…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 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

19 Experts available now in Live!

Get 1:1 Help Now