Welcome Guest!
 VB.NET Helper
 Previous Message All Messages Next Message 
VB .NET Helper Newsletter  Rod Stephens
 May 23, 2009 07:35 PDT 

Does anyone know what happened to Neil Crosby? I haven't heard from him
in a while. Are you out there Neil?
----------
New review of "Beginning Database Design Solutions":

    http://www.denvervisualstudio.net/Reviews/Books2009/Book04272009.htm
----------
Have a great week and thanks for subscribing!

Rod
RodSte-@vb-helper.com

Books To Keep: http://www.BooksToKeep.com
----------
*** Now Available ***

Beginning Database Design Solutions
http://www.amazon.com/exec/obidos/ASIN/0470385499/vbhelper/

Visual Basic 2008 Programmer's Reference
http://www.amazon.com/exec/obidos/ASIN/0470182628/vbhelper/
==========

    VB.NET Contents:
1. New HowTo: Make a ComplexNumber class with operators in Visual Basic
.NET
2. New HowTo: Get the values of fields (variables) declared in a form by
their names in Visual Basic .NET
3. New HowTo: Get information about the window under the mouse in Visual
Basic .NET

    Both Contents:
4. New HowTo: Use code to make a chart in Excel from the current
selection in VBA
5. New Links
6. A Different Kind of Review
7. New Article
==========
++++++++++
<VB.NET>
++++++++++
==========
1. New HowTo: Make a ComplexNumber class with operators in Visual Basic
.NET
http://www.vb-helper.com/howto_net_complex_number_with_operators.html
http://www.vb-helper.com/HowTo/howto_net_complex_number_with_operators.zip


The ComplexNumber class uses the following code, which is fairly
straightforward.

Public Class ComplexNumber
    Private m_RealPart As Single
    Private m_ImaginaryPart As Single

    ' Property procedures.
    Public Property RealPart() As Single
        Get
            Return m_RealPart
        End Get
        Set(ByVal Value As Single)
            m_RealPart = Value
        End Set
    End Property

    Public Property ImaginaryPart() As Single
        Get
            Return m_ImaginaryPart
        End Get
        Set(ByVal Value As Single)
            m_ImaginaryPart = Value
        End Set
    End Property

    ' Constructor using real and imaginary parts.
    Public Sub New(Optional ByVal real_part As Single = 0.0, Optional
ByVal imaginary_part As Single = 0.0)
        m_RealPart = real_part
        m_ImaginaryPart = imaginary_part
    End Sub

    ' Constructor using a String of the form R + Ii.
    Public Sub New(ByVal string_value As String)
        Dim pos As Integer

        ' Remove spaces and the "i".
        string_value = string_value.Replace(" "c, "")
        string_value = string_value.ToLower.Replace("i"c, "")

        ' Find the + or - between the parts.
        Dim plus_or_minus() As Char = {"+"c, "-"c}
        pos = string_value.IndexOfAny(plus_or_minus)
        If pos = 0 Then
            ' Skip the leading +/-.
            pos = string_value.IndexOfAny(plus_or_minus, 1)
        End If

        ' Get the real and imaginary parts.
        m_RealPart = Single.Parse(string_value.Substring(0, pos))
        m_ImaginaryPart = Single.Parse(string_value.Substring(pos))
    End Sub

    ' Return the negative of a complex number.
    Public Shared Operator -(ByVal c1 As ComplexNumber) As ComplexNumber
        Return New ComplexNumber( _
            -c1.RealPart, _
            -c1.ImaginaryPart)
    End Operator

    ' Return the sum of two complex numbers.
    Public Shared Operator +(ByVal c1 As ComplexNumber, ByVal c2 As
ComplexNumber) As ComplexNumber
        Return New ComplexNumber( _
            c1.RealPart + c2.m_RealPart, _
            c1.ImaginaryPart + c2.m_ImaginaryPart)
    End Operator

    ' Return the difference between two complex numbers.
    Public Shared Operator -(ByVal c1 As ComplexNumber, ByVal c2 As
ComplexNumber) As ComplexNumber
        Return c1 + -c2
    End Operator

    ' Return Me * complex_number.
    Public Shared Operator *(ByVal c1 As ComplexNumber, ByVal c2 As
ComplexNumber) As ComplexNumber
        Dim re_part As Single = _
            c1.RealPart * c2.RealPart - _
            c1.ImaginaryPart * c2.ImaginaryPart
        Dim im_part As Single = _
            c1.RealPart * c2.ImaginaryPart + _
            c1.ImaginaryPart * c2.RealPart
        Return New ComplexNumber(re_part, im_part)
    End Operator

    ' Return a string representation of this number.
    Public Overrides Function ToString() As String
        ' Start with the real part.
        Dim result As String = m_RealPart.ToString()

        ' Add the imaginary part.
        If m_ImaginaryPart >= 0 Then
            result &= " + " & _
                m_ImaginaryPart.ToString() & _
                "i"
        Else
            result &= " - " & _
                (-m_ImaginaryPart).ToString() & _
                "i"
        End If

        Return result
    End Function
