passing TYPE Variables 
Author Message
 passing TYPE Variables

Hi all;

Is it possible to pass a structure type of variable to onclick  events?
for example
type Details
myname as string * 32
myaddress as string * 60
end type

sub getDetails()
    dt as Details
    dt.myname = "what ever"
    dt.myaddress = "what ever address"
end sub

The above TYPE variable is place at the top with the modules global
declaration section.  Which I would have thought would be available to all
the functions and sub within the module.

I already know through my experience with `C` that the dot operator works,
but it doesn't seem to keep hold of the data that is assigned to the
individual parts. When pass looked at in another function.  When I was to do
the same thing with a `C` function as a pointer the data would still be
there to be operated on.

I am relatively new to vbs so any comment or help would be appreciated.

Ta in advance

ChrisMc



Thu, 23 Jan 2003 03:00:00 GMT  
 passing TYPE Variables
VBScript 5.0 and higher *does* support classes though...

Class Details
    Public myname
    Public myaddress
end Class

sub getDetails()
    set dt = new Details
    dt.myname = "what ever"
    dt.myaddress = "what ever address"
    ...
    ..
    ..
end sub

--
Michael Harris
Microsoft MVP - Scripting

Quote:



> I don't think VBS supports UDTs as in Type ... End Type, Also does not
> support As keyword in declarations, so your fixed length strings are out as
> well. Now regular VBA supports what you are trying, just not VBS. Consider
> some sort of array

> >Hi all;

> >Is it possible to pass a structure type of variable to onclick  events?
> >for example
> >type Details
> >myname as string * 32
> >myaddress as string * 60
> >end type

> >sub getDetails()
> >    dt as Details
> >    dt.myname = "what ever"
> >    dt.myaddress = "what ever address"
> >end sub

> >The above TYPE variable is place at the top with the modules global
> >declaration section.  Which I would have thought would be available to all
> >the functions and sub within the module.

> >I already know through my experience with `C` that the dot operator works,
> >but it doesn't seem to keep hold of the data that is assigned to the
> >individual parts. When pass looked at in another function.  When I was to do
> >the same thing with a `C` function as a pointer the data would still be
> >there to be operated on.

> >I am relatively new to vbs so any comment or help would be appreciated.

> >Ta in advance

> >ChrisMc



Thu, 23 Jan 2003 03:00:00 GMT  
 passing TYPE Variables


I don't think VBS supports UDTs as in Type ... End Type, Also does not
support As keyword in declarations, so your fixed length strings are out as
well. Now regular VBA supports what you are trying, just not VBS. Consider
some sort of array

Quote:
>Hi all;

>Is it possible to pass a structure type of variable to onclick  events?
>for example
>type Details
>myname as string * 32
>myaddress as string * 60
>end type

>sub getDetails()
>    dt as Details
>    dt.myname = "what ever"
>    dt.myaddress = "what ever address"
>end sub

>The above TYPE variable is place at the top with the modules global
>declaration section.  Which I would have thought would be available to all
>the functions and sub within the module.

>I already know through my experience with `C` that the dot operator works,
>but it doesn't seem to keep hold of the data that is assigned to the
>individual parts. When pass looked at in another function.  When I was to do
>the same thing with a `C` function as a pointer the data would still be
>there to be operated on.

>I am relatively new to vbs so any comment or help would be appreciated.

>Ta in advance

>ChrisMc



Fri, 24 Jan 2003 03:00:00 GMT  
 passing TYPE Variables
Hi Rico;

Thank for your in put.

I didn't explain correctly.  What I was trying to do was create a global
variable that would I though be able to pass details from a form to various
function.  There to be worked on and then on return, the new values be
processed in to a excel spreadsheet.

The above process it seem to be to complex so I scraped the idea, and went
for a more fundamental route.  Cutting it short I re wrote the whole {*filter*}y
thing.

Quote:


> I don't think VBS supports UDTs as in Type ... End Type, Also does not
> support As keyword in declarations, so your fixed length strings are out
as
> well. Now regular VBA supports what you are trying, just not VBS. Consider
> some sort of array

> >Hi all;

> >Is it possible to pass a structure type of variable to onclick  events?
> >for example
> >type Details
> >myname as string * 32
> >myaddress as string * 60
> >end type

> >sub getDetails()
> >    dt as Details
> >    dt.myname = "what ever"
> >    dt.myaddress = "what ever address"
> >end sub

> >The above TYPE variable is place at the top with the modules global
> >declaration section.  Which I would have thought would be available to
all
> >the functions and sub within the module.

> >I already know through my experience with `C` that the dot operator
works,
> >but it doesn't seem to keep hold of the data that is assigned to the
> >individual parts. When pass looked at in another function.  When I was to
do
> >the same thing with a `C` function as a pointer the data would still be
> >there to be operated on.

