new string what?-VBForums
Results 1 to 6 of 6

Thread: new string what?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    new string what?

    strNoWOCalDate = string(2-len(month(cdate(strCalDate))), "0") & month(cdate(strCalDate)) & string(2-len(day(cdate(strCalDate))), "0") & day(cdate(strCalDate)) & right(year(cdate(strCalDate)),2)


    Does anyone know what the heck the above is doing?
    I'm in the process of updating it to C# but that is classic ASP/VBScript code. I just dont quite get what its doing there.

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    88,948

    Re: new string what?

    It looks to me like it's taking a String representation of a date and reformatting it into MMddyy format. If you were to take a date string like "7/4/2013" (en-AU) and feed it to that code then I think that you'd get "040713" back. There's an easy way to test that, because that code should work the same way in VB.NET just as it would in VB6 or VBScript.

    2007-2014

    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: new string what?

    thanks.
    yes indeed. I thought the code would work with VB.NET as well and compare it using that. just wanted to make sure I understood what was going on rather than comparing like for like.

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: new string what?

    unfortunately doing it in VB.NET does not quite work - compiler error:

    Code:
    
    Dim strCalDate As DateTime = Me.DateTimePicker1.Value
            Dim strNoWOCalDate As String = string(2-len(month(cdate(strCalDate))), "0") & month(cdate(strCalDate)) & string(2-len(day(cdate(strCalDate))), "0") & day(cdate(strCalDate)) &  right(year(cdate(strCalDate)),2)
    error: '.' expected.

    this is just before the opening bracket: = string(2-...

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  5. #5
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    3,973

    Re: new string what?

    Does this give you the desired results?
    Code:
    Dim strCalDate As DateTime = Me.DateTimePicker1.Value
    MessageBox.Show(strCalDate.ToString("MMddyy"))

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: new string what?

    indeed. I figured it out earlier and forgot to post!
    so really, it is just MMddyy... wow... what a way to do it

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.