Solved

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

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

RHCE - Red Hat OpenStack Prep Course

This course will provide in-depth training so that students who currently hold the EX200 & EX210 certifications can sit for the EX310 exam. Students will learn how to deploy & manage a full Red Hat environment with Ceph block storage, & integrate Ceph into other OpenStack service

Question has a verified solution.

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

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

626 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