2014年4月25日 星期五

Maze Sample




Public Class Form1
    Dim a(16, 16) As Integer
    Dim str1 = ""

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim fileContents As String
        fileContents = My.Computer.FileSystem.ReadAllText(Application.StartupPath & "\MData.txt")
        Dim lines() = Split(fileContents, vbNewLine)

        For i = 0 To 14
            Dim ba() = Split(lines(i), ",")
            For j = 0 To 14
                a(i + 1, j + 1) = ba(j)
            Next
        Next

        For i = 0 To 16
            a(0, i) = 2
            a(i, 0) = 2
            a(16, i) = 2
            a(i, 16) = 2
        Next

        showArray0()

        If visit(1, 1) Then
            showArray()
        Else
            MsgBox("NoPath")
        End If
        End
    End Sub

    Sub showArray0()
        Dim str3 = ""
        For i = 1 To 15
            For j = 1 To 15
                If Not a(i, j) = 2 Then
                    str3 = str3 & "○"
                Else
                    str3 = str3 & "●"
                End If
            Next
            str3 = str3 & vbNewLine
        Next
        MsgBox(str3)
    End Sub

    Sub showArray()
        Dim str3 = ""
        For i = 1 To 15
            For j = 1 To 15
                If a(i, j) = 1 Then
                    str3 = str3 & "○"
                Else
                    str3 = str3 & "●"
                End If
            Next
            str3 = str3 & vbNewLine
        Next
        MsgBox(str3)
    End Sub

    Function visit(ByVal i As Integer, ByVal j As Integer) As Boolean
        If a(15, 15) = 1 Then Return True
        If a(i, j) = 0 Then
            a(i, j) = 1
            ' Call showArray()
            If Not a(15, 15) = 1 And Not (visit(i + 1, j) Or visit(i, j + 1) Or visit(i - 1, j) Or visit(i, j - 1)) Then
                a(i, j) = 0
            End If
        End If
        Return a(15, 15) = 1

    End Function
End Class




2014年4月22日 星期二

Resurive Sample

'' 求1+3+5+ + 99 = ?
'Public Class Form1
'    Dim sumN = 0
'    Sub sum(sN, eN, stepN)
'        '判斷結束否
'        If sN > eN Then Return

'        '每次過程要做的事
'        sumN = sumN + sN

'        '往完成工作方向前進
'        sum(sN + stepN, eN, stepN)
'    End Sub

'    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'        Call sum(1, 100, 2)
'        MsgBox(sumN)
'    End Sub
'End Class

' 求1!+2!+3!+ + 10! = ?
'Public Class Form1
'    Dim sumN = 0
'    Sub sum(sN, eN, stepN)
'        '判斷結束否
'        If sN > eN Then Return

'        '每次過程要做的事
'        Dim tsum = 1
'        For i = 1 To sN
'            tsum = tsum * i
'        Next
'        sumN = sumN + tsum

'        '往完成工作方向前進
'        sum(sN + stepN, eN, stepN)
'    End Sub

'    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'        Call sum(1, 5, 1)
'        MsgBox(sumN)
'    End Sub
'End Class


'尋找最大值
'Public Class Form1
'    Dim maxValue = 0
'    Dim a() = {10, 200, 100, 50, 30}

'    Sub fMax(sN, eN)
'        '判斷結束否
'        If sN > eN Then Return

'        '每次過程要做的事
'        If a(sN) > maxValue Then maxValue = a(sN)

'        '往完成工作方向前進
'        fMax(sN + 1, eN)
'    End Sub

'    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'        Call fMax(0, a.Length - 1)
'        MsgBox(maxValue)
'    End Sub
'End Class

重覆排列


Public Class Form1
    Dim ans(19) As String
    Dim str1 = ""
    Dim inStr = ""
    Dim ctr = 0

    Sub enu(d, n, m)
        Dim i As Integer
        If d = n Then
            For i = 0 To n - 1
                str1 = str1 & ans(i) & " "
            Next
            str1 = str1 & vbNewLine
            ctr = ctr + 1
            Return
        End If
        For i = 1 To m
            ans(d) = Mid(inStr, i, 1)
            enu(d + 1, n, m)
        Next
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim n, m As Integer
        inStr = "ABc"
        n = 3
        m = Len(inStr)
        enu(0, n, m)
        MsgBox(str1 & vbNewLine & "共" & ctr & "個")
        End
    End Sub
End Class


2014年4月1日 星期二

Kill Process

'Kill process
Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Timer1.Interval = 5000
        Timer1.Enabled = True
    End Sub

    Sub killProcess(processName)
        Dim process1 As Process()
        process1 = Process.GetProcessesByName(processName)
        For Each proces As Process In process1
            proces.Kill()
        Next
    End Sub

    Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
        System.Diagnostics.Process.Start("iexplore")
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Call killProcess("iexplore")
        Call killProcess("mspaint")
    End Sub
End Class