Re: Differences between VB6 and VB.Net causing problem




"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


.



Relevant Pages

  • Re: A little challenge for relativists.
    ... The Moon is 1.2 light seconds from Earth, ... > Dim redfirst As Boolean, bluefirst As Boolean, bluesecond As ... > Private Sub Command1_Click ...
    (sci.physics.relativity)
  • Re: Sorting a System.Collections.ObjectModel.Collection
    ... Public Sub Dispose() Implements System.IDisposable.Dispose ... Private m_SupportsSorting As Boolean = True ... Protected Overrides ReadOnly Property SupportsSortingCoreAs Boolean ... Dim m_SortList As New ArrayList ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Sorting a System.Collections.ObjectModel.Collection
    ... Public Sub Dispose() Implements System.IDisposable.Dispose ... Private m_SupportsSorting As Boolean = True ... Protected Overrides ReadOnly Property SupportsSortingCoreAs Boolean ... Dim m_SortList As New ArrayList ...
    (microsoft.public.dotnet.languages.vb)
  • Re: COM+, CRMs and Stuff
    ... Public Shared StartPath As String ... Public Sub New ... Dim _aRecord As New aRecord ... Function PrepareRecordAs Boolean ...
    (microsoft.public.dotnet.languages.vb)
  • Re: A little challenge for relativists.
    ... The Moon is 1.2 light seconds from Earth, ... > Dim redfirst As Boolean, bluefirst As Boolean, bluesecond As Boolean, ... > Private Sub Command1_Click ...
    (sci.physics.relativity)

Loading