Welcome Guest!
 VB 6 Helper
 Previous Message All Messages Next Message 
VB 6 Helper Newsletter  Rod Stephens
 Sep 23, 2011 10:59 PDT 

Lots of interesting stuff popping out of Microsoft lately.

    Announcing Visual Studio 11 Developer Preview
    Jason Zander's Weblog

    Visual Studio 11 Developer Preview (MSDN subscribers only)

    .NET Framework 4.5 Developer Preview

    What's New in Visual Studio 11 Developer Preview

    What's New for Visual Basic in Visual Studio 11 Developer Preview

See the articles in this newsletter for the details I've found so far.
The bottom line seems to be:
Just for fun

Scientists recently discovered a planet orbiting a binary star system.
That brought me to this link:

WPF Programmer's Reference

Go beyond what you thought possible in user interface development

Windows Presentation Foundation (WPF) enables you to build effective and
unique graphical user interfaces. However, it takes a steep learning
curve to master the exceptions and shortcuts that are built into WPF.
This reference provides you with a solid foundation of fundamental WPF
concepts so you can start building attractive, dynamic, and interactive
applications quickly and easily. As the book progresses, topics
gradually become more advanced, and you'll discover how to use WPF to
build applications that run in more environments, on more hardware,
using more graphical tools, and providing a more engaging visual
experience than is normally possible with Windows Forms.
Have a great week and thanks for subscribing!


Twitter feeds:

    VB6 Contents:
1. New HowTo: Measure distances on a map with a scale in Visual Basic 6

    Both Contents:
2. Summary of what's new in Visual Basic, Visual Studio, and Windows 8
3. What's new in Visual Basic 2011
4. What's new in Visual Studio 2011
5. What's new in .NET Framework 4.5
1. New HowTo: Measure distances on a map with a scale in Visual Basic 6

Picture at http://www.vb-helper.com/howto_measure_map.png.

Recently I wanted to know how far a lap around my local park was. If you
look at Google Maps, you can find maps of just about anywhere with the
scale shown on them. This application lets you load such a map,
calibrate by using the scale, and then measure distances on the map in
various units.

This is a fairly involved example. Most of the pieces are relatively
simple but there are a lot of details such as how to parse a distance
string such as "1.5 miles."

I wanted to use this program with a map from Google Maps but their terms
of use don't allow me to republish their maps so this example comes with
a cartoonish map of a park that I drew. (Probably no one would care but
there's no need to include one of their maps anyway.) To use a real
Google Map, find the area that you want to use and press Alt-PrntScrn to
capture a copy of your browser. Paste the result into Paint or some
other drawing program and edit the image to create the map you want.

The following code shows variables and types defined by the program.

' Known units.
Private Enum Units
    Undefined = -1
    Miles = 0
    Yards = 1
    Feet = 2
    Kilometers = 3
    Meters = 4
End Enum

' What we are doing.
Private Enum MouseStates
End Enum
Private MouseState As MouseStates

' Key map values.
Private ScaleDistanceInUnits As Double
Private ScaleDistanceInPixels As Double
Private CurrentUnit As Units
Private CurrentDistance As Double

' Scale information.
Private ScaleStartX As Single
Private ScaleStartY As Single
Private ScaleEndX As Single
Private ScaleEndY As Single

' Measurement information.
Private MeasurementXs As Collection
Private MeasurementYs As Collection

The Units enumeration defines the units of measure that this program can
handle. The MouseStates enumeration helps the program keep track of what
it is doing as the user manipulates the mouse. This is a bit easier in
.NET where the program can install and uninstall event handlers to
perform different tasks.

Use the File menu's Open command to open a map file. You can control the
program by using its combo box and two buttons.

The combo box lets you select one of the known units. If you pick one of
the choices, the following code executes.

' Set the scale.
Private Sub cboUnits_Click()
Dim conversion As Double

    ' Display the map scale and distance in this unit.
    ' Find a factor to convert from the old units to meters.
    conversion = 1
    If (CurrentUnit = Units.Feet) Then
        conversion = 0.3048
    ElseIf (CurrentUnit = Units.Yards) Then
        conversion = 0.9144
    ElseIf (CurrentUnit = Units.Miles) Then
        conversion = 1609.344
    ElseIf (CurrentUnit = Units.Kilometers) Then
        conversion = 1000
    End If

    ' Find a factor to convert from meters to the new units.
    CurrentUnit = cboUnits.ListIndex
    If (CurrentUnit = Units.Feet) Then
        conversion = conversion * 3.28083
    ElseIf (CurrentUnit = Units.Yards) Then
        conversion = conversion * 1.09361
    ElseIf (CurrentUnit = Units.Miles) Then
        conversion = conversion * 0.000621
    ElseIf (CurrentUnit = Units.Kilometers) Then
        conversion = conversion * 0.001
    End If
    ' Convert and display the values.
    If ScaleDistanceInUnits >= 0 Then
        ScaleDistanceInUnits = ScaleDistanceInUnits * conversion
        CurrentDistance = CurrentDistance * conversion
    End If

End Sub

The code checks the current units and makes a conversion factor to
convert from the current unit to meters. It then looks at the new choice
and multiplies on a conversion factor to convert from meters to the new
units. That avoids the need to have a table giving conversion factors
for every pair of old and new units.

The following code shows how the program responds when you click the Set
Scale or Measure button.

' Let the user set the scale.
Private Sub cmdSetScale_Click()
    lblInstructions.Caption = "Click and drag from the start and end
point of the map's scale bar."
    lblScale.Caption = ""
    picMap.MousePointer = vbCrosshair
    MouseState = MouseStates.ScaleStart
End Sub

' Let the user measure a distance.
Private Sub cmdMeasure_Click()
    lblInstructions.Caption = "Click and draw to select a distance to
    lblDistance.Caption = ""
    picMap.MousePointer = vbCrosshair
    MouseState = MouseStates.MeasureStart
End Sub

The key to these event handlers is that they set the MouseState
variable. The mouse event handlers then take the appropriate action. The
following code shows the MouseDown event handler.

' Do stuff with the mouse.
Private Sub picMap_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
    If MouseState = MouseStates.ScaleStart Then
        ScaleStartX = X
        ScaleStartY = Y
        MouseState = MouseStates.ScaleEnd
    ElseIf MouseState = MouseStates.MeasureStart Then
        Set MeasurementXs = New Collection
        Set MeasurementYs = New Collection
        MeasurementXs.Add X
        MeasurementYs.Add Y
        MouseState = MouseStates.MeasureEnd
    End If
End Sub

If the program is letting the user set the scale, the code saves the
mouse's location and sets MouseState to ScaleEnd to indicate that the
program must now let the user pick the scale's otehr end point.

If the program is letting the user set the measure a distance, the code
makes new collections to hold the selected path's points. It saves the
current position and then sets MouseState to MeasureEnd to indicate that
it is measuring a path.

The following code shows the program's MouseMove event handler.

Private Sub picMap_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)
Dim i As Integer

    If MouseState = MouseStates.ScaleEnd Then
        picMap.Line (ScaleStartX, ScaleStartY)-(X, Y), vbRed
    ElseIf MouseState = MouseStates.MeasureEnd Then
        MeasurementXs.Add X
        MeasurementYs.Add Y
        picMap.CurrentX = MeasurementXs(1)
        picMap.CurrentY = MeasurementYs(1)
        For i = 2 To MeasurementXs.Count
            picMap.Line -(MeasurementXs(i), MeasurementYs(i)), vbRed
        Next i
    End If
End Sub

If the program is drawing the map's scale, it clears the map and draws a
line from the scale's start position to its new end point.

If the program is drawing a path to measure, it saves the current
location in the collections of coordinates, clears the map, and draws
the path so far.

The following code shows the MouseUp event handler,

Private Sub picMap_MouseUp(Button As Integer, Shift As Integer, X As
Single, Y As Single)
Dim dlg As ScaleDialog
Dim dx As Double
Dim dy As Double
Dim dist As Double
Dim i As Integer

    If MouseState = MouseStates.ScaleEnd Then
        MouseState = MouseStates.Undefined
        picMap.MousePointer = vbDefault
        lblInstructions.Caption = ""

        ' Get the scale.
        Set dlg = New ScaleDialog
        dlg.Show vbModal
        If Not dlg.Canceled Then
            ' Get the distance on the screen.
            dx = X - ScaleStartX
            dy = Y - ScaleStartY
            dist = Sqr(dx * dx + dy * dy)
            If (dist < 1) Then Exit Sub
            ScaleDistanceInPixels = dist

            ' Parse the distance.
            ParseDistanceString dlg.txtScale.Text, _
                ScaleDistanceInUnits, CurrentUnit

            ' Display the units.
            cboUnits.Text = UnitName(CurrentUnit)

            ' Display the scale and measured distance.
            CurrentDistance = -1
        End If
    ElseIf MouseState = MouseStates.MeasureEnd Then
        MouseState = MouseStates.Undefined
        picMap.MousePointer = vbDefault
        lblInstructions.Caption = ""

        ' Measure the curve.
        dist = 0
        For i = 2 To MeasurementXs.Count
            dx = MeasurementXs(i) - MeasurementXs(i - 1)
            dy = MeasurementYs(i) - MeasurementYs(i - 1)
            dist = dist + Sqr(dx * dx + dy * dy)
        Next i
        ' Convert into the proper units.
        CurrentDistance = dist * ScaleDistanceInUnits /
        ' Display the result.
    End If
End Sub

If the program is drawing the map's scale, the code displays a small
dialog where you can enter the scale's distance as in "100 yards" or "1
kilometer." If you enter a value and click OK, the code parses the value
and calculates the length of the line you drew on the map. From that it
can later calculate the map's scale in units per pixel.

If the program is drawing a path to measure, the code measures the path
and displays its length in the appropriate units.

The most interesting remaining pieces of code parse distance values that
you enter in the dialog. The ParseDistanceString method shown in the
following code starts the process.

' Parse a distance string. Return the length and units.
Private Sub ParseDistanceString(ByVal txt As String, ByRef distance As
Double, ByRef unit As Units)
Dim i As Integer
Dim unit_string As String
Dim ch As String

    txt = Trim$(txt)

    ' Find the longest substring that makes sense as a double.
    i = DoublePrefixLength(txt)
    If (i <= 0) Then
        distance = -1
        unit = Units.Undefined
        ' Get the distance.
        distance = CDbl(Mid$(txt, 1, i))

        ' Get the unit.
        unit_string = LCase$(Mid$(txt, i + 1))
        ch = Mid$(unit_string, 1, 1)
        If Mid$(unit_string, 1, 2) = "mi" Then
            unit = Units.Miles
        ElseIf ch = "y" Then
            unit = Units.Yards
        ElseIf ch = "f" Then
            unit = Units.Feet
        ElseIf ch = "'" Then
            unit = Units.Feet
        ElseIf ch = "k" Then
            unit = Units.Kilometers
        ElseIf ch = "m" Then
            unit = Units.Meters
            unit = Units.Undefined
        End If
    End If
End Sub

This method calls the DoublePrefixLength method to see how many
characters at the beginning of the string should be interpreted as part
of the number. It extracts those characters to calculate the numeric
value. It then examines the beginning of the characters that follow to
see what unit you entered. For example, if the following text starts
with y, the unit is yards.

The following code shows the DoublePrefixLength method.

