Call ByVal ByRef StrPtr Address Inconsistencies.. at my End! Please Run a Code for me.

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




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
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Here you go: Excel 2010, Win 7 64 Machine...


12 Address main program-------StrPtr(x) 0
14 Address main program-------StrPtr(x) 137798364
16 Address main program-------StrPtr(x) 137911900
18 Address main program-------StrPtr(x) 0
30 Address main program-------StrPtr(x) 137911860
40 Address mySubByVal--------StrPtr(c) 137798364
50 Address mySubByVal--------StrPtr(c) 137798340
60 Address mySubByValcChange StrPtr(c) 137798364
70 Address mySubByValcChange StrPtr(c) 137798364
80 Address mySubByVal--------StrPtr(c) 137798364
90 Address main program-------StrPtr(x) 137911860
100 Address main program------StrPtr(x) 137911860
110 Address mySubByRef--------StrPtr(c) 137911860
120 Address main program------StrPtr(x) 137911860
130 Address mySubByRefcChange StrPtr(c) 137911860
140 Address mySubByRefcChange StrPtr(c) 137798340
150 Address main program------StrPtr(x) 137911900
160 Address main program------StrPtr(x) 137911900
170 Address mySubByRefcChange StrPtr(c) 137911900
180 Address main program------StrPtr(x) 137798340
190 Address main program------StrPtr(x) 137798340
200 Address mySubByRefcChange StrPtr(c) 137798340
210 Address mySubByVal--------StrPtr(c) 137798340
220 Address main program------StrPtr(x) 137911860
230 Address main program------StrPtr(x) 137911860
240 Address mySubByVal--------StrPtr(c) 137798364
250 Address mySubByVal--------StrPtr(c) 137798340
260 Address mySubByValcChange StrPtr(c) 137798364
270 Address mySubByValcChange StrPtr(c) 137798364
280 Address mySubByVal--------StrPtr(c) 137798364
300 Address mySubByRef--------StrPtr(c) 137911860
310 Address main program------StrPtr(x) 137911860
320 letting x = 111111
330 Address main program------StrPtr(x) 137911900
340 Address mySubByRef--------StrPtr(c) 137911900
350 Address main program------StrPtr(x) 137911900
360 Address mySubByRefcChange StrPtr(c) 137911900
370 Address main program------StrPtr(x) 137798340




igold
 
Upvote 0
Excel 2011 Mac OSx 10.9.5

12 Address main program-------StrPtr(x) 0
14 Address main program-------StrPtr(x) 2073574484
16 Address main program-------StrPtr(x) 2019668340
18 Address main program-------StrPtr(x) 0
30 Address main program-------StrPtr(x) 2074868852
40 Address mySubByVal--------StrPtr(c) 2073645908
50 Address mySubByVal--------StrPtr(c) 2073645908
60 Address mySubByValcChange StrPtr(c) 2073645908
70 Address mySubByValcChange StrPtr(c) 2073645908
80 Address mySubByVal--------StrPtr(c) 2073645908
90 Address main program-------StrPtr(x) 2074868852
100 Address main program------StrPtr(x) 2074868852
110 Address mySubByRef--------StrPtr(c) 2074868852
120 Address main program------StrPtr(x) 2074868852
130 Address mySubByRefcChange StrPtr(c) 2074868852
140 Address mySubByRefcChange StrPtr(c) 2073645908
150 Address main program------StrPtr(x) 2074868852
160 Address main program------StrPtr(x) 2074868852
170 Address mySubByRefcChange StrPtr(c) 2074868852
180 Address main program------StrPtr(x) 2073645908
190 Address main program------StrPtr(x) 2073645908
200 Address mySubByRefcChange StrPtr(c) 2073645908
210 Address mySubByVal--------StrPtr(c) 2073645908
220 Address main program------StrPtr(x) 2074868852
230 Address main program------StrPtr(x) 2074868852
240 Address mySubByVal--------StrPtr(c) 2073645908
250 Address mySubByVal--------StrPtr(c) 2073645908
260 Address mySubByValcChange StrPtr(c) 2073645908
270 Address mySubByValcChange StrPtr(c) 2073645908
280 Address mySubByVal--------StrPtr(c) 2073645908
300 Address mySubByRef--------StrPtr(c) 2074868852
310 Address main program------StrPtr(x) 2074868852
320 letting x = 111111
330 Address main program------StrPtr(x) 2074925812
340 Address mySubByRef--------StrPtr(c) 2074925812
350 Address main program------StrPtr(x) 2074925812
360 Address mySubByRefcChange StrPtr(c) 2074925812
370 Address main program------StrPtr(x) 2073645908
 