> >I am relatively new to vbs so any comment or help would be appreciated.

> >Ta in advance

> >ChrisMc



Fri, 24 Jan 2003 03:00:00 GMT  
 passing TYPE Variables
Hi Michael;


Quote:
> VBScript 5.0 and higher *does* support classes though...

> Class Details
>     Public myname
>     Public myaddress
> end Class

> sub getDetails()
>     set dt = new Details
>     dt.myname = "what ever"
>     dt.myaddress = "what ever address"
>     ...
>     ..
>     ..
> end sub

Thanks for the help.  The part that I had missed, totally, was the set dt in
my earier example.

I you read the reply I made to Rico.  You will see that I went back to the
roots.

Quote:
> --
> Michael Harris
> Microsoft MVP - Scripting




- Show quoted text -

Quote:

McCorry"

> > I don't think VBS supports UDTs as in Type ... End Type, Also does not
> > support As keyword in declarations, so your fixed length strings are out
as
> > well. Now regular VBA supports what you are trying, just not VBS.
Consider
> > some sort of array

> > >Hi all;

> > >Is it possible to pass a structure type of variable to onclick  events?
> > >for example
> > >type Details
> > >myname as string * 32
> > >myaddress as string * 60
> > >end type

> > >sub getDetails()
> > >    dt as Details
> > >    dt.myname = "what ever"
> > >    dt.myaddress = "what ever address"
> > >end sub

> > >The above TYPE variable is place at the top with the modules global
> > >declaration section.  Which I would have thought would be available to
all
> > >the functions and sub within the module.

> > >I already know through my experience with `C` that the dot operator
works,
> > >but it doesn't seem to keep hold of the data that is assigned to the
> > >individual parts. When pass looked at in another function.  When I was
to do
> > >the same thing with a `C` function as a pointer the data would still be
> > >there to be operated on.

> > >I am relatively new to vbs so any comment or help would be appreciated.

> > >Ta in advance

> > >ChrisMc



Fri, 24 Jan 2003 03:00:00 GMT  
 passing TYPE Variables
Hi Michael;

Sorry to trouble you again.  But does vbs have any method of using pointers
as in `C` and `C++` and here comes the dumb question. Is it possible to have
user type variables as detailed below public?  As when I tried it in a excel
spread sheet it didn't work.  I always had to make them private.  Am I
missing something fundamental?


Quote:
> VBScript 5.0 and higher *does* support classes though...

> Class Details
>     Public myname
>     Public myaddress
> end Class

> sub getDetails()
>     set dt = new Details
>     dt.myname = "what ever"
>     dt.myaddress = "what ever address"
>     ...
>     ..
>     ..
> end sub

> --
> Michael Harris
> Microsoft MVP - Scripting




- Show quoted text -

Quote:

McCorry"

> > I don't think VBS supports UDTs as in Type ... End Type, Also does not
> > support As keyword in declarations, so your fixed length strings are out
as
> > well. Now regular VBA supports what you are trying, just not VBS.
Consider
> > some sort of array

> > >Hi all;

> > >Is it possible to pass a structure type of variable to onclick  events?
> > >for example
> > >type Details
> > >myname as string * 32
> > >myaddress as string * 60
> > >end type

> > >sub getDetails()
> > >    dt as Details
> > >    dt.myname = "what ever"
> > >    dt.myaddress = "what ever address"
> > >end sub

> > >The above TYPE variable is place at the top with the modules global
> > >declaration section.  Which I would have thought would be available to
all
> > >the functions and sub within the module.

> > >I already know through my experience with `C` that the dot operator
works,
> > >but it doesn't seem to keep hold of the data that is assigned to the
> > >individual parts. When pass looked at in another function.  When I was
to do
> > >the same thing with a `C` function as a pointer the data would still be
> > >there to be operated on.

> > >I am relatively new to vbs so any comment or help would be appreciated.

> > >Ta in advance

> > >ChrisMc



Sat, 25 Jan 2003 03:00:00 GMT  
 passing TYPE Variables
<...brief pause while loading the magic gun with silver bullets...>

No, VBScript (thankfully) doesn't do pointers...  I'd hate to think what kinds of questions/problems
we'd see in the NGs if it did!!!

--
Michael Harris
Microsoft MVP - Scripting



Sat, 25 Jan 2003 03:00:00 GMT  
 passing TYPE Variables
uh, wait.  Isn't "GetRef" a pointer to a subroutine?

to quote the doc: "In other scripting and programming languages, the
functionality provided by GetRef is referred to as a function pointer, that
is, it points to the address of a procedure to be executed when the
specified event occurs".

cheers, jw


Quote:
> <...brief pause while loading the magic gun with silver bullets...>

> No, VBScript (thankfully) doesn't do pointers...  I'd hate to think what

