Wrox Programmer Forums
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 9th, 2004, 03:20 PM
Authorized User
 
Join Date: Jun 2004
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default need help with this code

HI guys im new to vb.net and im trying to do the following,
 i have a string in the format "30/07/1979", what i wana do is extract the last 4 characters, therefore in this case "1979" and place it in a variable X. I did this in java about 5 months ago and im kicking myself now cause i forgot how i did it. Does anyone have any ideas, many thanks in advance.



 
Old July 9th, 2004, 11:15 PM
Authorized User
 
Join Date: Jul 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to jhawar
Default

Hi,

Dim x As String
        x = (Strings.Right(YourString as String, 4))

Hope this helps

Amit Jhawar
Developer
 
Old September 12th, 2004, 10:03 PM
Registered User
 
Join Date: Sep 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Another way to do this would also include a validation check (to make sure the original string was a date)

        Dim YourString As String = "30/07/1979"
        Dim s As String
        Try
            ' get the year from the date
            s = CDate(YourString).Year.ToString
        Catch ex As Exception
            ' assume not valid date format
            MsgBox("Not valid Date format!")
        End Try

        ' display year
        MsgBox(s)

You are actually turning your original string into a Date first, then obtaining the Year, then turing that Year into a string. But it'll allow you to handle incorrect data formats!

By the way, I live in the UK, and I hate the problems I encounter because of American dates being mm/dd/yy?!? It doesn't make any sence to me!?!? Why not smallest unit first?? dd/mm/yy!?? Or at least in unit order.. i.e. hh:mm:ss (getting smaller)!! I guess I'll never know? ;)

 
Old September 23rd, 2004, 10:29 AM
Registered User
 
Join Date: Jul 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Funny, I've always seen it from the others side (helps that I live in the states, I suppose).

The long format for writing a date is:
 month dd, yyyy (ie September 7th, 2003). At least that was how I was taught to write dates in grade school.

So, it follow that the shortened version of that would be:
 mm/dd/yy or 9/7/2003.

Not sure how valid that is, but it's a possible explanation.

Steve

PS Oddly, when I was in the military dates were usually written:
  07SEP03 or less formally 7 Sept 2003. That was fairly standard.

Why is an elevator called a "lift", an apartment a "flat" and a flashlight a "torch?" :D






Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent:hard disk serial code and vb code ivanlaw Pro VB 6 0 July 25th, 2007 04:05 AM
VB: .Exe file, serial code and activation code ivanlaw Pro VB 6 8 July 6th, 2007 05:44 AM
code clinic - Why wont example asp code work? jardbf Classic ASP Basics 3 April 27th, 2006 06:22 PM
Writing Client Side Script from Code-Behind code sajid_pk Classic ASP Databases 1 January 18th, 2005 12:53 AM
disable forum code within [code] blocks? nikolai Forum and Wrox.com Feedback 0 October 23rd, 2003 07:52 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.