Welcome Guest!
 VB Helper
 Previous Message All Messages Next Message 
VB Helper Newsletter  Rod Stephens
 Jun 10, 2011 09:57 PDT 

Note that the "24-Hour" in the title "Stephens' Visual Basic Programming
24-Hour Trainer" means the book is available for training 24 hours a
day, not that you can finish the whole book in 24 hours. A few people
have been confused by that.

The book could still use more reviews, by the way! (Only about half of
the people who promised reviews have posted them.)
This newsletter includes two book reviews. If you want those books, I'll
send you my review copies if you pay postage. They're bigger books so
probably won't fit in a prepaid envelope so the cost will probably be
about $10 in the US. (Perhaps $15 elsewhere?) If you're interested, let
me know.
Rumors are flying about what's coming in the next versions of Windows
and Visual Basic. One says Microsoft is changing gears again (which
seems to happen about once a month) and everything is now going to be
HTML 5 and JavaScript (forget Windows Forms and WPF). Another says
everything is going to be WPF and Windows Forms will be deprecated the
way Visual Basic "Classic" was. Both of these scenarios would be
disastrous to us VB folk.

At this point the rumors don't seem consistent or reliable enough to
worry too much about.
In the last episode, our Hero's source code had been deleted because
someone moved them into the wastebasket for safekeeping. This week I
opened the current executable in .NET Reflector and compared the results
to the most recent source code (which is pretty old). Reflector
sometimes interprets code kind of strangely but it did highlight the
differences between the old and new code and you can sort of see what
the code is doing so it wasn't too horribly hard (about half a day's
work) to reproduce the changes. The client still needs to finish

(A more organized IT department would have regression testing all set
up. But then again, they would have had source code control so this
would never have been an issue.)
Things to do this week:

- View screencasts from "Visual Basic 24-Hour Trainer":

    Lesson 3, Part 1: http://www.youtube.com/watch?v=7jxlebRMuu0
    Lesson 3, Part 2: http://www.youtube.com/watch?v=GLGIFmvZx7E
    Lesson 5:         http://www.youtube.com/watch?v=xeJPTBTmNzA

- Post book reviews
Have a great week and thanks for subscribing!


Twitter feeds:

    VB.NET Contents:
1. New HowTo: Draw text that sits above or below a line segment in
Visual Basic .NET
2. New HowTo: Draw text that follows a curve in Visual Basic .NET

    Both Contents:
3. Windows Phone Developer Tools 7.1 Beta was released on 5/23/11. You
can see the announcement at:
4. Book Review: Murach's ADO.NET 4 database programming with C# 2010, 4e
5. Book Review: Murach's ASP.NET 4 Web Programming with C# 2010, 4e
6. Book Update: Stephens' Visual Basic Programming 24-Hour Trainer
1. New HowTo: Draw text that sits above or below a line segment in
Visual Basic .NET

The key to this example is the DrawTextOnSegment method shown in the
following code. It draws as many characters as will fit along a line

