4 Replies - 23232 Views - Last Post: 15 August 2006 - 11:18 AM Rate Topic: -----

#1 the_hangman  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 14
  • View blog
  • Posts: 602
  • Joined: 18-January 06

Dynamic Variables Or Objects

Posted 19 July 2006 - 10:36 AM

Ok I think I figured out how to create dynamic variable names or objects. A while ago I had asked about this and I believe it was amadeus who gave me some references. I needed a variable that I could use to create a loop through objects so as not to have to write a code over 52 times.

well I discovered today a way that helped me loop a similar code through 4 objects without having to code all 4.
Dim VariableHere As System.Object


Then I wrote a code assigning VariableHere a string ie:("X" + "1")
Later when I needed the object name "X1" I just used VariableHere instead and it worked!

Is this something that might be useful or is this something that everyone already knew and I'm just not as much of a retard as I thought?

Is This A Good Question/Topic? 0
  • +

Replies To: Dynamic Variables Or Objects

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Dynamic Variables Or Objects

Posted 19 July 2006 - 10:49 AM

Well, I doubt that everyone knew it, and it is extremely good information. As you may remember from our previous conversation, the CreateObject method was one that was suggested...the system.Object class is the .NET extension of that method. I'm afraid we did not reccomend it at the time as we were working with VB6.

Excellent solution.
Was This Post Helpful? 0
  • +
  • -

#3 the_hangman  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 14
  • View blog
  • Posts: 602
  • Joined: 18-January 06

Re: Dynamic Variables Or Objects

Posted 19 July 2006 - 11:09 AM

I see, I see...

Well here is one thing that I am running into. I need to call the function that performs this with 4 different buttons. Vb 2005 Express automates the code and for some reason I can only get the first button to work. I tried this:
Private Sub Mem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Mem1.Click, Mem2.Click, Mem3.Click, Mem4.Click

but I don't think it works... Is there a way to write one sub that handles all 4 buttons?


P.S. nvm, I figured this out.

This post has been edited by the_hangman: 26 July 2006 - 10:56 AM

Was This Post Helpful? 0
  • +
  • -

#4 the_hangman  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 14
  • View blog
  • Posts: 602
  • Joined: 18-January 06

Re: Dynamic Variables Or Objects

Posted 26 July 2006 - 10:56 AM

Ok my thing here worked just fine for the last application, but it won't work on this one. I keep ketting errors from "textbox" is not a number so you can't add counter to it, to .Text is not a property of Type String (meaning that grouper is coming through as a string and not an object..

Anyone see anything wrong??

Dim Counter = 0
	Dim Grouper As System.Object

	Public Sub Arrayer()
		While Counter < 100
			Grouper = "TextBox" + Counter
			Grouper.Text = 5
			Counter = Counter + 1
		End While
	End Sub

Was This Post Helpful? 0
  • +
  • -

#5 the_hangman  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 14
  • View blog
  • Posts: 602
  • Joined: 18-January 06

Re: Dynamic Variables Or Objects

Posted 15 August 2006 - 11:18 AM

The answer here was I needed to have Grouper = "TextBox" + Counter.ToString
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1