Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
|
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 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 May 21st, 2008, 12:54 AM
Authorized User
 
Join Date: Mar 2008
Posts: 74
Thanks: 2
Thanked 0 Times in 0 Posts
Send a message via ICQ to sektor
Default Extract a digit from specified position

I have number, which consists of 13 digits, and I need to extract 12-th digit.
In VBA I used LEFT function. What function I gotta use in VB 2005?

 
Old May 21st, 2008, 01:53 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Can you t ry the following

        Dim sInput As String = "SomeStringForExtraction"
        Dim sOutput
        sOutput = Mid(sInput, 12, 1)


Cheers
Shasur

http://www.dotnetdud.blogspot.com

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
 
Old May 23rd, 2008, 02:47 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Mid works in .NET.
But you can also use the new Substring() method.

If the name of your string is "s":
Code:
    s.Substring(startIndex_As_Integer, length_As_Integer)
    ' or
    s.Substring(12, 1)
    How would you use the Left() function? I could see Right(s, 1)...
 
Old June 4th, 2008, 01:05 AM
Authorized User
 
Join Date: Mar 2008
Posts: 74
Thanks: 2
Thanked 0 Times in 0 Posts
Send a message via ICQ to sektor
Default

BrianWren, thanks a lot!
But how can I get to know which methods are obsolete and which one are new to VB 2005?

 
Old June 4th, 2008, 08:46 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I don't know of anything that has been removed from the 1.1 to 2.0 .NET upgrade. Of course, there are many thousands of classes and that many more members of those classes so know one could know what's been changed but Microsoft. If a method has been deprecated, it will be marked as such in the framework and you'll get a warning that the class or method is not obsolete. This doesn't necessarily mean you can't use it, but that it's no longer supported and you should upgrade your code. There's always the potential that the next framework upgrade will break on obsolete members.

-Peter
compiledthoughts.com
 
Old June 4th, 2008, 10:26 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Peter,

Can you think of a way to use Left() to obtain the nth character in a string where n <> 1? (Since sektor apparently didn’t feel like answering...)

Perhaps he used Result = Left(Right(s, 2), 1)....
 
Old June 4th, 2008, 12:46 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Basically what you have but the other way around. Use left to get from the start to n, then right.

Right(Left(s, n), 1)

I can't imagine how you'd do it with only Left() though. But my VBA is very rusty.

-Peter
compiledthoughts.com
 
Old June 7th, 2008, 05:28 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

For .NET, you could also just index the string:

Dim digits As String = "1234567890123"
Dim result As Char = digits(11)


Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
 
Old June 9th, 2008, 03:30 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Now [u]that’s</u> handy! Kudos Imar!
 
Old June 9th, 2008, 03:50 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

;) You're welcome.....

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to extract a spreadsheet ravee39 SQL Server 2005 1 April 23rd, 2007 09:20 AM
TAPI 3.0 : Problem in Digit Detection Qaisar Visual C++ 0 March 10th, 2006 09:54 PM
7 Digit number jemacc SQL Server 2000 3 April 4th, 2004 01:02 AM
How to keep two digit after float number? Edward King Javascript 1 July 30th, 2003 01:12 AM





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