Page 1 of 1

Updating list of objects (not their values)

Posted: Sat May 11, 2013 4:34 pm
by Obiekt
Hi,
Is it possible to fill a list with for example:
Code: Select all
a = "string"
b = 42
c = True
(displaying the list would show "string 42 True")
...and have it actually update as the variables change? For example, if you changed a to "another string" it would update in the list as well (as it doesn't if you just add a, b and c at the start, you add their values not the variables themselves)? I know/think it can be done with classes but i don't want to have a different class for all of my variables.

I would use it so I'd add variables to a list, and then their values would be displayed during a "debug mode" (and I am aware of all the visual studio ways i can see what value they hold, i want it IN my program).

Thanks in advance!

Re: Updating list of objects (not their values)

Posted: Sat May 11, 2013 8:13 pm
by mandai
You may find it useful to put the variables in a List object. This would let you add, remove, change, and access each item.
There are some samples here: http://msdn.microsoft.com/en-us/library ... S.95).aspx

Re: Updating list of objects (not their values)

Posted: Sat May 11, 2013 10:06 pm
by Obiekt
Thank you for your reply, though this might not be what i'm after.
As far as I'm aware, if you add A (A="string123") to a list (of string) and later change A (to, for example "str000"), there will still be initial value in the list. It would my guess that you only add A's value into the list so the two aren't in any way linked.
I could do this by having a class, put it's instance in a list and then change it's property A.

What i'm asking is, is there any way to link A and the list, so you could dumb a bunch of variables - not their values - (preferably different types) in a list.

Re: Updating list of objects (not their values)

Posted: Sat May 11, 2013 10:36 pm
by smashapps
Maybe you could use something like:
Code: Select all
Dim a = "string"
        Dim b = 42
        Dim c = True
        Dim d As String = a & " " & b & " " & c
        MsgBox(d)
d will say: "string 42 True" and you can change the values at anyway and just use d again.

Re: Updating list of objects (not their values)

Posted: Sat May 11, 2013 11:35 pm
by Obiekt
Let me clarify the thing by explaining it's purpose:

I'm making a little game. I also have an overlay-thing-class that displays values of certain variables in-game.
I could of course make variables public or something and add the code into overlay so it would check them and display their values.

BUT. I was wondering, if i quickly wanted to know x&y of something, i would write something like "debug_queue.add(variable)"
and the overlay thing would periodically go over this list and display the current variable values, even if they were changed at runtime/later/after adding them in.

I'm sorry for not making it clear at first, and it may just be that such a thing is not doable, but if it is, I do think it would be a nice feature. It may seem a bit contrived, but with the system i currently have it would be perfect.

Re: Updating list of objects (not their values)

Posted: Sun May 12, 2013 12:16 am
by smashapps
I'm trying to figure out what you want I am a little confused sorry i didn't read your thread properly

So you don't want their values you want their their type?
Code: Select all
Dim a As String = "string"
        Dim b As Integer = 42
        Dim c As Boolean = True

        If VarType(a) = vbString Then
            MsgBox("a IS a string")
        End If
        If VarType(b) = vbInteger Then
            MsgBox("b IS an integer")
        End If
        If VarType(c) = vbBoolean Then
            MsgBox("c IS a boolean")
        End If
That can be used to check if they are a certain type if might be easier to do it over Skype call or Teamviewer, if you want to do that feel free to message me the details. Sorry if I am not being much help

Re: Updating list of objects (not their values)

Posted: Sun May 12, 2013 9:58 am
by Obiekt
While writing my reply for the second time (pressed backspace outside of textbox, got screwed over)
I have concluded that what I'm after cannot be done, and neither can my examples.

We could go over it on Skype/TW if you want (note I have CET time), including my current game thing but
for now I'll mark this thread as closed, and a pointless wasting of your time ;)