| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | VB6 ByRef problem |
Hi everyone,
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.
Calling code is:
Option Explicit
Public Const Mutation_Rate As Double = 0.001
a$ =
"000000000000000000000000000000000000000000000000000000000000000000000000000
00000"
For i = 1 To 10000
DoEvents
mutate (a$): Debug.Print a$
Next i
Sub is:
Public Sub mutate(ByRef bits As String)
Dim i As Integer
For i = 1 To Len(bits)
If Rnd < Mutation_Rate Then
If Mid(bits, i, 1) = "1" Then
Mid(bits, i, 1) = "0"
Else
Mid(bits, i, 1) = "1"
End If
End If
Next i
End Sub
Running in Debug with a breakpoint set on the assignment to "1":
Mid(bits, i, 1) = "1"
shows that the 'bits' string is being modified, but a$ in the main procedure
just stays at 80 zeros.
Any hints?
Thanks,
Andrew
---
þ 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™.