Passing array to form 
Author Message
 Passing array to form

Hello NG,

I have a form that displays a simple line graph with x- and y-axes.

Now the question is, what is the best way to pass the data to the form?

a) Define a global array?
b) Put the data in a string and pass it to the form with property let (and
in the form make an array again)
c) Define a property let with an array of unknown size (is this possible,
how?)
d) Just path a reference of the array to the form, like you do with subs (is
this possible, how?)

I should mention, that I use an array of a user defined type:

Public Type Coord
    x as single
    y as single
End Type

I do have a number of these forms, so I prefer an object orientated
solution.
help appreciated.

Gunter Schmidt



Sun, 11 Dec 2005 04:04:38 GMT  
 Passing array to form

Quote:

> Hello NG,

> I have a form that displays a simple line graph with x- and y-axes.

> Now the question is, what is the best way to pass the data to the form?

> a) Define a global array?
> b) Put the data in a string and pass it to the form with property let (and
> in the form make an array again)
> c) Define a property let with an array of unknown size (is this possible,
> how?)
> d) Just path a reference of the array to the form, like you do with subs (is
> this possible, how?)

I guess before I'd pick a solution, I wonder where the data come from
relative to the display form, are there multiple instances of the
generation of the data, and other details of how its structured now...

My personal coding style would be to try to make the data an array local
to the generation and pass it to the plotting form, but I don't have a
hard and fast rule agains "absolutely no globals" either, if they're
simpler in a given situation.  (But I wouldn't want a zillion little
global arrays{*filter*} around, either...) Another lesser question is how
big of an array are we talking of here...10's, 100s, 1000s, or bigger?

I'd avoid the array->string->array type of solutions like the plague
simply because I personally think its an abomination to futz around
w/data that way...



Sun, 11 Dec 2005 04:23:04 GMT  
 Passing array to form
On Tue, 24 Jun 2003 22:04:38 +0200, "Gunter Schmidt"

Quote:

>Hello NG,

>I have a form that displays a simple line graph with x- and y-axes.

>Now the question is, what is the best way to pass the data to the form?

>a) Define a global array?

No - that is disgusting - andone should never be disgusting
- without a good reason
Quote:
>b) Put the data in a string and pass it to the form with property let (and
>in the form make an array again)
Why ?
>c) Define a property let with an array of unknown size (is this possible,
>how?)

UBound, LBound - a Call instead of a property
( soddit - one I know oner can send other parameters into a property)
Quote:
>d) Just path a reference of the array to the form, like you do with subs (is
>this possible, how?)

Call the damn thing - the recipient just needs to get it ByVal
Quote:

>I should mention, that I use an array of a user defined type:

So - if Caller and Callee know about it - what is the problem
Quote:

>Public Type Coord
>    x as single
>    y as single
>End Type

>I do have a number of these forms, so I prefer an object orientated
>solution.

This looks horribly like 'homework'
- allbeit well presented
- if it is not 'homework' then type 'Friend' into VB and press [F1]
- (the UDTs obviously belong in a 'support' .bas module )
Quote:
>help appreciated.

>Gunter Schmidt



Sun, 11 Dec 2005 04:43:47 GMT  
 Passing array to form
My Mistake - change ByVal to ByRef

On Tue, 24 Jun 2003 20:43:47 +0000 (UTC),

Quote:

>On Tue, 24 Jun 2003 22:04:38 +0200, "Gunter Schmidt"

>>Hello NG,

>>I have a form that displays a simple line graph with x- and y-axes.

>>Now the question is, what is the best way to pass the data to the form?

>>a) Define a global array?
>No - that is disgusting - andone should never be disgusting
>- without a good reason
>>b) Put the data in a string and pass it to the form with property let (and
>>in the form make an array again)
>Why ?
>>c) Define a property let with an array of unknown size (is this possible,
>>how?)
>UBound, LBound - a Call instead of a property
>( soddit - one I know oner can send other parameters into a property)
>>d) Just path a reference of the array to the form, like you do with subs (is
>>this possible, how?)
>Call the damn thing - the recipient just needs to get it ByVal

