Problems with passing parameters by reference to a sub program 
Author Message
 Problems with passing parameters by reference to a sub program

 Hi all,

Excuse me for crossposting, but I have a problem I really want to be solved.

 At the moment I'm writing quite a large and complicated program using visual
 Basic.
 At a certain stage I want a set of sub procedures to calculate some values
and
 return them to the calling procedure via the parameter list.
 As far as I know (and according to the manual) this should be possible.
 However when I try to run the program I get an error message, claiming that
 the argument types don't match. This is strange because I pass a predefined
 integer variable to a sub which is defined to receive an integer parameter.
 This error message can be suppressed by passing the parameter by value. This
 still doesn't get me out of problems because I want to change the value of
the
 parameter and return it  to the calling procedure (this is called by
 reference, I believe). Another solution is declaring al the variables to be
 global, which isn't really favourable.

 The funny thing is that when I make a very small testing program using the
 example given by the help function for "Sub" this simply does work.

 Does anybody have any idea what might be the cause of my problem? Has it
 something to do with the size/complexity of my program? Or do I just make a
 very stupid mistake?

 Thanks in advance

 Ruud Dirksen

_______________________________________________________________

Ruud Dirksen
Faculteit Natuur- en Sterrenkunde, Universiteit van Amsterdam.
Valckeniersstraat 65-67
1018 XE  Amsterdam
tel: 020 525 5621

____________________________________________________________



Sat, 06 Dec 1997 03:00:00 GMT  
 Problems with passing parameters by reference to a sub program

Quote:

>Excuse me for crossposting, but I have a problem I really want to be solved.

I grant thee a full pardon. My opinion, however, means nothing.

Set BillsOpinion = Nothing

Quote:
>At a certain stage I want a set of sub procedures to calculate some values
>and return them to the calling procedure via the parameter list.
>However when I try to run the program I get an error message, claiming that
>the argument types don't match. This is strange because I pass a predefined
>integer variable to a sub which is defined to receive an integer parameter.
>This error message can be suppressed by passing the parameter by value. This
>still doesn't get me out of problems because I want to change the value of
>the parameter and return it  to the calling procedure (this is called by
>reference, I believe).

Make sure you're not passing a property. You can't pass an object property by
reference - you'll get your type mismatch error. You also can't pass a
function by reference.

    For example, the following is illegal in pass by reference:

    DoSomeSub Text1.Text

    As is this:

    DoSomeOtherSub Len(Text1.Text)

I ran into these problems when I first started programming VB. However, it may
be that this is not your problem. If it isn't, I apologize for wasting time
and bandwidth.

--
Bill Cernansky     | programming: n. The method used to convince



Sat, 06 Dec 1997 03:00:00 GMT  
 Problems with passing parameters by reference to a sub program

Quote:

>  Hi all,

> Excuse me for crossposting, but I have a problem I really want to be
solved.

>  At the moment I'm writing quite a large and complicated program using
visual
>  Basic.
>  At a certain stage I want a set of sub procedures to calculate some
values
> and
>  return them to the calling procedure via the parameter list.
>  As far as I know (and according to the manual) this should be possible.
>  However when I try to run the program I get an error message, claiming
that
>  the argument types don't match. This is strange because I pass a
predefined
>  integer variable to a sub which is defined to receive an integer
parameter.
>  This error message can be suppressed by passing the parameter by value.
This
>  still doesn't get me out of problems because I want to change the value
of
> the
>  parameter and return it  to the calling procedure (this is called by
>  reference, I believe). Another solution is declaring al the variables to
be
>  global, which isn't really favourable.

>  The funny thing is that when I make a very small testing program using
the
>  example given by the help function for "Sub" this simply does work.

>  Does anybody have any idea what might be the cause of my problem? Has it
>  something to do with the size/complexity of my program? Or do I just
make a
>  very stupid mistake?

>  Thanks in advance

>  Ruud Dirksen

If you include a snip of code, maybe we can the error...

Jens



Sat, 06 Dec 1997 03:00:00 GMT  
 Problems with passing parameters by reference to a sub program

Quote:

>Path: stc06.ctd.ornl.gov!fnnews.fnal.gov!uwm.edu!vixen.cso.uiuc.edu!howland.reston.ans.net!news.nic.surfnet.nl!news.sara.nl!phys.uva.nl!dirksen

>Newsgroups: comp.lang.basic.visual.3rdparty,comp.lang.basic.visual.misc
>Subject: Problems with passing parameters by reference to a sub program
>Date: Tue, 20 Jun 1995 15:21:19 GMT
>Organization: Van der Waals- Zeeman Lab. U.v.A.
>Lines: 43
>Distribution: world

>NNTP-Posting-Host: pc-ja104.phys.uva.nl
>X-Newsreader: Trumpet for Windows [Version 1.0 Rev A]
>Xref: stc06.ctd.ornl.gov comp.lang.basic.visual.3rdparty:5081 comp.lang.basic.visual.misc:22009
> Hi all,
>Excuse me for crossposting, but I have a problem I really want to be solved.
> At the moment I'm writing quite a large and complicated program using visual
> Basic.
> At a certain stage I want a set of sub procedures to calculate some values
>and
> return them to the calling procedure via the parameter list.
> As far as I know (and according to the manual) this should be possible.
> However when I try to run the program I get an error message, claiming that
> the argument types don't match. This is strange because I pass a predefined
> integer variable to a sub which is defined to receive an integer parameter.
> This error message can be suppressed by passing the parameter by value. This
> still doesn't get me out of problems because I want to change the value of
>the
> parameter and return it  to the calling procedure (this is called by
> reference, I believe). Another solution is declaring al the variables to be
> global, which isn't really favourable.
> The funny thing is that when I make a very small testing program using the
> example given by the help function for "Sub" this simply does work.
> Does anybody have any idea what might be the cause of my problem? Has it
> something to do with the size/complexity of my program? Or do I just make a
> very stupid mistake?
> Thanks in advance
> Ruud Dirksen
>_______________________________________________________________
>Ruud Dirksen
>Faculteit Natuur- en Sterrenkunde, Universiteit van Amsterdam.
>Valckeniersstraat 65-67
>1018 XE  Amsterdam
>tel: 020 525 5621

>____________________________________________________________

I have had problems problems passing parameters to subs which I, nor
anyone else I asked could solve.  In my case, the value was changed in the
function even though it wasn't supposed to be.  I can only assume that there
are some bugs in VB in this regard.

------------------------------------------------------

Chris Woodrow



Fri, 12 Dec 1997 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Problems passing DATE type parameter to sub report

2. Sub(V1): passed by value or by reference?

3. Sub(V1): passed by value or by reference?

4. Question on passing array parameters to VB.NET Sub/Function

5. Pass parameter to Sub Main() procedure

6. passing parameters to Sub Main

7. Pass parameter to Sub Main() procedure

8. Passing a userdocument as a parameter to a sub or function

9. Passing "Sub" as parameters

10. How pass parameter to sub repeort?

11. Passing a parameter to a sub-report?

12. how to pass parameter to Sub Report

 

 
Powered by phpBB® Forum Software