Board index » Visual Studio » vbNull and 0

vbNull and 0

Visual Studio258
When using API function for example:



Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd

As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long



should I use vbNull for wParam as below

rtn = SendMessage(x, WM_COPYDATA, vbNull, cds)



or 0

rtn = SendMessage(x, WM_COPYDATA, 0, cds)



Which will be the proper way?


-
 

Re:vbNull and 0

"Jack" <replyto@newsgroup>wrote in message

Quote
When using API function for example:



Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal

hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As

Any) As Long



should I use vbNull for wParam as below

rtn = SendMessage(x, WM_COPYDATA, vbNull, cds)



You should probably *never* use vbNull in an API call; it is a numeric value

which resolves to +1 and is usually not what you want. In some cases you

may want vbNullString but never vbNull.



Quote


or 0

rtn = SendMessage(x, WM_COPYDATA, 0, cds)



Which will be the proper way?



Using 0 there will pass "null" in the sense that the API call expects



--

Reply to the group so all can participate

VB.Net... just say "No"



-

Re:vbNull and 0

In this case, it makes no difference.



When passing a ByRef argument, Visual Basic actually passes the address of

the argument. In this case, vbNull can be used to pass an address of 0,

which normally indicates that the argument was not provided. But in this

case, wParam is declared as ByVal and so 0 would also pass a value of 0.



In this case, wParam is not generally associated with a reference (pointer,

ByRef arg, etc.) so I personally prefer 0.



--

Jonathan Wood

SoftCircuits

www.softcircuits.com">www.softcircuits.com

Available for consulting: www.softcircuits.com/jwood/resume.htm">www.softcircuits.com/jwood/resume.htm



"Jack" <replyto@newsgroup>wrote in message

Quote
When using API function for example:



Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd

As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long



should I use vbNull for wParam as below

rtn = SendMessage(x, WM_COPYDATA, vbNull, cds)



or 0

rtn = SendMessage(x, WM_COPYDATA, 0, cds)



Which will be the proper way?









-

Re:vbNull and 0

Jack <replyto@newsgroup>wrote:

Quote
When using API function for example:



Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd

As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long



should I use vbNull for wParam as below

rtn = SendMessage(x, WM_COPYDATA, vbNull, cds)



or 0

rtn = SendMessage(x, WM_COPYDATA, 0, cds)



Which will be the proper way?



Debug.Print vbNull



(IOW, never use that constant in an API call.)

--

[Microsoft Basic: 1976-2001, RIP]





-

Re:vbNull and 0

Jack wrote:

Quote


When using API function for example:



Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd

As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long



should I use vbNull for wParam as below

rtn = SendMessage(x, WM_COPYDATA, vbNull, cds)



or 0

rtn = SendMessage(x, WM_COPYDATA, 0, cds)



Which will be the proper way?





The ONLY thing you should ever use vbNull for

is to evaluate the returned value from a VarType() call.



Really - take a look at what it is. Put the cursor on "vbNull" and hit F2

if it doesn't come right up, enter "vbnull" in the search box.



You'll find this:



Const vbNull = 1

Member of VBA.VbVarType

Return value constant for VarType





That's it. That's ALL it's for.

ANY other use would lead to the kind of code which probably MISLED you

to think of using it.







Bob

-

Re:vbNull and 0

"Karl E. Peterson" <karl@mvps.org>wrote in message

<cut>

Quote
Debug.Print vbNull



(IOW, never use that constant in an API call.)



but it's such a great way to obfuscate the code! <g>



-

Re:vbNull and 0

Bob Butler <tiredofit@nospam.com>wrote:

Quote
"Karl E. Peterson" <karl@mvps.org>wrote in message

news:e4iFFp8UEHA.2692@TK2MSFTNGP09.phx.gbl

<cut>

>Debug.Print vbNull

>

>(IOW, never use that constant in an API call.)



but it's such a great way to obfuscate the code! <g>



And results! <bg>

--

[Microsoft Basic: 1976-2001, RIP]





-

Re:vbNull and 0

Thank you all.

I wonder, why anybody mentioned that 0 should be accompanied by &?

like in:

rtn = SendMessage(x, WM_COPYDATA, 0&, cds)



In my another thread about 0 and 0& Ken Halter pointed out that & forces vb

to supply 0 as a Long.

so I believe that 0 in API calls should be ALWAYS be accompanied by the

ampersand.

Is that correct?



"Jack" <replyto@newsgroup>wrote in message

