Click to See Complete Forum and Search --> : [RESOLVED] VB2008 - How do I declare an object with a dynamically assigned name?


GarethD.Norris
August 16th, 2008, 04:18 AM
Hi All,

I have just taken the leap from VB6 to VB2008 and am not finding it too bad but I have now come across a scenario which has got me stumped:

I am trying to declare an object with the name dynamically assigned from the contents of the string as per the example below:


Public Shared Function Launch_Session(ByVal Session_Path As String, ByVal Session_File As String) As Boolean

Dim Session_File.Value As Object

' Do other things here


End Function I am not even sure if this is possible but I need some way of using the same code to generate multiple objects based on the parameters sent to the function. I need to do this to use each of the objects created independently.

Any idea on how to get this working or an alternative solution?

Thanks,
Gareth.

GarethD.Norris
August 16th, 2008, 06:18 AM
Hi All,

I found a way to do what i needed. I just use the functions return value to send the object details back to the function call as shown below:

Form1.vb Form Code:

MySession1 = Attachmate_Extra.Session_Integration.Launch_Session("C:\Temp\", "one.edp")

Attachmate_Extra.vb Class Code:

Public Shared Function Launch_Session(ByVal Session_Path As String, ByVal Session_File As String) As Object


' Code to create the object i want and copy that object to the Launch_Session object so i can differentiate.


Return Launch_Session

If i make a second call to the Attachmate_Extra class from the form with a different session as below:

MySession2 = Attachmate_Extra.Session_Integration.Launch_Session("C:\Temp\", "two.edp")

I can then use a specific object by referencing to it as part of the call as below:

SendKeys_Result = Attachmate_Extra.Session_Integration.SendKeys_To_Session(MySession1, "The keys i want to send")

This sends the object to use to the function (In the Attachmate_Extra.vb class) as below:

Public Shared Function SendKeys_To_Session(ByVal Session_To_Use As Object, ByVal Keys_To_Send As String, Optional By Val Wait_Time As Short = 200) As Boolean

Not really along the lines of what i was asking but as i dont think it is actually possible to do the way i wanted this may be of use to others,

Gareth.