Textboxes are strings. time.Month is integer. ToString() converts Integer to a string. Why does this not work?
Code:If (TextBox10.Text = time.Month.ToString() & TextBox7.Text = time.Day.ToString() & TextBox23.Text = time.Year.ToString()) Then
Printable View
Textboxes are strings. time.Month is integer. ToString() converts Integer to a string. Why does this not work?
Code:If (TextBox10.Text = time.Month.ToString() & TextBox7.Text = time.Day.ToString() & TextBox23.Text = time.Year.ToString()) Then
Because the & is the concatenation operation... not the bitwise operator you're looking for. Try And or AndAlso instead.
-tg
I think you mean And / AndAlso instead of &, which is the concatenation character
Of those, you almost certainly want AndAlso rather than And. It looks like you want logical comparisons, in which case AndAlso will be slightly more efficient than And, as it will stop evaluating as soon as the truth of the overall statement can be determined.
A couple further points you might consider:
1) String comparisons aren't the fastest, though in this case they should be pretty fast. You might consider using a NumericUpDown control rather than textboxes. The .Value property of a NUD is a Decimal, which can be converted easily to Integer. People can't enter invalid values into a NUD. They MUST enter a number, and you can set the number of decimal places (0 in this case), along with a max and min.
2) Using better names on the controls is a good idea.
Instead of using TextBoxes or even NumericUpDowns, why not use a DateTimePicker? It seems that the user is entering a date so why not use the control intended for that purpose? It will handle validation, e.g. ensure a valid day selection for February based on year, and then you can just compare its Value directly to the time variable.