DocAElstein
Banned user
- Joined
- May 24, 2014
- Messages
- 1,336
Call ByVal ByRef StrPtr Address Inconsistencies.. at my End!
Please Run a Code for me and post me the results in a reply to this thread .
Hi
Following on from this Thread
http://www.mrexcel.com/forum/excel-questions/917689-passing-array-class-byval-byref.html
_... I may be experiencing some inconsistencies due to my older computers and older Excel versions.
_. I have a code prepared below. If anyone has the time i would be grateful if they could copy the code to a spare code module, run the code for me, hit Ctrl G to get the Immediate Window up, then copy the results from the Immediate Window and paste those results in a reply to this thread.
_. I would be grateful if you could tell me what versions of XL you are using.
_ ( I am using PC only: XL 2003 ; XL 2007 ; and XL 2010 ) I would be interested in particular for results from Excel Versions above XL 2010. But also results from earlier versions would be OK for me to compare with my results.
_. Here is a typical set of Results one should get: ( This I got from running the code in XL 2007 )
12 Address main program-------StrPtr(x) 0
14 Address main program-------StrPtr(x) 367478348
16 Address main program-------StrPtr(x) 365693740
18 Address main program-------StrPtr(x) 0
30 Address main program-------StrPtr(x) 367478348
40 Address mySubByVal--------StrPtr(c) 365693740
50 Address mySubByVal--------StrPtr(c) 365694300
60 Address mySubByValcChange StrPtr(c) 365693740
70 Address mySubByValcChange StrPtr(c) 365693740
80 Address mySubByVal--------StrPtr(c) 365693740
90 Address main program-------StrPtr(x) 367478348
100 Address main program------StrPtr(x) 367478348
110 Address mySubByRef--------StrPtr(c) 367478348
120 Address main program------StrPtr(x) 367478348
130 Address mySubByRefcChange StrPtr(c) 367478348
140 Address mySubByRefcChange StrPtr(c) 367478788
150 Address main program------StrPtr(x) 365694300
160 Address main program------StrPtr(x) 365694300
170 Address mySubByRefcChange StrPtr(c) 365694300
180 Address main program------StrPtr(x) 367478348
190 Address main program------StrPtr(x) 367478348
200 Address mySubByRefcChange StrPtr(c) 367478348
210 Address mySubByVal--------StrPtr(c) 367478348
220 Address main program------StrPtr(x) 367478788
230 Address main program------StrPtr(x) 367478788
240 Address mySubByVal--------StrPtr(c) 365693740
250 Address mySubByVal--------StrPtr(c) 367478348
260 Address mySubByValcChange StrPtr(c) 365693740
270 Address mySubByValcChange StrPtr(c) 365693740
280 Address mySubByVal--------StrPtr(c) 365693740
300 Address mySubByRef--------StrPtr(c) 367478788
310 Address main program------StrPtr(x) 367478788
320 letting x = 111111
330 Address main program------StrPtr(x) 367478348
340 Address mySubByRef--------StrPtr(c) 367478348
350 Address main program------StrPtr(x) 367478348
360 Address mySubByRefcChange StrPtr(c) 367478348
370 Address main program------StrPtr(x) 367478788
_ ......
Here are the Code(s):
The code to run is the first
Sub TestByValByRefStrWonky()
There are 4 additional Sub Routines which it calls.
All codes are in the Code window below. All should be copied to any spare Normal Module or Sheet Code Module
_................................................
Many thanks in advance.
No Rush. - Anyone when you have the time ( the more the better!! )
Alan
Please Run a Code for me and post me the results in a reply to this thread .
Hi
Following on from this Thread
http://www.mrexcel.com/forum/excel-questions/917689-passing-array-class-byval-byref.html
_... I may be experiencing some inconsistencies due to my older computers and older Excel versions.
_. I have a code prepared below. If anyone has the time i would be grateful if they could copy the code to a spare code module, run the code for me, hit Ctrl G to get the Immediate Window up, then copy the results from the Immediate Window and paste those results in a reply to this thread.
_. I would be grateful if you could tell me what versions of XL you are using.
_ ( I am using PC only: XL 2003 ; XL 2007 ; and XL 2010 ) I would be interested in particular for results from Excel Versions above XL 2010. But also results from earlier versions would be OK for me to compare with my results.
_. Here is a typical set of Results one should get: ( This I got from running the code in XL 2007 )
12 Address main program-------StrPtr(x) 0
14 Address main program-------StrPtr(x) 367478348
16 Address main program-------StrPtr(x) 365693740
18 Address main program-------StrPtr(x) 0
30 Address main program-------StrPtr(x) 367478348
40 Address mySubByVal--------StrPtr(c) 365693740
50 Address mySubByVal--------StrPtr(c) 365694300
60 Address mySubByValcChange StrPtr(c) 365693740
70 Address mySubByValcChange StrPtr(c) 365693740
80 Address mySubByVal--------StrPtr(c) 365693740
90 Address main program-------StrPtr(x) 367478348
100 Address main program------StrPtr(x) 367478348
110 Address mySubByRef--------StrPtr(c) 367478348
120 Address main program------StrPtr(x) 367478348
130 Address mySubByRefcChange StrPtr(c) 367478348
140 Address mySubByRefcChange StrPtr(c) 367478788
150 Address main program------StrPtr(x) 365694300
160 Address main program------StrPtr(x) 365694300
170 Address mySubByRefcChange StrPtr(c) 365694300
180 Address main program------StrPtr(x) 367478348
190 Address main program------StrPtr(x) 367478348
200 Address mySubByRefcChange StrPtr(c) 367478348
210 Address mySubByVal--------StrPtr(c) 367478348
220 Address main program------StrPtr(x) 367478788
230 Address main program------StrPtr(x) 367478788
240 Address mySubByVal--------StrPtr(c) 365693740
250 Address mySubByVal--------StrPtr(c) 367478348
260 Address mySubByValcChange StrPtr(c) 365693740
270 Address mySubByValcChange StrPtr(c) 365693740
280 Address mySubByVal--------StrPtr(c) 365693740
300 Address mySubByRef--------StrPtr(c) 367478788
310 Address main program------StrPtr(x) 367478788
320 letting x = 111111
330 Address main program------StrPtr(x) 367478348
340 Address mySubByRef--------StrPtr(c) 367478348
350 Address main program------StrPtr(x) 367478348
360 Address mySubByRefcChange StrPtr(c) 367478348
370 Address main program------StrPtr(x) 367478788
_ ......
Here are the Code(s):
The code to run is the first
Sub TestByValByRefStrWonky()
There are 4 additional Sub Routines which it calls.
All codes are in the Code window below. All should be copied to any spare Normal Module or Sheet Code Module
Code:
[color=darkgreen]'[/color]
[color=blue]Sub[/color] TestByValByRefStrWonky() '
10 [color=blue]Dim[/color] x [color=blue]As[/color] [color=blue]String[/color] [color=darkgreen]'I am using this as a "pseudo" Global Variable. That is to say it has assigned a Pigeon Hole containing the Address where the String would be[/color]
11 [color=darkgreen]' "get the Address of variable".. maybe.... https://support.microsoft.com/en-us/kb/199824[/color]
12 Debug.Print " 12 Address main program-------StrPtr(x) " & StrPtr(x) [color=darkgreen]'I expect no Address yet[/color]
13 [color=blue]Let[/color] x = "qwer"
14 Debug.Print " 14 Address main program-------StrPtr(x) " & StrPtr(x) [color=darkgreen]' Bet it has an address now[/color]
15 [color=blue]Let[/color] x = ""
16 Debug.Print " 16 Address main program-------StrPtr(x) " & StrPtr(x) [color=darkgreen]' Might have another address now[/color]
17 [color=blue]Let[/color] x = vbNullString
18 Debug.Print " 18 Address main program-------StrPtr(x) " & StrPtr(x) [color=darkgreen]' Suspect it has no address again[/color]
20 [color=blue]Let[/color] x = "qwer"
30 Debug.Print " 30 Address main program-------StrPtr(x) " & StrPtr(x) [color=darkgreen]' Might have another address now, or the very first one as it is available[/color]
40 Debug.Print " 40 ";: [color=blue]Call[/color] mySubByVal(x) [color=darkgreen]'[/color]
50 Debug.Print " 50 ";: [color=blue]Call[/color] mySubByVal(x)
60 Debug.Print " 60 ";: [color=blue]Call[/color] mySubByValcChange(x)
70 Debug.Print " 70 ";: [color=blue]Call[/color] mySubByValcChange(x)
80 Debug.Print " 80 ";: [color=blue]Call[/color] mySubByVal(x)
90 Debug.Print " 90 Address main program-------StrPtr(x) " & StrPtr(x)
100 Debug.Print "100 Address main program------StrPtr(x) " & StrPtr(x)
110 Debug.Print "110 ";: [color=blue]Call[/color] mySubByRef(x)
120 Debug.Print "120 Address main program------StrPtr(x) " & StrPtr(x)
130 Debug.Print "130 ";: [color=blue]Call[/color] mySubByRefcChange(x)
140 Debug.Print "140 ";: [color=blue]Call[/color] mySubByRefcChange(x)
150 Debug.Print "150 Address main program------StrPtr(x) " & StrPtr(x)
160 Debug.Print "160 Address main program------StrPtr(x) " & StrPtr(x)
170 Debug.Print "170 ";: [color=blue]Call[/color] mySubByRefcChange(x)
180 Debug.Print "180 Address main program------StrPtr(x) " & StrPtr(x)
190 Debug.Print "190 Address main program------StrPtr(x) " & StrPtr(x)
200 Debug.Print "200 ";: [color=blue]Call[/color] mySubByRefcChange(x)
210 Debug.Print "210 ";: [color=blue]Call[/color] mySubByVal(x)
220 Debug.Print "220 Address main program------StrPtr(x) " & StrPtr(x)
230 Debug.Print "230 Address main program------StrPtr(x) " & StrPtr(x)
235
240 Debug.Print "240 ";: [color=blue]Call[/color] mySubByVal(x)
250 Debug.Print "250 ";: [color=blue]Call[/color] mySubByVal(x)
260 Debug.Print "260 ";: [color=blue]Call[/color] mySubByValcChange(x)
270 Debug.Print "270 ";: [color=blue]Call[/color] mySubByValcChange(x)
280 Debug.Print "280 ";: [color=blue]Call[/color] mySubByVal(x)
290
300 Debug.Print "300 ";: [color=blue]Call[/color] mySubByRef(x)
310 Debug.Print "310 Address main program------StrPtr(x) " & StrPtr(x)
320 Debug.Print "320 letting x = 111111": [color=blue]Let[/color] x = "111111"
330 Debug.Print "330 Address main program------StrPtr(x) " & StrPtr(x)
340 Debug.Print "340 ";: [color=blue]Call[/color] mySubByRef(x)
350 Debug.Print "350 Address main program------StrPtr(x) " & StrPtr(x)
360 Debug.Print "360 ";: [color=blue]Call[/color] mySubByRefcChange(x)
370 Debug.Print "370 Address main program------StrPtr(x) " & StrPtr(x)
[color=blue]End[/color] [color=blue]Sub[/color]
[color=darkgreen]'[/color]
'
[color=blue]Sub[/color] mySubByRef(ByRef c [color=blue]As[/color] [color=blue]String[/color])
Debug.Print "Address my[color=blue]Sub[/color]ByRef--------StrPtr(c) " & StrPtr(c)
[color=blue]End[/color] [color=blue]Sub[/color]
[color=darkgreen]'[/color]
Sub my[color=blue]Sub[/color]ByRefcChange(ByRef c [color=blue]As[/color] [color=blue]String[/color])
Debug.Print "Address my[color=blue]Sub[/color]ByRefcChange StrPtr(c) " & StrPtr(c)
c = "22"
[color=blue]End[/color] Sub
[color=darkgreen]'[/color]
[color=blue]Sub[/color] my[color=blue]Sub[/color]ByVal(ByVal c [color=blue]As[/color] [color=blue]String[/color])
Debug.Print "Address mySubByVal--------StrPtr(c) " & StrPtr(c)
[color=blue]End[/color] [color=blue]Sub[/color]
[color=darkgreen]'[/color]
Sub mySubByValcChange(ByVal c [color=blue]As[/color] [color=blue]String[/color])
Debug.Print "Address mySubByValcChange StrPtr(c) " & StrPtr(c)
c = "22"
[color=blue]End[/color] Sub
_................................................
Many thanks in advance.
No Rush. - Anyone when you have the time ( the more the better!! )
Alan