[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

BeeJ

4/9/2012 12:29:00 AM

I tried asking this before but it got lost in the other parts of the
previous post.

I am not asking about frmWhatEver.Name

If I
Public fWhatever As frmWhatever

then someplace instantiate it

Set fWhatever = New frmWhatever

While in fWhatEver object how do I find its name fWhatEver?
And no, I do not want to set a string to fWhatever and pass to
fWhatever in a Property Let.

Is there not a way to just get the name the object was assigned?

and to complicate it more

if I do
Public fWhatEver(0 to 1) as frmWhatEver
Set fWhatEver(0) = New frmWhatEver

How would I get the index while in fWhatever object?

Is there some API call that does all of that?

--
Noah's Ark was built by amateurs,
The Titanic was built by professionals.
Row, row, row your boat gently down the stream ...
Life is but a dream!


13 Answers

ralph

4/9/2012 3:47:00 AM

0

On Sun, 08 Apr 2012 17:29:08 -0700, BeeJ <nospam@spamnot.com> wrote:

>I tried asking this before but it got lost in the other parts of the
>previous post.
>
>I am not asking about frmWhatEver.Name
>
>If I
> Public fWhatever As frmWhatever
>
>then someplace instantiate it
>
> Set fWhatever = New frmWhatever
>
>While in fWhatEver object how do I find its name fWhatEver?
>And no, I do not want to set a string to fWhatever and pass to
>fWhatever in a Property Let.
>
>Is there not a way to just get the name the object was assigned?
>
>and to complicate it more
>
>if I do
> Public fWhatEver(0 to 1) as frmWhatEver
> Set fWhatEver(0) = New frmWhatEver
>
>How would I get the index while in fWhatever object?
>
>Is there some API call that does all of that?

No.
If you want to record this information then you will have to
instrument it yourself.

-ralph

unknown

4/9/2012 4:31:00 AM

0

"BeeJ" <nospam@spamnot.com> wrote in message
news:jltagk$np8$1@speranza.aioe.org...
>I tried asking this before but it got lost in the other parts of the
>previous post.
>
> I am not asking about frmWhatEver.Name
>
> If I
> Public fWhatever As frmWhatever
>
> then someplace instantiate it
>
> Set fWhatever = New frmWhatever
>
> While in fWhatEver object how do I find its name fWhatEver?
> And no, I do not want to set a string to fWhatever and pass to fWhatever
> in a Property Let.
>
> Is there not a way to just get the name the object was assigned?
>
> and to complicate it more
>
> if I do
> Public fWhatEver(0 to 1) as frmWhatEver
> Set fWhatEver(0) = New frmWhatEver
>
> How would I get the index while in fWhatever object?
>
> Is there some API call that does all of that?

That doesn't seem to be a good design, but you could do this:

Public Type TMyForms
frm As Form
WhatsThisFormFor As String
End Type

Public fWhatEver(0 to 1) As TMyForms


Larry Serflaten

4/9/2012 9:57:00 AM

0

BeeJ wrote:

> Is there not a way to just get the name the object was assigned?

No, and to understand why, try thinking on a smaller scale:

Sub Form_Load()
Dim Foo As Long, Bar As Long
Foo = Rnd * 100
Bar = Rnd * 100
DoSomething Foo
End Sub

Sub DoSomething(FooBar As Long)
' How can you tell the name of the passed variable?
End Sub


Code running in the DoSomething sub has no way to know which
variable was passed, Foo, or Bar. Do you know why?

LFS

BeeJ

4/9/2012 2:18:00 PM

0

In this case passed by reference so if VB6 had been implemented in such a
way, the reference could have had included that info if the variable name
had been "included". But since it is a simple variable it really is not
worth it so the language does not do it. Also if it had been passed by
ByVal the value would be on the stack and the language would be extra busy
passing the "name" all the time making the language inefficient.
However an object is a more substantial (can't think of a better term) thing
so that it would be a good thing to have its "name" handy.
Think of a variable or other object. At some level we can get at the Type
of variable and Type of control.
So why not the assigned / retain the name of the instantiated?
Anyway I am hearing that the language does not do what I want.
What else am I missing?


Jeff Johnson [MVP: VB]

4/9/2012 3:03:00 PM

0



"BeeJ" wrote in message news:jltagk$np8$1@speranza.aioe.org...

> Public fWhatever As frmWhatever

> then someplace instantiate it

> Set fWhatever = New frmWhatever

> While in fWhatEver object how do I find its name fWhatEver?

That's not the name of the object; it's the name of a variable, and it's
only there for your human eyes and the compiler. In other words, it's a
one-way street. You know what fWhatEver is and what it's used for. fWhatEver
can "see" frmWhatever. frmWhatever cannot "see" that it has been assigned to
fWhatEver.

Here's the real question: Why do you care? Why do you want to do this?

ralph

4/9/2012 5:33:00 PM

0

On Mon, 9 Apr 2012 07:18:21 -0700, "BeeJ" <nospam@spamnot.com> wrote:

>In this case passed by reference so if VB6 had been implemented in such a
>way, the reference could have had included that info if the variable name
>had been "included". But since it is a simple variable it really is not
>worth it so the language does not do it. Also if it had been passed by
>ByVal the value would be on the stack and the language would be extra busy
>passing the "name" all the time making the language inefficient.
>However an object is a more substantial (can't think of a better term) thing
>so that it would be a good thing to have its "name" handy.

A Variable name is simply a symbol to identify a particular block of
memory. It only exists within the scope and context of the programming
language that uses Variables. I can't think of a single instance where
keeping its "name" handly outside of that context would be useful.

>Think of a variable or other object. At some level we can get at the Type
>of variable and Type of control.
>So why not the assigned / retain the name of the instantiated?
>Anyway I am hearing that the language does not do what I want.
>What else am I missing?

Nothing but perhaps what it is you seem to want to do is not worth
doing.

-ralph

Larry Serflaten

4/9/2012 7:46:00 PM

0

BeeJ wrote:

> But since it is a simple variable it really is not
> worth it so the language does not do it.

And there really is no need...


> However an object is a more substantial (can't think of a better term) thing
> so that it would be a good thing to have its "name" handy.

The object may be substantial, but you are still using a standard
variable to interact with it in your program.


> Think of a variable or other object. At some level we can get at the Type
> of variable and Type of control.
> So why not the assigned / retain the name of the instantiated?
> Anyway I am hearing that the language does not do what I want.
> What else am I missing?

Computers work with data in memory. The variables you declare are
actually pointers to some specific memory location. That location
may hold a value, or a pointer to some other location. The executable
code doesn't need to know what you call your variables, it only needs
to know where in memory you are storing your values. Remember, the
computer only works on/with numbers in memory.

All that effort you put in to properly naming your variables,
doesn't get included in the compiled code.... :-)

LFS

unknown

4/10/2012 12:20:00 AM

0

"BeeJ" <nospam@spamnot.com> wrote in message
news:jlur31$i2c$1@speranza.aioe.org...
> At some level we can get at the Type of variable and Type of control.

Here is another alternative: Add Form1, Form2, Module1 to a new project, and
set the Startup object to Sub Main, then add this code to Module1:

Option Explicit

' Late bound, we don't know which
' type of Form this refers to
Dim f As Object

Public Sub Main()

Set f = New Form2

If TypeOf f Is Form Then
Debug.Print "f is Form"
End If
If TypeOf f Is Form1 Then
Debug.Print "f is Form1"
End If
If TypeOf f Is Form2 Then
Debug.Print "f is Form2"
End If

Set f = Nothing

End Sub


Output:

f is Form
f is Form2



BeeJ

4/10/2012 12:43:00 AM

0

I am trying to find a universal way to identify an object.
Specifically in the current case, the instantiated name of the form.

The language is missing an important capability.

In the form unload event of a form that was Set I would like to have
something like
Set Me.Instance = Nothing

to remove the form from memory.

All the work arounds require specific cases unique to the way the form
is instantiated.

--
Noah's Ark was built by amateurs,
The Titanic was built by professionals.
Row, row, row your boat gently down the stream ...
Life is but a dream!


Karl E. Peterson

4/10/2012 12:54:00 AM

0

BeeJ expressed precisely :
> I am trying to find a universal way to identify an object.

ObjPtr()

> Specifically in the current case, the instantiated name of the form.

Stuff it in the Tag, if it matters that much. Or create a new public
property.

> The language is missing an important capability.

You too can overcome your limitations.

> In the form unload event of a form that was Set I would like to have
> something like
> Set Me.Instance = Nothing
>
> to remove the form from memory.
>
> All the work arounds require specific cases unique to the way the form is
> instantiated.

There's no need to do that. You're looking for trouble. And,
apparently, with much success!

--
..NET: It's About Trust!
http://vfre...