Re: Differences between VB6 and VB.Net causing problem
- From: "Bill McCarthy" <Bill@xxxxxxxxxxxxx>
- Date: Tue, 21 Oct 2008 12:02:07 +1100
Hi Schmidt,
I didn't test that code but I presume it forces a value into a boolean other than 0 or -1. This is the exact concept I was referring to. I showed Larry the same using CopyMemory, but I don't think he got it.
There's a couple of important things to understand:
(1) a boolean is not guaranteed to have any internal value. If it did it would make it tri-state. It's two states are 0 and non 0
(2) Never compare a Boolean to True. That's a bitwise operation that depends on the internal state which is not guaranteed
(3) The operators And, equality =, Or, XOr and Not are all bitwise. They are not boolean operators. The only boolean operator in VB6 is the CBool one.
(4) This one's for Larry. Bitwise operators require the types to be bitwise. In VB6 only byte, Integer and Long are bitwise numerics. You can't do bitwise operations directly on a Decimal type: a conversion, implicit or otherwise, is required to one of the bitwise types first.
(5) Also for Larry: True is 16 bit. Boolean is 16 bit.
"Schmidt" <sss@xxxxxxxxx> wrote in message news:%23u6am3wMJHA.5840@xxxxxxxxxxxxxxxxxxxxxxx
"Larry Serflaten" <serflaten@xxxxxxxxxxxxxx> schrieb im Newsbeitrag
news:OyJOFBpMJHA.3588@xxxxxxxxxxxxxxxxxxxxxxx
Suffice it to say, that in types other than Byte and String, -1
is the value stored when representing True.
To add some fun into the discussion... the above is 'True',
... and just to formulate it a bit "stronger":
Dont force a boolean compare or Bit-Op, if you cannot
be sure that the Variable really contains 0 or -1.
The following snippet shows, that you cannot even rely
on the content of VBs Boolean-Variables, to be *always*
0 or -1.
It came up some years ago in the german groups - I only
readjusted the example a bit, to be more comprehensible,
covering a (more or less) "realistic" scenario...
Option Explicit
Private Sub Form_Load()
If AppInitializeNeeded Then 'we don't have files in the App.Path
'so we should initialize
Debug.Print "Really... no Files there?"
Else 'proceed normally with your App
End If
End Sub
Function AppInitializeNeeded() As Boolean
Dim boolFilesFound As Boolean 'we rely on the cast on this variable
FilesExistInPath App.Path, boolFilesFound
AppInitializeNeeded = Not boolFilesFound
'just to shade some light on VBs misbehaviour...
'the result of that statement is really "funny" ;-)
Debug.Print CInt(boolFilesFound);
End Function
Sub FilesExistInPath(Path As String, VReturn As Variant)
Dim FileCount As Long
'Determine the FileCount in a DirLoop for example -
'here we only simulate the result, stored in a Long
FileCount = 3
'now we pass the result back in the ByRef-Param
VReturn = FileCount
End Sub
Olaf
.
- Follow-Ups:
- Re: Differences between VB6 and VB.Net causing problem
- From: Larry Serflaten
- Re: Differences between VB6 and VB.Net causing problem
- References:
- Differences between VB6 and VB.Net causing problem
- From: Howard G
- Re: Differences between VB6 and VB.Net causing problem
- From: Tom Shelton
- Re: Differences between VB6 and VB.Net causing problem
- From: expvb
- Re: Differences between VB6 and VB.Net causing problem
- From: Tom Shelton
- Re: Differences between VB6 and VB.Net causing problem
- From: Bill McCarthy
- Re: Differences between VB6 and VB.Net causing problem
- From: Larry Serflaten
- Re: Differences between VB6 and VB.Net causing problem
- From: Bill McCarthy
- Re: Differences between VB6 and VB.Net causing problem
- From: Larry Serflaten
- Re: Differences between VB6 and VB.Net causing problem
- From: Bill McCarthy
- Re: Differences between VB6 and VB.Net causing problem
- From: Larry Serflaten
- Re: Differences between VB6 and VB.Net causing problem
- From: Bill McCarthy
- Re: Differences between VB6 and VB.Net causing problem
- From: Larry Serflaten
- Re: Differences between VB6 and VB.Net causing problem
- From: Bill McCarthy
- Re: Differences between VB6 and VB.Net causing problem
- From: Larry Serflaten
- Re: Differences between VB6 and VB.Net causing problem
- From: Robert Morley
- Re: Differences between VB6 and VB.Net causing problem
- From: Larry Serflaten
- Re: Differences between VB6 and VB.Net causing problem
- From: Schmidt
- Differences between VB6 and VB.Net causing problem
- Prev by Date: Re: LargeHex function revisited
- Next by Date: Re: Add a context menu item to Windows Explorer (Win98) with VB6?
- Previous by thread: Re: Differences between VB6 and VB.Net causing problem
- Next by thread: Re: Differences between VB6 and VB.Net causing problem
- Index(es):
Relevant Pages
|