Upvote 0
Hi
Just a quick bump to ask if anyone has the time to do the run for me requested in Post #1 . It would be helpful to have a greater spread of results from different XL versions and different computer systems.
Anytime, no rush
Many thank
s again
Alan





















_ .............................
P.s.
While i am here this may be a convenient place to make an in-between conclusion, for future reference

Igold Excel 2010, Win 7 64 Machine
Mostly ties up with my results.
Minor difference: Line 30 - second time around a string variable was given a new StrPtr() address. ( my computer used the one from last time ( first time ) around, presumably it was available in time )
_...............................................
mikerickson Excel 2011 Mac OSx 10.9.5
Identical results to Igold
_......................................................
Alan Various repeated test in 2003 2007 2010, various computers
In different computer and versions is rill get identical consistent results, only differing from Igold and mikerickson in line 30. Repeatedly my old slow equipment appears to have freed up the first used address again. Maybe something more subtle??
_ .................................................................

Notes: Summary of the experiments going in the referred to Thread.
http://www.mrexcel.com/forum/excel-questions/917689-passing-array-class-byval-byref.html

_. Basically i am trying to get a clear understanding of the difference in passing arrays ByVal and ByRef, and in doing so being a bit more precise in how really VBA really handles variables.
Finally some attempt is made to clear up the question of if / how / why an Array may or may not only be called ByRef ( For the case of Callable SubProcedures ). I talk about the two differences in terms of “ORefviginal” and “CopVy / CopVyS” _.....___

_... so...Just some of my terminology there.
_ . ORefviginal ___ A Variable Declaration ( In this example a String Type ) . Declared within the Main Procedure . It is referred to ( VBA is pointed to ) its Pigeon Hole, which contains appropriate info ( start address if any, length information, if any ) . This Pointer is what is referenced when the Variable ORefviginal is encountered by VBA within a Callable Sub Procedure when the variable ORefviginal is given in the calling line to a Callable Sub Procedure of the type that contains the qualifier of ByRef within the brackets in its shignature line.
( I could use this actual word, ORefviginal, for fun, as an appropriate word for that Variable in the Declaration Line )

_. CopVy / CopVyS ____ When I use this word I am talking about any ( there could be more than one ) copy of the variable, that is to say in this as we believe, I believe, a ByVal call on the ORefviginal Presumably again some Pigeon Hole pointer is assigned to each of these Copies, allowing for more than one held in some “stack” of variables in a process such as recursion. In other words with CopVy I am talking about what is made / what happens when the variable ORefviginal is given in the calling line to a Callable Sub Procedure of the type that contains the qualifier of ByVal within the brackets in its shignature line.
( if i use the word CopVy I am talking about one or more “words”, or rather “identifying pointer” somewhere held by VBA whichIt presumably uses to know where to point in each instance )

My experiments , I believe, are returning me not the Pigeon Hole location ( which in absence of a better understanding I believe is the Pointed to location, and i believe may not ever change ), but rather it is returning me the start location given within that Pigeon Hole referring to where any created actual string is held.
This address would appear to be very volatile and inconsistent.

Thank you once again.
Alan
 
Upvote 0
Hi Alan.
Windows 10, Excel 2013 8GB RAM.

12 Address main program-------StrPtr(x) 0
14 Address main program-------StrPtr(x) 483394300
16 Address main program-------StrPtr(x) 482841084
18 Address main program-------StrPtr(x) 0
30 Address main program-------StrPtr(x) 483394300
40 Address mySubByVal--------StrPtr(c) 482841084
50 Address mySubByVal--------StrPtr(c) 482840916
60 Address mySubByValcChange StrPtr(c) 482841084
70 Address mySubByValcChange StrPtr(c) 482841084
80 Address mySubByVal--------StrPtr(c) 482841084
90 Address main program-------StrPtr(x) 483394300
100 Address main program------StrPtr(x) 483394300
110 Address mySubByRef--------StrPtr(c) 483394300
120 Address main program------StrPtr(x) 483394300
130 Address mySubByRefcChange StrPtr(c) 483394300
140 Address mySubByRefcChange StrPtr(c) 482840916
150 Address main program------StrPtr(x) 521554812
160 Address main program------StrPtr(x) 521554812
170 Address mySubByRefcChange StrPtr(c) 521554812
180 Address main program------StrPtr(x) 482840916
190 Address main program------StrPtr(x) 482840916
200 Address mySubByRefcChange StrPtr(c) 482840916
210 Address mySubByVal--------StrPtr(c) 482840916
220 Address main program------StrPtr(x) 483394300
230 Address main program------StrPtr(x) 483394300
240 Address mySubByVal--------StrPtr(c) 482841084
250 Address mySubByVal--------StrPtr(c) 482840916
260 Address mySubByValcChange StrPtr(c) 482841084
270 Address mySubByValcChange StrPtr(c) 482841084
280 Address mySubByVal--------StrPtr(c) 482841084
300 Address mySubByRef--------StrPtr(c) 483394300
310 Address main program------StrPtr(x) 483394300
320 letting x = 111111
330 Address main program------StrPtr(x) 521554812
340 Address mySubByRef--------StrPtr(c) 521554812
350 Address main program------StrPtr(x) 521554812
360 Address mySubByRefcChange StrPtr(c) 521554812
370 Address main program------StrPtr(x) 482840916
 