End Class

For more information on algorithms in Visual Basic, see my book <A
HREF="http://www.vb-helper.com/vba.htm">Ready-to-Run Visual Basic
Algorithms</A>.
==========
2. New HowTo: Get the values of fields (variables) declared in a form by
their names in Visual Basic .NET
http://www.vb-helper.com/howto_net_get_field_by_name.html
http://www.vb-helper.com/HowTo/howto_net_get_field_by_name.zip

When you select a field's name from the combo box, the program uses
GetField to get information about the field. It then uses IsArray to see
if the field is an array, and uses GetValue to get the field's value and
treat it appropriately.

Private private_value1 As String = "This is private value 1"
Private private_value2 As String = "This is private value 2"
Public public_value1 As String = "This is public value 1"
Public public_value2 As String = "This is public value 2"
Public arr1() As String = {"A", "B", "C"}
Public arr2() As String = {"1", "2", "3"}

Private Sub cboFields_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
cboFields.SelectedIndexChanged
    Dim field_info As FieldInfo = Me.GetType().GetField(cboFields.Text,
_
        BindingFlags.Instance Or BindingFlags.NonPublic Or
BindingFlags.Public)
    If field_info Is Nothing Then
        lblValue.Text = "<not found>"
    ElseIf field_info.FieldType.IsArray() Then
        ' Join the array values into a string.
        lblValue.Text = Join(field_info.GetValue(Me))
    Else
        ' Just convert it into a string.
        lblValue.Text = field_info.GetValue(Me).ToString()
    End If
End Sub
==========
3. New HowTo: Get information about the window under the mouse in Visual
Basic .NET
http://www.vb-helper.com/howto_net_get_window_under_mouse.html
http://www.vb-helper.com/HowTo/howto_net_get_window_under_mouse.zip

When the program's Timer ticks, the following code displays information
about the window under the mouse. It uses MousePosition to get the
mouse's location in screen coordinates. It calls the WindowFromPoint API
function to get the window's handle. It then calls function FindRoot to
find that window's root window. Finally it calls WindowText to gtet the
root window's text.

Private Sub tmrCheckMouse_Tick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles tmrCheckMouse.Tick
    Dim txt As String = ""

    txt &= "Position: " & MousePosition().ToString() & vbCrLf

    Dim window_handle As Integer = _
        WindowFromPoint(MousePosition.X, MousePosition.Y).ToString()
    txt &= "Window handle: " & window_handle & vbCrLf

    Dim root_handle As Integer = FindRoot(window_handle)
    txt &= "Root handle: " & root_handle & vbCrLf

    txt &= "Root text: " & vbCrLf & WindowText(root_handle) & vbCrLf

    lblInfo.Text = txt
End Sub

Function FindRoot calls the GetParent API function until the function
returns 0. At that point, the previous window is the root window.

' Return the window's root window.
Private Function FindRoot(ByVal hWnd As Int32) As Int32
    Do
        Dim parent_hwnd As Int32 = GetParent(hWnd)
        If parent_hwnd = 0 Then Return hWnd
        hWnd = parent_hwnd
    Loop
End Function

Function WindwoText uses the GetWindowTextLength function to see how
long the window's text is. It makes a StringBuilder large enough to hold
the text plus a null character after it. It then calls the GetWindowText
API function to get the text.

' Return the window's text.
Private Function WindowText(ByVal hWnd As Int32) As String
    If hWnd = 0 Then Return ""

    Dim text_len As Integer = GetWindowTextLength(hWnd)
    If text_len = 0 Then Return ""

    Dim sb As New System.Text.StringBuilder(text_len + 1)
    Dim ret = GetWindowText(hWnd, sb, sb.Capacity)
    If ret = 0 Then Return ""

    Return sb.ToString