' Return the length of the longest prefix
' string that makes sense as a double.
Private Function DoublePrefixLength(ByVal txt As String) As Integer
Dim i As Integer
Dim test_string As String
Dim test_value As Double

    For i = 1 To Len(txt)
        test_string = Mid$(txt, 1, i)

        On Error Resume Next
        test_value = CDbl(test_string)
        If Err.Number <> 0 Then
            DoublePrefixLength = i - 1
            Exit Function
        End If
        On Error GoTo 0
    Next i

    DoublePrefixLength = Len(txt)
End Function

This code considers prefixes of the string of increasing lengths until
it finds one that it cannot parse as a double. For example, if you enter
"100yards," the program can parse the prefixes 1, 10, and 100 but it
cannot parse 100y so it concludes that the numeric part of the string
contains 3 characters.

The program uses the following code to let you measure a distance on the

I haven't spent too much time on bug proofing this program so I wouldn't
be surprised if it shows some odd behavior. I'll leave it to you to
experiment with it.
2. Summary of what's new in Visual Basic, Visual Studio, and Windows 8

I have not spent nearly enough time with the new versions to be certain
about this, bit I think the bottom line seems to be:

- In Visual Basic, not much has changed.

- In Visual Studio, there are a few new windows and tools. Nothing that
will require extensive retraining.

- In Windows, big changes. Microsoft now favors "Metro-style"
applications. I think they basically want the computer to look like a
big Windows 7 Phone or iPad or something. You can switch to a classic
windows desktop but it seems like Microsoft is pushing for the Metro

To make building Metro-style interfaces easier, the next release of
Visual Studio will include a bunch of templates that you can use as a
basis for creating applications. I think this will be pretty important
for us Windows developers.

This article caught my eye:

    Microsoft's Metro proves the PC is dead

Probably the most interesting part is the architectural picture at the
top, which is also discussed in greater detail here:

    Here's the one Microsoft Windows 8 slide that everyone wants to redo

That picture shows how Metro-style and desktop applications fit in
Windows 8. The two areas are noticeably separated vertically so there's
very little that they share except at the lowest levels (Windows kernel
services or core OS services).

Microsoft says everything will eventually transition from the blue
desktop area to the green Metro area and that lack of interaction
between the two in the picture makes this plausible.

Other pictures from the second article provide more information. It
seems like Microsoft is still pushing its notion that all developers
will move to WPF, and that this will happen in the Metro-style
environment in the future.

As usual, we�ll see how it plays out over the next year or so.
3. What's new in Visual Basic 2011

Here are the key changes I've read about so far:
Async - A new way to run code asynchronously, although without starting
new threads.

Taking advantage of parallelism will be essential in the future for
getting the most out of multicore and multi-CPU systems. Unfortunately
parallel programming in general is difficult. Anything that makes it
easier is a good thing. What this does is allow a method to wait for
some other asynchronous call to complete before continuing, but at the
same time allowing the rest of the program to continue.

For example, suppose you write a DownloadFileAsync method (by convention
you now add Async to the end of the name) that downloads a big file from
the Internet. You mark the method Async. At some point it starts the
download call. You mark that statement with the Await keyword. When
execution reaches that point, the DownloadFileAsync method waits but
control is returned to the main program so it can continue executing.
When the download finishes, the DownloadFileAsync method continues
running after the Await statement.
Iterators - You can write an iterator that other code can loop through
by using a For Each loop.

The Yield statement makes the iterator return a value to the looping
code. For example, the following code defines an iterator that returns
the even numbers between 1 and 100.

    Private Iterator Function Evens1to100() As IEnumerable(Of Integer)
        For number As Integer = 1 To 100
            If number Mod 2 = 0 Then
                Yield number
            End If
        Next number
    End Function

The following code calls this iterator:

    For Each number As Integer In Evens1to100()
    Next number
Call hierarchy IDE design time window - Lets you understand the code's
call graph better. It lets you display:

    - All calls to or from a method
    - All implementations of an interface
    - All overrides of an Overridable or MustOverride member
Global namespace keyword - Defines a namespace outside of your root

