2009年6月15日 星期一

副程式例

'副程式例
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '氣泡排序 
        Dim a() = {95, 90, 98, 92, 96} 
        sortIt(a) 
        printIt(a)

        Dim b() = {95, 90, 98, 92, 96, 87, 90, 98, 92, 96, 87, 90, 98, 92, 96, 87, 90, 98, 92, 96, 87, 90, 98, 92, 96, 87, 90, 98, 92, 96, 87} 
        sortIt(b) 
        printIt(b)

        Dim c() = {95, 90} 
        sortIt(c) 
        printIt(c)

        Dim a() = {95, 90, 98, 92, 96}
        selSortIt(a)
        printIt(a)

        Dim b() = {95, 90, 98, 92, 96, 87, 90, 98, 92, 96, 87, 90, 98, 92, 96, 87, 90, 98, 92, 96, 87, 90, 98, 92, 96, 87, 90, 98, 92, 96, 87}
        selSortIt(b)
        printIt(b)

        Dim c() = {95, 90}
        selSortIt(c)
        printIt(c)
    End Sub

    Sub sortIt(ByVal a)
        Dim i, j
        For j = 0 To a.length - 1 - 1
            For i = 0 To a.length - 1 - 1
                If a(i) > a(i + 1) Then
                    change(a(i), a(i + 1))
                End If
            Next
        Next
    End Sub

    Sub selSortIt(ByVal a)
        Dim i, j
        For j = 0 To a.length - 1 - 1
            For i = j + 1 To a.length - 1
                If a(j) > a(i) Then
                    change(a(j), a(i))
                End If
            Next
        Next
    End Sub

    Sub change(ByRef x, ByRef y)
        Dim t = x
        x = y
        y = t
    End Sub

    Sub printIt(ByVal a)
        Dim i
        Dim str1 = ""
        For i = 0 To a.length - 1
            str1 = str1 & a(i) & " "
        Next
        MsgBox(str1)
    End Sub
End Class

2009年6月4日 星期四

電子通訊錄地圖版

image

image

image

Public Class Form1

    Private Sub 聯絡資料BindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 聯絡資料BindingNavigatorSaveItem.Click
        Me.Validate()
        Me.聯絡資料BindingSource.EndEdit()
        Me.聯絡資料TableAdapter.Update(Me.Db1DataSet.聯絡資料)

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: 這行程式碼會將資料載入 'Db1DataSet.聯絡資料' 資料表。您可以視需要進行移動或移除。
        Me.聯絡資料TableAdapter.Fill(Me.Db1DataSet.聯絡資料)
        Label1.Text = "點按圖形可改變圖片大小"
        Label1.ForeColor = Color.Red
    End Sub

    Private Sub 地圖PictureBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 地圖PictureBox.Click
        If 地圖PictureBox.SizeMode = PictureBoxSizeMode.CenterImage Then
            地圖PictureBox.SizeMode = PictureBoxSizeMode.StretchImage
        Else
            地圖PictureBox.SizeMode = PictureBoxSizeMode.CenterImage
        End If
    End Sub

End Class