Quote
When using API function for example:



Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd

As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long



should I use vbNull for wParam as below

rtn = SendMessage(x, WM_COPYDATA, vbNull, cds)



or 0

rtn = SendMessage(x, WM_COPYDATA, 0, cds)



Which will be the proper way?









-

Re:vbNull and 0

"Jack" <replyto@newsgroup>wrote in message

<cut>

Quote
In my another thread about 0 and 0& Ken Halter pointed out that &

forces vb to supply 0 as a Long.

so I believe that 0 in API calls should be ALWAYS be accompanied by

the ampersand.

Is that correct?

<cut>

>Declare Function SendMessage Lib "user32" Alias "SendMessageA"

>(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long,

>lParam As Any) As Long



You declared "ByVal wMsg As Long" which also forces the parameter to be 32

bits. Passing 0& won't hurt but in this case the end result is the same.



--

Reply to the group so all can participate

VB.Net... just say "No"



-

Re:vbNull and 0

Jack <replyto@newsgroup>wrote:

Quote
so I believe that 0 in API calls should be ALWAYS be accompanied by the

ampersand.

Is that correct?



Let's just call it a "good habit" and leave it at that? <G>

--

[Microsoft Basic: 1976-2001, RIP]





-

Re:vbNull and 0

"Karl E. Peterson" <karl@mvps.org>wrote in message

Quote
Bob Butler <tiredofit@nospam.com>wrote:

>"Karl E. Peterson" <karl@mvps.org>wrote in message

>news:e4iFFp8UEHA.2692@TK2MSFTNGP09.phx.gbl

><cut>

>>Debug.Print vbNull

>>

>>(IOW, never use that constant in an API call.)

>

>but it's such a great way to obfuscate the code! <g>



And results! <bg>



not necessarily.. anywhere you want +1 you can use it



x = Shell_NotifyIcon(vbNull, uInfo)



or use it as a multiplier:



x = GetUsername(sUser, vbNull * Len(sUser))



--

Reply to the group so all can participate

VB.Net... just say "No"



-

Re:vbNull and 0



"Jonathan Wood" <jwood@softcircuits.com>wrote in message

Quote
In this case, it makes no difference.



When passing a ByRef argument, Visual Basic actually passes the address of

the argument. In this case, vbNull can be used to pass an address of 0,

which normally indicates that the argument was not provided. But in this

case, wParam is declared as ByVal and so 0 would also pass a value of 0.



You might want to double-check your facts...and the value of the vbNull

constant (which is 1).



Mike







-

Re:vbNull and 0

Bob Butler <tiredofit@nospam.com>wrote:

Quote
"Karl E. Peterson" <karl@mvps.org>wrote in message

news:%23CBqTz8UEHA.3692@TK2MSFTNGP09.phx.gbl

>Bob Butler <tiredofit@nospam.com>wrote:

>>"Karl E. Peterson" <karl@mvps.org>wrote in message

>>news:e4iFFp8UEHA.2692@TK2MSFTNGP09.phx.gbl

>><cut>

>>>Debug.Print vbNull

>>>

>>>(IOW, never use that constant in an API call.)

>>

>>but it's such a great way to obfuscate the code! <g>

>

>And results! <bg>



not necessarily.. anywhere you want +1 you can use it



x = Shell_NotifyIcon(vbNull, uInfo)



or use it as a multiplier:



x = GetUsername(sUser, vbNull * Len(sUser))



LOL! So true...

--

[Microsoft Basic: 1976-2001, RIP]





-

Re:vbNull and 0

I was thinking of vbNullString. Sorry.



--

Jonathan Wood

SoftCircuits

www.softcircuits.com">www.softcircuits.com

Available for consulting: www.softcircuits.com/jwood/resume.htm">www.softcircuits.com/jwood/resume.htm



"MikeD" <nobody@nowhere.edu>wrote in message

Quote


"Jonathan Wood" <jwood@softcircuits.com>wrote in message

news:ucIgum8UEHA.4064@TK2MSFTNGP11.phx.gbl...

>In this case, it makes no difference.

>

>When passing a ByRef argument, Visual Basic actually passes the address

of

>the argument. In this case, vbNull can be used to pass an address of 0,

>which normally indicates that the argument was not provided. But in this

>case, wParam is declared as ByVal and so 0 would also pass a value of 0.



You might want to double-check your facts...and the value of the vbNull

constant (which is 1).



Mike











-