Results 1 to 5 of 5

Thread: Integer into Strings

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2010
    Posts
    87

    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

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Integer into Strings

    Because the & is the concatenation operation... not the bitwise operator you're looking for. Try And or AndAlso instead.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,733

    Re: Integer into Strings

    I think you mean And / AndAlso instead of &, which is the concatenation character

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,102

    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

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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
  •  



Click Here to Expand Forum to Full Width