>>I should mention, that I use an array of a user defined type:
>So - if Caller and Callee know about it - what is the problem

>>Public Type Coord
>>    x as single
>>    y as single
>>End Type

>>I do have a number of these forms, so I prefer an object orientated
>>solution.
>This looks horribly like 'homework'
>- allbeit well presented
>- if it is not 'homework' then type 'Friend' into VB and press [F1]
>- (the UDTs obviously belong in a 'support' .bas module )
>>help appreciated.

>>Gunter Schmidt



Sun, 11 Dec 2005 04:50:48 GMT  
 Passing array to form
VB6: Question remains: How do I pass an array of a user defined type (UDT)
from on form to another?
Details see below



Quote:
> On Tue, 24 Jun 2003 22:04:38 +0200, "Gunter Schmidt"

> >Hello NG,

> >I have a form that displays a simple line graph with x- and y-axes.

> >Now the question is, what is the best way to pass the data to the form?

> >a) Define a global array?
> No - that is disgusting - andone should never be disgusting
> - without a good reason
> >b) Put the data in a string and pass it to the form with property let
(and
> >in the form make an array again)
> Why ?

a) and b) are just possible workarounds.

Quote:
> >c) Define a property let with an array of unknown size (is this possible,
> >how?)
> UBound, LBound - a Call instead of a property
> ( soddit - one I know oner can send other parameters into a property)

I am sorry, I did not get your point here.
Do you mean, I should call a public function of that form?

Yes, I can pass an array() as long it is not a udt.

Quote:
> >d) Just path a reference of the array to the form, like you do with subs
(is
> >this possible, how?)
> Call the damn thing - the recipient just needs to get it ByRef

Call what??

Quote:

> >I should mention, that I use an array of a user defined type:
> So - if Caller and Callee know about it - what is the problem

> >Public Type Coord
> >    x as single
> >    y as single
> >End Type

> >I do have a number of these forms, so I prefer an object orientated
> >solution.
> This looks horribly like 'homework'
> - allbeit well presented
> - if it is not 'homework' then type 'Friend' into VB and press [F1]

Well it is not homework, just a hobby.
My (german) help states that I can use user defined types with property let
unless it is optional. The compiler says I can not.

Example:
 Public Property Let ArrayTest(MyArray() As MyType)
does not work, whereas
 Friend Property Let ArrayTest(MyArray() As MyType)
does work.

Same problem with subs.

I did not know about friend until you pointed it out.

BUT, friend does not help me, as it is not possible to call a friend sub
from another form, like in my case.

Question remains: How do I pass an array of a user defined type (UDT) from
on form to another?

Gunter Schmidt



Sun, 11 Dec 2005 06:09:45 GMT  
 Passing array to form

Quote:

> VB6: Question remains: How do I pass an array of a user defined type (UDT)
> from on form to another?

The Sub or Function defined on the forms need to be Friend, not Public,
in order to pass UDTs around.  It's just an OLE/COM/Automation thing.

' Module1

Option Compare Binary
Option Explicit: DefObj A-Z

Public Type Coord
  X As Single
  Y As Single
  Z As Single
End Type

Sub Main()
  Dim Stuff(1 To 10) As Coord
  Stuff(1).X = 1000: Stuff(1).Y = 1000
  Stuff(2).X = 1100: Stuff(2).Y = 666
  Stuff(3).X = 1200: Stuff(3).Y = 555
  Stuff(4).X = 2000: Stuff(4).Y = 0
  Form1.ShowCoords Stuff
End Sub

' Form1

Option Compare Binary
Option Explicit: DefObj A-Z

Friend Sub ShowCoords(Coords() As Coord, Optional ByVal OwnerForm As Form)

  If OwnerForm Is Nothing Then Show Else Show OwnerForm:=OwnerForm

  Cls

  Dim i As Long
  For i = LBound(Coords) To UBound(Coords)
    Me.Line -(Coords(i).X, Coords(i).Y), Coords(i).Z
  Next

  Form2.ShowCoords Coords, Me
End Sub

