Create Array to String(,)

Thor Vestaberg
Thor Vestaberg used Ask the Experts™
on
I'm working with Google maps, and need to generate the Position list from database. I have not work to much with these things, and struggle to create an array that I can use.

This is how the sample line looks:
 Dim positonTitlesAndIcons As String(,) = New String(2, 3) {{"58.468688", "7.515196", "Test1", "truck_red.png"}, {"60.182109", "10.324894", "Test2", "truck_red.png"}, {"69.902528", "22.898733", "Test3", "truck_red.png"}}

But I need to create some sort of array/params like this


My.array(0) = ""58.468688", "7.515196", "Test1", "truck_red.png""
My.array(1) = ""60.182109", "10.324894", "Test2", "truck_red.png""
My.array(2) = ""69.902528", "22.898733", "Test3", "truck_red.png""

Dim positonTitlesAndIcons As String(,) = MyArray()

I get errors like this: Value of type 'Object()' cannot be converted to 'String(*,*)
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
If the end results really need to be this: Dim positonTitlesAndIcons As String(,)

Then there's no other way to do it as shown in the example.

If you want to do it in a _slightly_ other way, it's like this. But besides that, if you need this variable to be like that, then that's it.

positonTitlesAndIcons(0, 0) = "58.468688"
positonTitlesAndIcons(0, 1) = "7.515196"
positonTitlesAndIcons(0, 2) = "Test1"
positonTitlesAndIcons(0, 3) = "truck_red.png"
positonTitlesAndIcons(1, 0) = "60.182109"
positonTitlesAndIcons(1, 1) = "10.324894"
positonTitlesAndIcons(1, 2) = "Test2"
positonTitlesAndIcons(1, 3) = "truck_red.png"
positonTitlesAndIcons(2, 0) = "69.902528"
positonTitlesAndIcons(2, 1) = "22.898733"
positonTitlesAndIcons(2, 2) = "Test3"
positonTitlesAndIcons(2, 3) = "truck_red.png"
Eduard GherguArchitect - Coder - Mentor

Commented:
Hi,
How the data from database looks like?
Thor VestabergDeveloper

Author

Commented:
I tried your solution @Kimputer, but I get an error, se error2.png

@Eduard Ghergu the database is simple, just name an location data
My trouble is that i don't understand why the array i give it gives me error :-)
Se error.png
error.png
error2.png
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Fernando SotoRetired
Distinguished Expert 2017

Commented:
Hi Thor;

Is this more of what you are looking for?
'' This is how the sample line looks:
Dim positonTitlesAndIcons As String(,) = New String(2, 3) {{"58.468688", "7.515196", "Test1", "truck_red.png"}, {"60.182109", "10.324894", "Test2", "truck_red.png"}, {"69.902528", "22.898733", "Test3", "truck_red.png"}}
'' Number of rows in the 2D array
Dim rows = positonTitlesAndIcons.GetLength(0) - 1
'' Number of columns in the 2D array
Dim columns = positonTitlesAndIcons.GetLength(1) - 1
Dim Myarray(rows) As String

'' Parse the sample line into the Myarray
For index1 = 0 To rows
    For index2 = 0 To columns
        '' Build each element of the Myarray
        Myarray(index1) = Myarray(index1) & ",""" & positonTitlesAndIcons(index1, index2) & """"
    Next
    '' Remove the leadding comma
    Myarray(index1) = Myarray(index1).TrimStart(",")
Next 

Open in new window


Fernando

Commented:
Your error shows ,because you should initialize it this way:

Dim positonTitlesAndIcons As String(,) = New String(2, 3)

Then the rest of the code works.
Thor VestabergDeveloper

Author

Commented:
Still not quite there @Kimputer, I tried that to, but that give the error you see in file error3.png :-)

The error is on the siffer "2"

I hope you can help me, almost there :-)
error3.png
Thor VestabergDeveloper

Author

Commented:
@Fernando

No, I dont need an array from:
Dim positonTitlesAndIcons As String(,) = New String(2, 3) {{"58.468688", "7.515196", "Test1", "truck_red.png"}, {"60.182109", "10.324894", "Test2", "truck_red.png"}, {"69.902528", "22.898733", "Test3", "truck_red.png"}}

I want to build and array that I can put into like this
Dim positonTitlesAndIcons As String(,) = Myarray()

But i look like the comma in String(,) creates the problem. But it has to be there, if else I get error in the last line:
Dim gmh As GoogleMapHelper = New GoogleMapHelper(wbmap, positonTitlesAndIcons)
Thor VestabergDeveloper

Author

Commented:
I Solved it :-)

had to add {}  :-)

Dim positonTitlesAndIcons As String(,) = New String(2, 3) {}

Thanks @Kimputer for give me good direction

This is the sample result before i write code to add data from database:

Dim positonTitlesAndIcons As String(,) = New String(2, 3) {}

        positonTitlesAndIcons(0, 0) = "58.468688"
        positonTitlesAndIcons(0, 1) = "7.515196"
        positonTitlesAndIcons(0, 2) = "Test1"
        positonTitlesAndIcons(0, 3) = "10.png"
        positonTitlesAndIcons(1, 0) = "60.182109"
        positonTitlesAndIcons(1, 1) = "10.324894"
        positonTitlesAndIcons(1, 2) = "Test2"
        positonTitlesAndIcons(1, 3) = "46.png"
        positonTitlesAndIcons(2, 0) = "69.902528"
        positonTitlesAndIcons(2, 1) = "22.898733"
        positonTitlesAndIcons(2, 2) = "Test3"
        positonTitlesAndIcons(2, 3) = "28.png"


        Dim gmh As GoogleMapHelper = New GoogleMapHelper(wbmap, positonTitlesAndIcons)
        gmh.loadMap()
Thor VestabergDeveloper

Author

Commented:
Thanks @Kimputer :-)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial