2009年1月30日 星期五

麗山50題之15

image

image 

image 

 image

Public Class Form1
    Function checkid(ByVal perID As String) As Boolean
        Dim engarray As String
        Dim peridtemp As Integer
        Dim peridchk1, peridchk2, peridchksum As Integer
        Dim loops As Integer
        engarray = "ABCDFGHJKLMNPQRSTUVXYWZIO"
        peridtemp = InStr(1, engarray, Microsoft.VisualBasic.Left(perID, 1)) + 9
        peridchk1 = (peridtemp \ 10) + (peridtemp Mod 10) * 9
        For loops = 2 To 9
            peridchk2 = peridchk2 + Val(Mid(perID, loops, 1)) * (10 - loops)
        Next
        peridchksum = Val(Microsoft.VisualBasic.Right(perID, 1))
        If (peridchk1 + peridchk2 + peridchksum) Mod 10 = 0 Then
            checkid = True
        Else
            checkid = False
        End If
    End Function
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Len(TextBox1.Text) = 10 Then
            If checkid(UCase(TextBox1.Text)) Then
                Label2.Text = "這是一個正確的身分證號碼"
            Else
                Label2.Text = "這是一個錯誤的身分證號碼"
            End If
        Else
            Label2.Text = "身分證號碼需要10碼"
            TextBox1.Text = ""
        End If
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        End
    End Sub
End Class

99-47



Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox3.Text = Val(TextBox1.Text) + Val(TextBox2.Text)
End Sub
End Class

2009年1月29日 星期四

99-27

image

image

image

 

image 

'27.將輸入字串轉換為對應之整數輸出。如輸入 1234567abcd,則輸出234567。
'若輸入 a12345,則輸出 0。
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox2.Text = Val(TextBox1.Text)
    End Sub
End Class

2009年1月27日 星期二

99-15

image

 

'15.列出九九乘法表。
Public Class Form1
    Dim i, j As Integer
    Dim s, w As String
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        For i = 1 To 9
            For j = 1 To 9
                s = s & j & "*" & i & "=" & Format(i * j, "0#") & "   "
                w = s & j & "*" & i & "=" & Format(i * j, "0#") & "   "
            Next
            TextBox1.Text = w & vbNewLine
        Next
        TextBox1.Text = s & vbNewLine
    End Sub
End Class

99-48

image

image 

'48.計算兩個相當長之整數的乘積,如 1234567890123 * 1234567890123。
Public Class Form1
    Dim a, b As Long
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        a = Val(TextBox1.Text)
        b = Val(TextBox2.Text)
        TextBox3.Text = a * b
    End Sub
End Class

2009年1月26日 星期一

99-47





'47.計算兩個相當長之整數的和,

'如:12345678901234567890 + 12345678901234567890。

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

TextBox3.Text = Val(TextBox1.Text) + Val(TextBox2.Text)

End Sub

End Class

2009年1月23日 星期五

99-9





Public Class Form1
Dim i, n
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
n = Val(TextBox1.Text)
For i = 1 To n
If i Mod 13 = 0 Then
TextBox2.Text = TextBox2.Text & i & " "
End If
Next
End Sub
End Class

2009年1月22日 星期四

彰商程式設計隊的99題練習題(4.輸入四個數字,找出最大與最小值。)

 

image

image

image

 

程式碼

Public Class Form1
    Dim a, b, c, d
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        a = Val(TextBox1.Text)
        b = Val(TextBox2.Text)
        c = Val(TextBox3.Text)
        d = Val(TextBox4.Text)
        If a > b And a > c And a > d Then
            TextBox1.ForeColor = Color.Red
        ElseIf b > a And b > c And b > d Then
            TextBox2.ForeColor = Color.Red
        ElseIf c > a And c > b And c > d Then
            TextBox3.ForeColor = Color.Red
        Else
            TextBox4.ForeColor = Color.Red
        End If

        If a < b And a < c And a < d Then
            TextBox1.ForeColor = Color.Green
        ElseIf b < a And b < c And b < d Then
            TextBox2.ForeColor = Color.Green
        ElseIf c < a And c < b And c < d Then
            TextBox3.ForeColor = Color.Green
        Else
            TextBox4.ForeColor = Color.Green
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TextBox1.Clear()
        TextBox2.Clear()
        TextBox3.Clear()
        TextBox4.Clear()

        TextBox1.ForeColor = Color.Black
        TextBox2.ForeColor = Color.Black
        TextBox3.ForeColor = Color.Black
        TextBox4.ForeColor = Color.Black
    End Sub
End Class

2009年1月21日 星期三

廬山99-7 : 計算 1 + 2 + ... + n = ﹖




Public Class Form1
Dim n, i, s
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
n = Val(TextBox1.Text)
For i = 1 To n
s = s + i
Next
TextBox2.Text = s
End Sub
End Class

彰商程式設計隊的99題練習題(1.將輸入之秒數轉換成「時:分:秒」)

image

image

image

 

程式碼

Public Class Form1
    Dim a As Single
    Dim s As Long
    Dim m As Long
    Dim m1 As Long
    Dim h As Long
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        a = Val(TextBox1.Text)
        If a Mod 60 > 0 Then
            s = a Mod 60
        End If
        m1 = a \ 60
        h = m1 \ 60
        m = m1 Mod 60
        TextBox2.Text = h
        TextBox3.Text = m
        TextBox4.Text = s
    End Sub
End Class

假如哪裡的程式有問題    請告訴我一聲 哪裡需要再改進  謝謝!

2009年1月14日 星期三

公佈聖誕樹答案

For t = 1 To 8 '此最外回圈是控制聖誕樹的層數
  For i = 1 + e To 7 + s Step 2 '此第二迴圈聖誕樹是控制每層聖誕樹的高(每個梯形的行數)
    For j = 1 To i '此最內迴圈是控制每行要印出幾個"*"
      c = c & "*"
    Next j
    Print Space(35 - i); c
    c = ""
  Next i
  e = e + 3
  s = s + 4
Next t
For i = 1 To 7 '此回圈是樹幹
  Print Space(35 - 8); "********"
Next i

 

此程式碼的版本是 VB6 的 再2008或2005是無法執行的

請利用這個邏輯改寫成VB2008的寫法吧

 

另外沒有上寒期輔導,但在寒輔期間想要進行「程式設計的特別訓練」的人

可以找我 我是上一屆 程式設計的選手  我會到學校指導你們

有意願者請加我的及時通吧  anemo8083

液晶顯示器

image

(範例:我現在擷取這個畫面的電腦時間是 PM 5點58分24秒)

請做出一個液晶顯示器

他會自動抓電腦的時間 每秒做更新!!!

99-6

'6.輸入 A, B, C,求 AX^2 + BX + C = 0 的解。
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        '測試資料

        'Dim a = 4
        'Dim b = -5
        'Dim c = 1

        '輸入資料
        Dim a = InputBox("a=")
        Dim b = InputBox("b=")
        Dim c = InputBox("c=")
        If b ^ 2 - 4 * a * c < 0 Then
            MsgBox("無實數解")
        Else
            Dim x1 = (-b + (b ^ 2 - 4 * a * c) ^ 0.5) / (2 * a)
            Dim x2 = (-b - (b ^ 2 - 4 * a * c) ^ 0.5) / (2 * a)
            MsgBox("解為:" & x1 & "," & x2)
        End If
    End Sub
End Class

image

99-5

'5.輸入西元年數,判斷其是否為閏年。
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim a = InputBox("請輸入一個西元年如2008")
        If a Mod 4 = 0 And a Mod 100 <> 0 Or a Mod 400 = 0 Then
            MsgBox(a & "是潤年")
        Else
            MsgBox(a & "不是潤年")
        End If
    End Sub
End Class

image

99-4

'4.輸入四個數字,找出最大與最小值。
'假設輸入 2,5,3,4
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim a(4) As Integer
        For i = 1 To 4
            Dim pStr = "請輸入第" & i & "個數字"
            a(i) = InputBox(pStr)
        Next

        Dim aMax = a(1)
        Dim aMin = a(1)
        For i = 2 To 4
            If a(i) > aMax Then aMax = a(i)
            If a(i) < aMin Then aMin = a(i)
        Next
        MsgBox("最大值為:" & aMax & vbNewLine & "最小值為:" & aMin)
    End Sub