End Function
==========
++++++++++
<Both>
++++++++++
==========
4. New HowTo: Use code to make a chart in Excel from the current
selection in VBA
http://www.vb-helper.com/howto_vba_excel_chart_from_selection.html
http://www.vb-helper.com/HowTo/howto_vba_excel_chart_from_selection.zip

The MakeGraph subroutine takes as a parameter a Range to use to build
the chart. You can pass it the Selection object to use the currently
selected values.

The subroutine creates a new worksheet and adds a chart to it. It adds
any labels that is was passed as parameters and then sizes the chart.

Public Sub MakeGraph(value_range As Range, Optional ByVal title As
String = "", Optional ByVal x_label As String = "", Optional ByVal
y_label As String = "")
Dim work_book As Workbook
Dim last_sheet As Worksheet
Dim new_sheet As Worksheet
Dim r As Integer
Dim new_chart As Chart
Dim chart_shape As Shape

    ' Make a new worksheet.
    Set work_book = Application.ActiveWorkbook
    Set last_sheet = work_book.Sheets(work_book.Sheets.Count)
    Set new_sheet = work_book.Sheets.Add(after:=last_sheet)
    new_sheet.Name = "New Chart"

    ' Make the chart.
    Set new_chart = Charts.Add()
    ActiveChart.ChartType = xlLineMarkers
    ActiveChart.SetSourceData _
        Source:=value_range, _
        PlotBy:=xlColumns
    ActiveChart.Location Where:=xlLocationAsObject, Name:="New Chart"

    ' Set the chart's title abd axis labels.
    With ActiveChart
        If Len(title) = 0 Then
            .HasTitle = False
        Else
            .HasTitle = True
            .ChartTitle.Characters.Text = title
        End If

        If Len(x_label) = 0 Then
            .Axes(xlCategory, xlPrimary).HasTitle = False
        Else
            .Axes(xlCategory, xlPrimary).HasTitle = True
            .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text =
x_label
        End If

        If Len(y_label) = 0 Then
            .Axes(xlValue, xlPrimary).HasTitle = False
        Else
            .Axes(xlValue, xlPrimary).HasTitle = True
            .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text =
y_label
        End If
    End With

    ' Make it bigger.
    Set chart_shape = new_sheet.Shapes(new_sheet.Shapes.Count)
    With chart_shape
        .ScaleWidth 1.9, msoFalse, msoScaleFromBottomRight
        .ScaleHeight 1.9, msoFalse, msoScaleFromBottomRight
        .Left = 20
        .Top = 20
    End With
End Sub
==========
5. New Links
http://www.vb-helper.com/links.htm

CareerJet.com
http://www.careerjet.com
U.S. job search engine. Seems to aggregate from a bunch of other job
sites.
==========
6. A Different Kind of Review

The Denver Visual Studio Users's Group is quite active in posting
reviews. Publishers give them free books and they review them. The
reviews are a bit more in-depth than what you often see on Amazon,
Barnes and Noble, and other online booksellers.

Here's the one for my book "Beginning Database Design Solutions":

    http://www.denvervisualstudio.net/Reviews/Books2009/Book04272009.htm

Recently they posted one about John Mueller's book "LINQ for Dummies"
at:

    http://www.denvervisualstudio.net/Reviews/Books2009/Book05102009.htm

They have lots of other reviews, too, (including a few about my books)
at:

    http://www.denvervisualstudio.net/Reviews.htm

If you want more detailed reviews, take a look at a few.
==========
7. New Article

DevX: WPF Wonders: An Alphabetical Compendium of WPF Controls
http://www.devx.com/dotnet/Article/41560
April 29, 2009

Among many other changes, WPF brings a completely new set of controls.
Learn which controls do what and pick up a few tips on getting the most
out of them in your WPF applications.

This article summarizes the most useful WPF controls. Some will be
familiar friends (TextBox, Label, Button) but others will be new
acquaintances (StackPanel, BulletDecorator, DocumentViewer).
==========
Archives:
    http://www.topica.com/lists/VBHelper
    http://www.topica.com/lists/VB6Helper
    http://www.topica.com/lists/VBNetHelper

Post questions at:
    http://www.topica.com/lists/VBHelperQA
	
 Previous Message All Messages Next Message 
  Check It Out!

  Topica Channels
 Best of Topica
 Art & Design
 Books, Movies & TV
 Developers
 Food & Drink
 Health & Fitness
 Internet
 Music
 News & Information
 Personal Finance
 Personal Technology
 Small Business
 Software
 Sports
 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.