TIP: Click on subject to list as thread! ANSI
echo: visual_basic
to: All
from: Rick Rothstein
date: 2004-06-22 17:16:00
subject: Re: VB6 ByRef problem

> This is probably one that's staring me in the face, but I cannot get
it to
> work.  I have a Sub with string passed ByRef, but changes made to the
string
> inside the Sub don't affect the string passed, which they definitely
should.

Actually, the problem is a subtle one...


>   a$ =
>
"00000000000000000000000000000000000000000000000000000000000000000000000
0000
> 00000"
>   For i = 1 To 10000
>     DoEvents
>     mutate (a$): Debug.Print a$
>   Next i

See those parentheses you have around the a$ variable? Either add the
keyword "Call" in front of the "mutate" Sub's name or remove the
parentheses. In VB, the syntax for a Sub is

     Call YourSubName(Argument)

or

     YourSubName Argument

The problem is that when you use parentheses that are not part of the
syntax for a statement, VB **evaluates** the contents of the parentheses
(even if no calculation is required)... what is getting passed to your
Sub, and being changed by your Sub, is the temporary address in memory
where the evaluation is taking place at and NOT your variable's address
in memory. Adhere to one of the two proper syntaxes for a call to a Sub
and your problem will disappear.

Rick - MVP
---
þ RIMEGate(tm)/RGXPost V1.14 at BBSWORLD * Info{at}bbsworld.com

---
 * RIMEGate(tm)V10.2áÿ* RelayNet(tm) NNTP Gateway * MoonDog BBS
 * RgateImp.MoonDog.BBS at 6/22/04 5:16:00 PM
* Origin: MoonDog BBS, Brooklyn,NY, 718 692-2498, 1:278/230 (1:278/230)
SEEN-BY: 633/267 270
@PATH: 278/230 10/345 106/1 2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.