End Class

image

99-3

'3.產生輸入字元相對應之 ASCII 碼。
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim inChar As String
        inChar = InputBox("請輸入一個字元")
        MsgBox(Asc(inChar))
    End Sub
End Class

image

image

99-2

'2.計算兩個時間 (時:分:秒) 的間隔秒數。
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim t1 = #1/14/2009 2:32:00 PM#
        Dim t2 = Now
        MsgBox((t2 - t1).TotalSeconds)
    End Sub
End Class

image

2009年1月12日 星期一

時分秒

---------------------------
第一題    時分秒
---------------------------
2:46:40
---------------------------
確定  
---------------------------

↑圖出不來

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim t = 10000
        Dim sec = t Mod 60
        Dim minute = t \ 60 Mod 60
        Dim hour = t \ 3600
        MsgBox(hour & ":" & minute & ":" & sec)
    End Sub
End Class

麗山50題之2

image

image 

image

image

image

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Button2.Enabled = True
        Button1.Enabled = False
        Dim a, b, c As Integer
        a = 0
        b = 1
        Do
            c = InputBox("輸入第" & a + 1 & "筆", "輸入對話框")
            If c <> 0 Then
                b = b * c
                a = a + 1
            End If
        Loop Until c = 0
        TextBox1.Text = a
        TextBox2.Text = b
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Button1.Enabled = True
        Button2.Enabled = False
        End
    End Sub
End Class

2009年1月9日 星期五

聖誕樹

 

image

請利用迴圈寫出一個聖誕樹

廬山99-1

image

Public Class Form1
    Dim h, m, s
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim t = 10000
        h = t \ 3600
        m = t \ 60 Mod 60
        s = t Mod 60
        MsgBox(h & ":" & m & ":" & s)
    End Sub
End Class

hello 試貼

image

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        MsgBox("hello")
    End Sub
End Class

hi !

"hello"

image

Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        MsgBox("hello")
    End Sub
End Class

Hello

image 

Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        MsgBox("hello")
    End Sub
End Class

Hello!的程式

 

image

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        MsgBox("hello!")
    End Sub
End Class

試貼hello程式

image 

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        MsgBox("hello")
    End Sub
End Class

99-1

image

'1.將輸入之秒數轉換成「時:分:秒」。如輸入 10000,則輸出 02:46:40

Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim t = 10000
        Dim sec = t Mod 60
        Dim minute = t \ 60 Mod 60
        Dim hour = t \ 3600
        MsgBox(hour & ":" & minute & ":" & sec)
    End Sub
End Class

試貼Hello

image

Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        MsgBox("Hello")
    End Sub
End Class

試貼Hello程式

image 

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        MsgBox("hello")
    End Sub
End Class

2009年1月8日 星期四

vblearn123臨時帳號

正式帳號未開通前可用的臨時帳號

臨時帳號: vblearn123 密碼:vblearn321

類別請填入: 班級座號姓名,如 20156王小明 
(類別僅需新增一次,第二次直接選取即可)

 

image

2009年1月7日 星期三

4取3組合

Module Module1

    Sub Main()
        Dim a1() As String = {"A", "B", "C", "D"}
        Dim i = 0
        For Each elem1 In a1
            For Each elem2 In a1
                For Each elem3 In a1
                    If elem1 < elem2 And elem2 < elem3 Then
                        i = i + 1
                        Console.WriteLine(i & ":" & elem1 & elem2 & elem3)
                    End If
                Next
            Next
        Next
        Console.Read()
    End Sub

End Module

 

image

副程式例2

Public Class Form1

    '主程式
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        MsgBox(ymoney(10, "大學", "主管"))
        MsgBox(ymoney(2, "大學", "職員"))
    End Sub

    '函式
    Function ymoney(ByVal yy, ByVal gr, ByVal pr)
        If yy < 5 Then
            ymoney = 3000
        Else
            ymoney = 5000
        End If
        If gr = "大學" Then
            ymoney = ymoney + 5000
        Else
            ymoney = ymoney + 2000
        End If
        If pr = "主管" Then
            ymoney = ymoney + 10000
        End If
    End Function
End Class

image