Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
| Search | Today's Posts | Mark Forums Read
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 3rd, 2004, 05:12 AM
Authorized User
Points: 236, Level: 4
Points: 236, Level: 4 Points: 236, Level: 4 Points: 236, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: Bucharest, , Romania.
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default Referencing an object from within a procedure

Hi,

I have several forms which each contain a similar Grid. I want to be able to process any such Grid with a single (public) Procedure, residing in the Main.bas module, instead of writing the same procedure again and again in each Form.

Question : is there a way of referencing an object belonging to, say, a Form, from within a procedure "implicitly" , AND NOT by calling it by its complete name ( Form99.Grid1.Row ) ?

The idea is that I would need an implicit variable/"pointer" to indicate the calling Form - similar, I think, to "Me". Then, I would be able to write something like

CallingForm.Flex1.Row = 2 etc, etc...

where "CallingForm" is the implicit "pointer" towards any of the forms which call the Procedure.

Thanks,

Mike




Reply With Quote
  #2 (permalink)  
Old February 3rd, 2004, 06:03 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

No, you cannot reference a form implicitly from within a module, but why can't you pass in the form instance (Me) as an argument to the module function?
Reply With Quote
  #3 (permalink)  
Old February 3rd, 2004, 07:25 AM
Authorized User
Points: 236, Level: 4
Points: 236, Level: 4 Points: 236, Level: 4 Points: 236, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: Bucharest, , Romania.
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The Function that processes the Form (and all other forms that call it) is not in the Form's code, but in a separate code module, where all public functions of the Project reside.

Reply With Quote
  #4 (permalink)  
Old February 3rd, 2004, 08:36 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Yes I understand that, what I mean is why can't you change the module functions from:
Public Function DoSomethingWithGrid(arg1, ..., argN)
to
Public Function DoSomethingWithGrid(theForm, arg1, ..., argN)
then when you call DoSomethingWithGrid just pass in 'Me' as the first argument.

(You could instead pass in a reference to the actual Grid object rather than its containing form - I think I prefer that...)

hth
Phil
Reply With Quote
  #5 (permalink)  
Old February 3rd, 2004, 09:08 AM
Authorized User
Points: 236, Level: 4
Points: 236, Level: 4 Points: 236, Level: 4 Points: 236, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: Bucharest, , Romania.
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default

OK, I tried it and it works ("theForm" variable of DoSomething... defined as type "object").

You can then reference it (theForm.Flex.Row... ) from within the function and change the calling form or the objects it contains.

Thanks


Reply With Quote
  #6 (permalink)  
Old February 3rd, 2004, 02:51 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Alameda, ca, USA.
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It is a bad idea to assume that the global procedure knows the name of the grid in the form you are passing. As you wrote, it works only if the form has a grid named 'Flex'.
Much safer to pass the grid itself:

Public sub DoGrid(grd as MSFlexGrid, ...)

and call it from your form with:

DoGrid Me.NameOfTheGrid

In this way you can reuse you main code and any form can rename their grids as needed without breaking the code.

Marco


Quote:
quote:Originally posted by mike123abc
 OK, I tried it and it works ("theForm" variable of DoSomething... defined as type "object").

You can then reference it (theForm.Flex.Row... ) from within the function and change the calling form or the objects it contains.

Thanks


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Number of variables referencing an Object Muyavil Java Basics 3 April 11th, 2009 11:02 PM
Referencing another field and more scandalous Access VBA 1 January 30th, 2007 09:28 AM
referencing an object in an edit item template dan195 ASP.NET 1.0 and 1.1 Basics 3 September 25th, 2006 07:15 AM
Referencing the object that invoked a method benr Classic ASP Professional 0 March 12th, 2006 01:55 PM
Stored Procedure/Command Object results differ John K. King Access VBA 0 November 20th, 2003 11:07 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.