Upvote 0
Hi RickXL,
Thanks very much
This time your results are identical to mine. ( The only ones so far, but the two from the other two members were also very similar, just the one minor difference at the start ( Line 30 ) where yours and mine re-used a cleared address, and presumably there systems were not quite ready, that is to say the variable had not been cleared ). But your results are much different to yours before. It is all suggesting that the address used in the “Pigeon Hole” “pointed to” for the original ByRef ( “ My so called “ORefviginal“ Variable ) also can vary. ( I do not mean the Pigion Hole varies , but the address therein of where the actual variable is ( or rather may start ! ) )
I was back in that other Thread a bit, and may in a day or two pop back a last time and summarise some things, for prosperity!
Thanks again for all your help and advice
Alan

EDIT
P.s. Just noticed a PM from Yous as well, thanks.
 
Last edited:
Upvote 0
Hello

Hi just a quick note, in the Spirit of the Forum Rules to say that i have posted a similar request to the one in this Thread here, just now
Call ByVal ByRef StrPtr Address. Please Run a Code for me and post me the results.


This is just to get possibly a few more results.
Thanks again for all the help from here. Much appreciated.

Alan

P.s. Does anyone know a code that will give you the basic brief details of the computer you are using? I could add that to save a bit of time in the future for anyone helping. ( I found a bit to get the Excel version )

P.P.s For anyone else stumbling across this and has the time to help, the original request is in Post#1 – Basically i was asking for you to run a code for me and paste the results from the immediate Window into a Reply to this thread.
_ ..Either use the code Sub TestByValByRefStrWonky() from Post #1 as explained there, or alternatively my newest version here below.
( Note as before, the first code should be run, ( in the new code Sub TestByValByRefStrPtrTiddlyFoo() ) but all the codes should be copied to the same module as the first code calls the other codes
. Thanks again for any new additions, Alan )



Code:
[color=darkgreen]'[/color]
[color=blue]Sub[/color] TestByValByRefStrPtrTiddlyFoo() '
2   Debug.Print "Using " & ExcelVersion & ""
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 Ads. where the String would be[/color]
11   [color=darkgreen]'   "get the Ads. of variable"..  maybe....  https://support.microsoft.com/en-us/kb/199824[/color]
12  Debug.Print " 12 Ads. main program-~~~~-"; Tab(30); "StrPtr(x) " & StrPtr(x) [color=darkgreen]'I expect no Ads. yet[/color]
13  [color=blue]Let[/color] x = "qwer"
14  Debug.Print " 14 Ads. main program-~~~~-"; Tab(30); "StrPtr(x) " & StrPtr(x) [color=darkgreen]' Bet it has an Ads. now[/color]
15  [color=blue]Let[/color] x = ""
16  Debug.Print " 16 Ads. main program-~~~~-"; Tab(30); "StrPtr(x) " & StrPtr(x) [color=darkgreen]' Might have another Ads. now[/color]
17  [color=blue]Let[/color] x = vbNullString
18  Debug.Print " 18 Ads. main program-~~~~-"; Tab(30); "StrPtr(x) " & StrPtr(x) [color=darkgreen]' Suspect it has no Ads. again[/color]
20  [color=blue]Let[/color] x = "qwer"
30  Debug.Print " 30 Ads. main program-~~~~-"; Tab(30); "StrPtr(x) " & StrPtr(x) [color=darkgreen]' Might have another Ads. 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 Ads. main program-~~~~-"; Tab(30); "StrPtr(x) " & StrPtr(x)
100 Debug.Print "100 Ads. main program-~~~~"; Tab(30); "StrPtr(x) " & StrPtr(x)
110 Debug.Print "110 ";: [color=blue]Call[/color] mySubByRef(x)
120 Debug.Print "120 Ads. main program-~~~~"; Tab(30); "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 Ads. main program-~~~~"; Tab(30); "StrPtr(x) " & StrPtr(x)
160 Debug.Print "160 Ads. main program-~~~~"; Tab(30); "StrPtr(x) " & StrPtr(x)
170 Debug.Print "170 ";: [color=blue]Call[/color] mySubByRefcChange(x)
180 Debug.Print "180 Ads. main program-~~~~"; Tab(30); "StrPtr(x) " & StrPtr(x)
190 Debug.Print "190 Ads. main program-~~~~"; Tab(30); "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 Ads. main program-~~~~"; Tab(30); "StrPtr(x) " & StrPtr(x)
230 Debug.Print "230 Ads. main program-~~~~"; Tab(30); "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 Ads. main program-~~~~"; Tab(30); "StrPtr(x) " & StrPtr(x)
320 Debug.Print "320 " & vbTab & " letting "; Tab; "  x = 111111": [color=blue]Let[/color] x = "111111"
330 Debug.Print "330 Ads. main program-~~~~"; Tab(30); "StrPtr(x) " & StrPtr(x)
340 Debug.Print "340 ";: [color=blue]Call[/color] mySubByRef(x)
350 Debug.Print "350 Ads. main program-~~~~"; Tab(30); "StrPtr(x) " & StrPtr(x)
360 Debug.Print "360 ";: [color=blue]Call[/color] mySubByRefcChange(x)
370 Debug.Print "370 Ads. main program-~~~~"; Tab(30); "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 "Ads. my[color=blue]Sub[/color]ByRef-~~~~--"; Tab(30); "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 "Ads. my[color=blue]Sub[/color]ByRefcChange "; Tab(30); "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 "Ads. mySubByVal-~~~~--"; Tab(30); "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 "Ads. mySubByValcChange "; Tab(30); "StrPtr(c) " & StrPtr(C)
    C = "22"