This has always been an odd omission. If you want two programs to use
something that is in the same namespace, this lets you do it. For
example, suppose you define a Student class that you want multiple
projects to use. By using the Global namespace, you can declare a
namespace to hold the Students class that is outside of the namespaces
of the two projects.

Global also allows you to use system namespaces even if you have
"shadowed" them by defining one with the same name. For example, if you
make a namespace called "System" (which would be prestty confusing), you
can access the real system namespace by using Global.System.
4. What's new in Visual Studio 2011

Here are the key changes I've read about so far:
From Jason Zander's blog

"Visual Studio 11 provides an integrated development experience that
spans the entire lifecycle of software creation from architecture to
code creation, testing and beyond. This release adds support for Windows
8 and HTML 5, enabling you to target platforms across devices, services
and the cloud. Integration with Team Foundation Server enables the
entire team to collaborate throughout the development cycle to create
quality applications."

It's not clear what all that means in practical terms.
Code clone analysis

Jason's blog mentions this. It will look through your code for common
structure. You may be able to use that to refactor or to find code that
is similar to code in which you found a bug so you know where to look
for similar bugs.
Code review workflow with Team Explorer
Exploratory testing and enhanced unit testing
Backward compatibility

Really this means forward compatibility.

I've been complaining about this since Visual Basic 3.0. There's no
reason why you can't make software forward compatible. If you try to
open a VB 2011 project in VB 2010, it can work as long as the project
doesn't use any of the features that were introduced in VB 2011. We
finally have this, sort of.

If you edit a VB 2010 project in VB 2011, you can later open it again in
VB 2010 as long as you haven't used any new VB 2011 features.

It's not quite what I had in mind but it's a start.
Browse code in Solution Explorer
Pin frequently used files
Preview files by single-clicking them in Solution Explorer (without
opening them and cluttering up the IDE with extra windows)
Enhanced multi-monitor support
Quick search for IDE menu commands

For example, to find that missing window. Is it in the View menu? The
Debug menu? The View menu's Other Windows submenu?
Filter entries in Toolbox, Solution Explorer, Error List and other

This is a feature that was already introduced in Expression Blend, IMHO
to overcome the terrible arrangement of items in the Properties window.
Items are ordered by categories that don't make intuitive sense so it's
very hard to find anything even if you know exactly what you're looking
for. Now if you can't find the HScrollBar control in a Toolbox
containing more than 50 controls, you can search for it.
Regular expressions in Find and Replace

This is very powerful but it will take some time to get good at it.
Simplified remote debugging
Collect IntelliTrace event data on computers that don't have Visual
Studio installed
New windows and features for parallel debugging
Concurrency Visualizer enhancements
TPL dataflow support
New image and texture editing tools. Includes support for compression
(PNG, JPG, TIFF), alpha transparency, and mipmaps.
3D modeling support

Inspect files in standard 3D model formats and add placeholder objects.
Edit HLSL programmable shaders
Create pixel shaders
DirectX graphics debugging tools
LocalDB engine

A lightweight SQL Server engine.
SQL Server node in Server Explorer
ASP.NET and Web development enhancements

I didn't look closely at these because I haven't done much of that
Sharepoint development enhancements

I didn't look closely at these either because I haven't done much of
that lately.
5. What's new in .NET Framework 4.5

Here are the key changes I've read about so far:
Core New Features and Improvements
    - Add timeout limit for regular expressions
    - Define culture for an application domain
    - Console support for Unicode
    - Versioning for cultural string ordering and comparison data
.NET for Metro style apps

I haven't looked closely at these. If you do a lot of this, you'll want
more detail than I can give you.

New programming interface for working with HTTP.

    - A new ribbon control. (Hasn't Microsoft realized how horrible the
ribbon is yet?)
    - New support for synchronous and asynchronous data validation.
    - New features for some classes.
    - Improved performance.
    - Data binding to static properties.
    - Repositioning data as values change.

I haven't looked closely at this.

I haven't looked closely at this.

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.