Home > Software engineering >  The Boolean result, connection problems
The Boolean result, connection problems

Time:09-17

Public Sub test ()
Dim d As the Date
D="10/1/2015
"T="10/2/2015
"MsgBox Asc (d) & amp; ", "& amp; Asc (t) & amp; ", "& amp; D & lt; T
End Sub

Display the results why only False? 50,49, should not be "True"?

CodePudding user response:

Basic types of freedom, a bunch of bad habit to the programmer,
Different types of data you threw him, then he granted according to the results you want to give you? Why don't you give him want?
All uncertainty is caused by you,

Try
 
MsgBox Asc (CStr) (d) & amp; ", "& amp; Asc (CStr (t)) & amp; ", "& amp; CStr (d & lt; T)

CodePudding user response:

reference 1st floor chewinggum response:
basic types of freedom, a bunch of bad habit to the programmer,
Different types of data you threw him, then he granted according to the results you want to give you? Why don't you give him want?
All uncertainty is caused by you,

Try
 
MsgBox Asc (CStr) (d) & amp; ", "& amp; Asc (CStr (t)) & amp; ", "& amp; CStr (d & lt; T)

I know what you mean, I want to know, the reasons for the results I give is?

CodePudding user response:

I need to know "operator precedence" problem,




According to the expressions: you wrote Asc (d) & amp; ", "& amp; Asc (t) & amp; ", "& amp; D & lt; T
"Operator" of these only & amp; And & lt; ,

Because & amp; The priority of the above & lt; Advanced, so before the "strings", the last part "comparison",
Because of your variable t is "undefined", just so it is the Variant types of variables;
T after the assignment, the subtype is a String (although it is a "date", but it the first is "string" !) ,
As a result, the execution is "compare the size of the two strings", operation results, of course, only two kinds of True or False!

This period of "specific code" for you, the front & amp; The result is: "50,49,2015/10/1"
(note: the variable d converted into a "string", the result may be affected by the "system Settings", and in most cases are probably yyyy/m/d)
The last part of "comparison" is: "50,49,2015/10/1" & lt; "10/2/2015
"This result is of course False !!!!!!

Do you want your "desired results", so, must want to change the order of operations brackets!
To write like this: Asc (d) & amp; ", "& amp; Asc (t) & amp; ", "& amp; (d & lt; T)
So it would be "the results you want,"

  •  Tags:  
  • VBA
  • Related