[color=blue]End[/color] Sub
[color=darkgreen]'[/color]
'
Rem 'Ref
' http://www.mrexcel.com/forum/excel-questions/918015-call-byval-byref-strptr-address-inconsistencies-my-end-please-run-code-me.html
[color=darkgreen]' http://www.mrexcel.com/forum/excel-questions/919174-debug-print-comma-vs-semicolon.html[/color]
[color=darkgreen]'[/color]
[color=blue]Function[/color] ExcelVersion() [color=blue]As[/color] [color=blue]String[/color] 'Stole From Rory's Tools. Code is in module mCreateHTML   , bottom page Klick on Link underlined in blue "here." at thoos blog site:  http://excelmatters.com/excel-forums/
    [color=darkgreen]'On Error Resume Next[/color]
#[color=blue]If[/color] Mac [color=blue]Then[/color] [color=darkgreen]'# I think means do at complie time. In any case this code will not work without it[/color]
    [color=blue]Select[/color] [color=blue]Case[/color] Val(Application.Version)
        [color=blue]Case[/color] 11: ExcelVersion = "XL 2004"
        [color=blue]Case[/color] 12: ExcelVersion = "XL 2008" [color=darkgreen]' this should NEVER happen![/color]
        [color=blue]Case[/color] 14: ExcelVersion = "XL 2011"
        [color=blue]Case[/color] 15: ExcelVersion = "XL Version maybe newest"
        [color=blue]Case[/color] Else: ExcelVersion = "Unknown"
    [color=blue]End[/color] [color=blue]Select[/color]
#[color=blue]Else[/color]
    [color=blue]Select[/color] [color=blue]Case[/color] Val(Application.Version)
        [color=blue]Case[/color] 9: ExcelVersion = "Excel 2000"
        [color=blue]Case[/color] 10: ExcelVersion = "Excel 2002"
        [color=blue]Case[/color] 11: ExcelVersion = "Excel 2003"
        [color=blue]Case[/color] 12: ExcelVersion = "Excel 2007"
        [color=blue]Case[/color] 14: ExcelVersion = "Excel 2010"
        [color=blue]Case[/color] 15: ExcelVersion = "Excel 2013"
        [color=blue]Case[/color] Else: ExcelVersion = "Not XL 2000 2002 2003 2007 2010 2013 2004 ( 2008 ) 2011"
    [color=blue]End[/color] [color=blue]Select[/color]
#[color=blue]End[/color] [color=blue]If[/color]
[color=darkgreen]'Let ExcelVersion = temp[/color]
[color=blue]End[/color] [color=blue]Function[/color]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,527
Messages
6,114,150
Members
448,552
Latest member
WORKINGWITHNOLEADER

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top