kinds of questions/problems
Quote:
> we'd see in the NGs if it did!!!

> --
> Michael Harris
> Microsoft MVP - Scripting



Mon, 27 Jan 2003 03:00:00 GMT  
 passing TYPE Variables
The docs say "In other languages [...] the functionality provided by GetRef is referred to as a
function pointer [...]", not that it IS a function pointer.  <Emphasis on "the functionality
provided"...>

GetRef builds (on the fly) and returns an IDispatchEx object.  Here's the full contents of a
3/23/1999 post from Eric Lippert on the subject of GetRef().

For those who don't know who Eric is, he's a member of the MS Scripting Dev team that makes all of
this stuff work <g>!  I assume he's been *way* too busy lately to post in the NGs (but probably not
too busy to lurk ;-)...

======================================================
Re: what do I mean by "first class functions"?

We language designers call a particular entity "first class" if it can be
manipulated like any other data.  An excellent example is functions in
JScript.  In JScript, functions are objects.  They can be passed around,
printed out, modified, stuck into local variables, etc:

Example:

function square(x) { return x * x; }

var s;
s = square;  // this does NOT call square.  square is an object.
alert(square(5)); // 25
alert(s(6)); // 36

See, in JScript there is a difference between

x = square;  // assign the function to x.

and

x = square();  // call the function, assign the return value to x.

Or, for another example, functions are first class in C++.  You can obtain a
pointer to a function and pass it around like data.  But classes are not
first class.  In C++ you CAN'T say

class foo {};
x = foo;
y = new x;

In C++, functions are first class but classes are second class.  In Dylan,
functions and classes are first class.

In VBScript, neither functions nor classes are first class.  In VBScript:

function square(x) : square = x * x : end function
dim s
s = square(5) ' 25
s = square  ' error, expected argument - functions are not first class

There is no way to pass a function around -- the only thing you can do to
functions in VBScript is _call_ them.

Now, this deficiency is a real pain in IE.  In JScript, people do this kind
of thing all the time:

function click() { /* what ever */ }
button1.onclick = click;

That assigns the function click to the button's event handler.  When the
button is clicked, IE calls the function.  It would be nice if you could do
this from VBScript, but VBScript doesn't have first class functions.  So we
added a little hack to allow this.  In V5 you can say

function click
    ' whatever
end function

set button1.onclick = GetRef("click")

What GetRef does is it looks up the string "click" in the global name table
and sees if it resolves to a function.  If it does, it constructs an object
whose default method is to call the named function.  It then returns that
object, which is assigned to the button property.  (Internally, this is
exactly what JScript is doing -- in JScript, functions are implemented as
objects whose default method is to call the object.  But JScript constructs
the function objects when the script starts up, whereas VBScript constructs
them only on-the-fly when requested by GetRef.  This is because constructing
all those objects is _expensive_ -- since we can get away with not doing it
in VBScript, we do.)

Eric
======================================================

--
Michael Harris
MVP Scripting


uh, wait.  Isn't "GetRef" a pointer to a subroutine?

to quote the doc: "In other scripting and programming languages, the
functionality provided by GetRef is referred to as a function pointer, that
is, it points to the address of a procedure to be executed when the
specified event occurs".

cheers, jw


Quote:
> <...brief pause while loading the magic gun with silver bullets...>

> No, VBScript (thankfully) doesn't do pointers...  I'd hate to think what

kinds of questions/problems
Quote:
> we'd see in the NGs if it did!!!

> --
> Michael Harris
> Microsoft MVP - Scripting



Mon, 27 Jan 2003 03:00:00 GMT  
 passing TYPE Variables
hi Michael,

thanks for the clarification.

I didn't read the documentation carefully enough.  I should have known that
"functionality provided by... " was not the same as "IS".    As we learned
last year (courtesy of WJC), it all depends on what the meaning of "IS"
is...

cheers, jw


Quote:
> The docs say "In other languages [...] the functionality provided by

GetRef is referred to as a
Quote:
> function pointer [...]", not that it IS a function pointer.  <Emphasis on
"the functionality
> provided"...>



Mon, 27 Jan 2003 03:00:00 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. How to pass Date type variable to a custom ActiveX component

2. Passing a variable type parameter to an .asp file

3. Type problem: passing variables to methods

4. passing "type" variables HELP plz

5. Help with passing user defined types as variables in functions - VB4 32bit

6. Largest Variable for the Long variable type

7. Type mismatch when comparing session variable to page variable

8. passing javascript variable into asp variable using vbscript

9. Pass client script variable to server script variable

10. Passing Javascript Variables to VBscript (ASP) Variables

11. The value of a variable (String type) is the name of a variable

12. Cannot assign a variable declared as a string to a variable declared as data type

 

 
Powered by phpBB® Forum Software