|
-
Mar 14th, 2022, 10:12 AM
#1
Thread Starter
Lively Member
Integer into Strings
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
-
Mar 14th, 2022, 10:18 AM
#2
Re: Integer into Strings
Because the & is the concatenation operation... not the bitwise operator you're looking for. Try And or AndAlso instead.
-tg
-
Mar 14th, 2022, 10:19 AM
#3
Re: Integer into Strings
I think you mean And / AndAlso instead of &, which is the concatenation character
-
Mar 14th, 2022, 11:58 AM
#4
Re: Integer into Strings
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.
My usual boring signature: Nothing
 
-
Mar 14th, 2022, 06:34 PM
#5
Re: Integer into Strings
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.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|