Regarding boolean type variable
-
When i use below code, it returns true and then i changed the condition to check m=1 then its returns false. I am little confused about booleans so please let me know the internal implementation about boolean. Dim m As Boolean = 1 If m = -1 Then MsgBox("true") Else MsgBox("false") End If I know that using "True" or "False" is best practise but for better understanding i need this Thanks in advance Regards Azeem
-
When i use below code, it returns true and then i changed the condition to check m=1 then its returns false. I am little confused about booleans so please let me know the internal implementation about boolean. Dim m As Boolean = 1 If m = -1 Then MsgBox("true") Else MsgBox("false") End If I know that using "True" or "False" is best practise but for better understanding i need this Thanks in advance Regards Azeem
-
When i use below code, it returns true and then i changed the condition to check m=1 then its returns false. I am little confused about booleans so please let me know the internal implementation about boolean. Dim m As Boolean = 1 If m = -1 Then MsgBox("true") Else MsgBox("false") End If I know that using "True" or "False" is best practise but for better understanding i need this Thanks in advance Regards Azeem
-
When i use below code, it returns true and then i changed the condition to check m=1 then its returns false. I am little confused about booleans so please let me know the internal implementation about boolean. Dim m As Boolean = 1 If m = -1 Then MsgBox("true") Else MsgBox("false") End If I know that using "True" or "False" is best practise but for better understanding i need this Thanks in advance Regards Azeem
Trying to locate a link that shows you why this happens, but what you are seeing is type conversion related. VB.NET stores false as a 0 and any other value as true, but that defaults to being stored as = -1. So, when you assign the Boolean = 1 it gets converted internally to -1 because it is not a false value (0). Try doing a few debug.prints and setting the Boolean to a few values and see what happens. It looks to me like you do not have option strict turned on. If not, you should because it forces your code to be far more explicit and not allow type coercion (dynamic type conversion) like this.
-
When i use below code, it returns true and then i changed the condition to check m=1 then its returns false. I am little confused about booleans so please let me know the internal implementation about boolean. Dim m As Boolean = 1 If m = -1 Then MsgBox("true") Else MsgBox("false") End If I know that using "True" or "False" is best practise but for better understanding i need this Thanks in advance Regards Azeem