Link to home
Start Free TrialLog in
Avatar of Thor Vestaberg
Thor Vestaberg

asked on

Create Array to String(,)

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(*,*)
ASKER CERTIFIED SOLUTION
Avatar of Kimputer
Kimputer

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,
How the data from database looks like?
Avatar of Thor Vestaberg
Thor Vestaberg

ASKER

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
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
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.
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
@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)
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()
Thanks @Kimputer :-)