Array Convertion

Do you need something made? then ask in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
5 posts Page 1 of 1
Contributors
User avatar
muttley1968
Hardcore Programmer
Hardcore Programmer
Posts: 622
Joined: Thu Jun 17, 2010 11:54 pm

Array Convertion
muttley1968
hello Im building a program that is retrieving a lot of info in the form of
array lists but I am finding it hard to find a nice clean low code way of
converting these lists into

Strings for a textbox
Items for a listbox
text for labels

That type of thing so I was wondering if anyone would be able to either comment how or better yet make a full tut on array lists as well before this program I barley used them and when I did it was to save data and never open it in program again :(

And pluss that code was googled so I didn't really understand much just bits
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4389
Joined: Tue Aug 04, 2009 1:47 am

Re: Array Convertion
CodenStuff
A list of strings is fairly straight forward...

Create a list:
Code: Select all
Dim SomeList As New List(Of String)
Add item(s) to list:
Code: Select all
SomeList.Add("bob")
Go through the list and add items to listbox example:
Code: Select all
For Each item As String In SomeList
    ListBox1.Items.Add(item)
Next
If that's what you're looking for lol cooll;
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
muttley1968
Hardcore Programmer
Hardcore Programmer
Posts: 622
Joined: Thu Jun 17, 2010 11:54 pm

Re: Array Convertion
muttley1968
Thank you but it dose not work maybe I can try and explain my self a little better by showing the code :)

I am using JSONAPI To try and make a minecraft control client for servers hosted on websites
now I need to use a method in the config that with the following name and calls ect..
Code: Select all
		
{
			"name":"getPlayerNames",
			"desc":"Retrieves an array of the names of all the players currently on the server.",
			"returns":["String[]", "The players' names."],
			"call":"this.getPlayerNames()"
		},
now I am trying to use the follow code to retrieve this information (edited to add updates from codenstuff)
Code: Select all
        Dim result As Dictionary(Of Object, Object) = j.[call]("getPlayerNames", arr)
        Dim SomeList As New List(Of String)

            For Each item In result.ToString
                SomeList.Add(item)
            Next
        For Each item As String In SomeList
            If ListBox1.Items.Contains(item) Then
            Else
                ListBox1.Items.Add(item)
            End If
        Next
but this returns the following in listbox form
S
Y
S
T
E
M

C
O
L
E
C
T
I
O
N
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4389
Joined: Tue Aug 04, 2009 1:47 am

Re: Array Convertion
CodenStuff
Erm yes I have no idea at this point :lol:

You should probably be using a proper Json class to parse all this data but maybe this will work, I pieced this together from the github code:
Code: Select all
        Dim result As New Dictionary(Of Object, Object) = j.[call]("getPlayerNames", arr)
        For Each o As Object In result
            For Each key As Object In DirectCast(o, String).Values
                ListBox1.Items.Add(Convert.ToString(key))
            Next
        Next
My experience with parsing json data isn't a whole lot so I'm not sure :?

Maybe someone else will know how to use this JSONAPI thing effectively cooll;
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
muttley1968
Hardcore Programmer
Hardcore Programmer
Posts: 622
Joined: Thu Jun 17, 2010 11:54 pm

Re: Array Convertion
muttley1968
Thank you and I understand im in the same boat right now
They should make the support for vb a lot better tbh but their we go :)

Anyway that code looks a lot better but I get this error
Unable to cast object of type 'System.Collections.Generic.KeyValuePair`2[System.Object,System.Object]' to type 'System.String'.
5 posts Page 1 of 1
Return to “Tutorial Requests”