' Form2

Option Compare Binary
Option Explicit: DefObj A-Z

Friend Sub ShowCoords(Coords() As Coord, Optional ByVal OwnerForm As Form)

  If OwnerForm Is Nothing Then Show Else Show OwnerForm:=OwnerForm

  Cls

  Dim i As Long
  For i = LBound(Coords) To UBound(Coords)
    Print Coords(i).X; Coords(i).Y; Coords(i).Z
  Next

End Sub

--
Joe Foster <mailto:jlfoster%40znet.com>  "Regged" again? <http://www.xenu.net/>
WARNING: I cannot be held responsible for the above        They're   coming  to
because  my cats have  apparently  learned to type.        take me away, ha ha!



Sun, 11 Dec 2005 07:51:42 GMT  
 Passing array to form


Quote:
> Question remains: How do I pass an array of a user defined type (UDT) from
> on form to another?

What if you put the UDT declaration in a module and make it public?


Sun, 11 Dec 2005 14:08:36 GMT  
 Passing array to form


Quote:


> > Question remains: How do I pass an array of a user defined type (UDT)
from
> > on form to another?

> What if you put the UDT declaration in a module and make it public?

Nothing else I did.


Sun, 11 Dec 2005 14:50:48 GMT  
 Passing array to form




Quote:

> > VB6: Question remains: How do I pass an array of a user defined type
(UDT)
> > from on form to another?

> The Sub or Function defined on the forms need to be Friend, not Public,
> in order to pass UDTs around.  It's just an OLE/COM/Automation thing.

> ' Module1

> Option Compare Binary
> Option Explicit: DefObj A-Z

> Public Type Coord
>   X As Single
>   Y As Single
>   Z As Single
> End Type

> Sub Main()
>   Dim Stuff(1 To 10) As Coord
>   Stuff(1).X = 1000: Stuff(1).Y = 1000
>   Stuff(2).X = 1100: Stuff(2).Y = 666
>   Stuff(3).X = 1200: Stuff(3).Y = 555
>   Stuff(4).X = 2000: Stuff(4).Y = 0
>   Form1.ShowCoords Stuff
> End Sub

> ' Form1

> Option Compare Binary
> Option Explicit: DefObj A-Z

> Friend Sub ShowCoords(Coords() As Coord, Optional ByVal OwnerForm As Form)

>   If OwnerForm Is Nothing Then Show Else Show OwnerForm:=OwnerForm

>   Cls

>   Dim i As Long
>   For i = LBound(Coords) To UBound(Coords)
>     Me.Line -(Coords(i).X, Coords(i).Y), Coords(i).Z
>   Next

>   Form2.ShowCoords Coords, Me
> End Sub

> ' Form2

> Option Compare Binary
> Option Explicit: DefObj A-Z

> Friend Sub ShowCoords(Coords() As Coord, Optional ByVal OwnerForm As Form)

>   If OwnerForm Is Nothing Then Show Else Show OwnerForm:=OwnerForm

>   Cls

>   Dim i As Long
>   For i = LBound(Coords) To UBound(Coords)
>     Print Coords(i).X; Coords(i).Y; Coords(i).Z
>   Next

> End Sub

Thank you very much. This helped me to find my mistake.

What I did, was this (adapted to your example):

in Form1

Dim f as form
set f = new form2

f.ShowCoords Coords, Me
--- error ----

It must be

Dim f as form2 <---
set f = new form2

f.ShowCoords Coords, Me
--- working ----

Thanks, Joe.

Gunter Schmidt



Sun, 11 Dec 2005 16:24:39 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Passing dynamic array of custom type to form method from another form

2. Passing an array to another form

3. Question on passing string array between forms

4. pass array value to other form?

5. Passing an array between forms?

6. passing arrays using request.form

7. passing arrays from vb dll to vb form

8. Passing a UserDefined Array to a form

9. Passing array info to another form

10. Passing form and object array

11. Passing Dynamic Arrays from a class into a form procedure

12. Passing Arguments / Passing an Array

 

 
Powered by phpBB® Forum Software