p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Visual Basic 2008 Programmer's Reference ISBN: 978-0-470-18262-8 (http://p2p.wrox.com/forumdisplay.php?f=384)
-   -   formatting strings and string.format (http://p2p.wrox.com/showthread.php?t=84509)

eightbits2011 July 27th, 2011 01:44 PM

formatting strings and string.format
Just got my book a few hours ago. I was unable to find any subject matter
concerning the use of string.format("{o}",vbCrLf) as an example.
I was looking for the explanation on using the place holders such as {0}.[:(]

Perhaps I could not find it yet. Also need information on using the serial port if it is covered.

I am looking forward to using the book in my quest to gain enough knowledge to use VB.NET for various projects.
I look forward as well to using the forum for assistance and knowledge.

Years ago I was able to use a WROX book on HTML and it helped much.
That was the reason I purchased this book.

Best Regards to all.

Rod Stephens July 27th, 2011 03:34 PM

That's covered briefly in Appendix Q, "Other Format Specifiers" on page 1105-6.

The quick explanation is that the method replaces the placeholders with the parameters that follow. For example:


Dim txt As String = String.Format("There are {0} players", num_players)
If num_players is a variable holding the value 9, then this builds the string:


There are 9 players
You can also add an alignment and format specifier if you like.

Let me know if you have specific questions about this. It isn't covered too much in the book. Often it's just as easy to compose strings using concatenation instead of String.Format.

eightbits2011 July 28th, 2011 11:00 AM

Thanks so much for the quick reply.
Yes, I agree, the examples are sparse on this particular subject. I was hoping for a lot of example(s). I was looking for examples that covered
the formating of the placeholders and the results.

I agree that the just doing concatenate techniques will also do the job in most cases .

Considering that using VB.NET is relatively new to me, I wanted to insure that I have an understanding of using string.format.
It seems similar to using printf (C language) that I have some experience with.

All on all , I think the book will assist my goal to become knowledgeable in using VB.NET.

Also, I think I need to learn to use modules but did not see a lot of
examples on doing this.

Once again, thank you for the reply.

Rod Stephens July 28th, 2011 12:40 PM

Yes, String.Format is a lot like printf (or probably really sprintf). The time I probably use it most is when I want to align things in columns.

Modules are pretty easy. They're simply code like global variables and routines that sits out there for any part of the program to use. The only really different thing is that code modules don't have any associated class. In contrast, C# doesn't have code modules so every piece of code must be in a class. To get a similar effect, you create a class (often called Globals or something similar) and give it static (shared) members so all of the rest of the code can use it without instantiating the class.

eightbits2011 July 30th, 2011 02:23 PM

Thanks. Where in the book is the best place to get up to speed on
using modules and incorporating modules into new or existing projects?

Best Regards.

Rod Stephens July 30th, 2011 03:10 PM

Chapter 17, "Subroutines and Functions," may be a good place to start. But it's so easy there isn't too much coverage.

Just open the Project menu, select Add Module, give it a name, and click OK. Then add code to the module. If you add a public subroutine, function, or variable to the module, then any code in the project will be able to use it.

It's that easy.

Give it a try and let me know if you have problems.

eightbits2011 July 31st, 2011 10:08 AM

OK, I will continue to look at this. It seems this is an important feature
of using VB.NET.
Is there any simple examples on using a module from a form ?
As you might be able to tell, the inner workings of VB.NET are still
new to me.

I do thank you for your assistance.
Going through the book, there are many subjects covered, and I will
continue to learn from this book.
I already have four additional VB 2008 books as well.[:D]

Best Regards

Rod Stephens July 31st, 2011 10:40 PM

You can download an example at:

Write a subroutine in a code module that scales controls without moving them in Visual Basic .NET.

All times are GMT -4. The time now is 02:31 PM.

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