' Draw some text along a line segment.
' Leave char_num pointing to the next character to be drawn.
' Leave start_point holding the coordinates of the last point used.
Private Sub DrawTextOnSegment(ByVal gr As Graphics, ByVal brush As
Brush, ByVal font As Font, ByVal txt As String, ByRef first_ch As
Integer, ByRef start_point As PointF, ByVal end_point As PointF, ByVal
text_above_segment As Boolean)
    Dim dx As Single = end_point.X - start_point.X
    Dim dy As Single = end_point.Y - start_point.Y
    Dim dist As Single = CSng(Math.Sqrt(dx * dx + dy * dy))
    dx /= dist
    dy /= dist

    ' See how many characters will fit.
    Dim last_ch As Integer = first_ch
    While (last_ch < txt.Length)
        Dim test_string As String = txt.Substring(first_ch, last_ch -
first_ch + 1)
        If (gr.MeasureString(test_string, Font).Width > dist) Then
            ' This is one too many characters.
            last_ch -= 1
            Exit While
        End If
        last_ch += 1
    End While
    If (last_ch < first_ch) Then Return
    If (last_ch >= txt.Length) Then last_ch = txt.Length - 1
    Dim chars_that_fit As String = txt.Substring(first_ch, last_ch -
first_ch + 1)

    ' Rotate and translate to position the characters.
    Dim state As GraphicsState = gr.Save()
    If (text_above_segment) Then
        gr.TranslateTransform(0, _
            -gr.MeasureString(chars_that_fit, font).Height, _
    End If
    Dim angle As Single = CSng(180 * Math.Atan2(dy, dx) / Math.PI)
    gr.RotateTransform(angle, MatrixOrder.Append)
    gr.TranslateTransform(start_point.X, start_point.Y,

    ' Draw the characters that fit.
    gr.DrawString(chars_that_fit, font, brush, 0, 0)

    ' Restore the saved state.

    ' Update first_ch and start_point.
    first_ch = last_ch + 1
    Dim text_width As Single = gr.MeasureString(chars_that_fit,
    start_point = New PointF( _
        start_point.X + dx * text_width, _
        start_point.Y + dy * text_width)
End Sub

The code starts by getting a unit-length vector (cx, dy) pointing in the
direction of the line segment. It then enters a loop making longer and
longer strings until it finds one that won't fit on the line segment. It
then removes the last character added giving the longest substring that
will fit.

If the longest substring is empty, the method returns without drawing
anything. If every character fits, the code sets the last character to
be the final one in the string.

Next the code saves the Graphics object's state so the code can undo the
transformations that follow.

If the method should draw the text above the line segment, the code adds
a translation to the Graphics object to move the text up by the text's

The code then calculates the angle of the line segment and adds a
rotation transformation to rotate the text to lie along the segment. It
then adds a final translation to move the text to the segment's starting

Finally the code draws the text at the origin. The transformations
rotate and position the text appropriately.

The code then cleans up. It restores the Graphics object's original
state, sets first_ch to indicate the first character that didn't fit,
and sets start_point to the last position drawn by the text.
2. New HowTo: Draw text that follows a curve in Visual Basic .NET

The example "Draw text that sits above or below a line segment in Visual
Basic .NET"
(http://www.vb-helper.com/howto_net_draw_text_along_segment.html) shows
how to draw text that follows a line segment. This example uses that
code to draw the pieces of code that follow a curve. The DrawTextOnPath
method shown in the following code uses the previous example's
DrawTextOnSegment method to draw text that follows a GraphicsPath.

' Draw some text along a GraphicsPath.
Private Sub DrawTextOnPath(ByVal gr As Graphics, ByVal brush As Brush,
ByVal font As Font, ByVal txt As String, ByVal path As GraphicsPath,
ByVal text_above_path As Boolean)
    ' Make a copy so we don't mess up the original.
    path = DirectCast(path.Clone(), GraphicsPath)

    ' Flatten the path into segments.

    ' Draw characters.
    Dim start_ch As Integer = 0
    Dim start_point As PointF = path.PathPoints(0)
    For i As Integer = 1 To path.PointCount - 1
        Dim end_point As PointF = path.PathPoints(i)
        DrawTextOnSegment(gr, brush, font, txt, start_ch, _
            start_point, end_point, text_above_path)
        If (start_ch >= txt.Length) Then Exit For
    Next i
End Sub

The code first makes a copy of the GraphicsPath so it can modify it
without messing up the original. It then flattens the path to turn it
into a series of line segments. (Note that a GraphicsPath may contain
more than one disconnected "figure." This example does not take that
into account and assumes all of the resulting segments are connected.)

The code then loops through the path's points and calls the
DrawTextOnSegment method to draw as many characters as will fit on the
current line segment.

If no characters fit on a line segment, the code keeps its current
starting point and uses the next point as the end point of a segment on
which to draw. That means if the path curves tightly the text may end up
written over parts of it. For reasonably smooth curves, which are the
only ones that text can really follow well, this isn't a problem.
3. Windows Phone Developer Tools 7.1 Beta was released on 5/23/11. You
can see the announcement at:


This release includes Visual Basic support for XNA and Windows Phone.

Here's an article about using it with VB:

4. Book Review: Murach's ADO.NET 4 database programming with C# 2010, 4e

At 712 pages, this book has plenty of room to cover a wide range of
topics with a satisfying depth. As its title says, it explains how to
use ADO.NET in C# programs, but it doesn't just explain how to use bound
controls. It also explains more advanced topics such as using XML data,
web applications, the Visual Studio Report Designer, and Microsoft's
latest attempt to make database programming easier the Entity Framework.

The book is more advanced than an "Idiot's" or "Dummies" book but is
well-written and easy to read so it is still accessible to database
programming beginners. While it covers some pretty advanced material, it
doesn't assume you know everything to begin with and it does a good job
of covering the basics. It includes lots of screen shots to help you
navigate through the confusing wizards and designers that Visual Studio
provides for working with databases.

The only nit I'll pick with this book is that it doesn't cover any
database products other than SQL Server. That is a very important
database tool for Visual Studio applications but much of the same
techniques work with other databases such as MySQL.

But I know firsthand that you can't cover everything in a book, even one
that's 712 pages long.
5. Book Review: Murach's ASP.NET 4 Web Programming with C# 2010, 4e

As the title implies, this book explains how to build web sites using
ASP.NET and C#. It's a big book (834 pages) so it has plenty of room to
cover a lot of material in depth. It doesn't assume you know anything
about web programming, however, so it also covers the basics, albeit

The book covers ASP.NET basics and explains how to use a database in a
web site. It also covers some very important and confusing topics such
as how to secure a website and authenticate users.

I particularly liked the appendix that explains how to install Internet
Information Services (IIS), Visual Studio, and SQL Server 2008 Express.
These aren't really part of the ASP.NET material but they are necessary
to work through the book so it's nice to have a little extra guidance

Similarly there's an appendix that gives you some guidance for working
with IIS. Again it's not really part of ASP.NET but it can make building
ASP.NET applications a lot easier. (Together these two appendices only
take up about 30 pages so the book doesn't waste too much space on

My only real complaint with the book is that it only covers SQL Server
databases. It would have been nice to have had at least a mention of
other databases such as MySQL, which is fairly popular on websites.

Also note that this book doesn't cover WPF or Silverlight applications.
Those are separate topics.

Overall a good introduction to ASP.NET development, suitable for both
beginners and those who have some experience with web development.
6. Book Update: Stephens' Visual Basic Programming 24-Hour Trainer

About Page 73, Keith Zavodney correctly says:

The Black and Blue items under 'Format / Text Color' use the same
accelerator "B". The Blue item should be using the 'l' as the
accelerator. For consistency the Blue item in the 'Format / Background
Color' submenu should also use the 'l'.

Twitter feeds:

Post questions at:
 Previous Message All Messages Next Message 
  Check It Out!

  Topica Channels
 Best of Topica
 Art & Design
 Books, Movies & TV
 Food & Drink
 Health & Fitness
 News & Information
 Personal Finance
 Personal Technology
 Small Business
 Travel & Leisure
 Women & Family

  Start Your Own List!
Email lists are great for debating issues or publishing your views.
Start a List Today!

© 2001 Topica Inc. TFMB
Concerned about privacy? Topica is TrustE certified.
See our Privacy Policy.