What are the Integer values of Boolean False and True in VB6?

前端 未结 3 792
南方客
南方客 2020-12-19 01:52

I\'m working with a bit of old VB6 code that goes thus...

Dim STATUS As Integer

STATUS = -1

If (Not STATUS) Then
\' do something
Else
\' do something else
         


        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-19 02:17

    Not really an answer, but just poking about, I typed this into the immediate window, with these results:

    For x = -5 To 5 : ? x, CBool(x), ( x = True ), ( x = False ) : Next x
    -5            True          False         False
    -4            True          False         False
    -3            True          False         False
    -2            True          False         False
    -1            True          True          False
     0            False         False         True
     1            True          False         False
     2            True          False         False
     3            True          False         False
     4            True          False         False
     5            True          False         False
    

    (I tested more values, but only -1 and 0 had anything "interesting" going on. The rest were all True/False/False.) So, empirically, I'd say that the comparison is being done arithmetically unless you cast with CBool. Why? I can't really say...

提交回复
热议问题