วันจันทร์ที่ 1 กรกฎาคม พ.ศ. 2556

Job2




Private Sub comCal_Click()
amount = Val(txtQty.Text)
If optE.Value = True Then
price = 55 * amount
AddList optE.Caption
ElseIf optA.Value = True Then
price = 50 * amount
AddList optA.Caption
ElseIf optL.Value = True Then
price = 50 * amount
AddList optL.Caption
ElseIf optM.Value = True Then
price = 50 * amount
AddList optM.Caption
ElseIf optC.Value = True Then
price = 55 * amount
AddList optC.Caption
ElseIf optG.Value = True Then
price = 50 * amount
AddList optG.Caption
End If
 tprice = price
  lblAmt.Caption = tprice
        If price <> 0 Then
            sumprice = price + sumprice
            lblSubTotal.Caption = sumprice
        End If
        AddList1 lblAmt.Caption
          If tprice <> 0 Then
            sumdue = sumdue + 1
            lblTotal.Caption = sumdue
        End If
        comClear.Visible = True
        comCal.Visible = False
End Sub
-------------------------------------------------------------------------------------------------
Private Sub comClear_Click()
  comClear.Visible = False
  comCal.Visible = True
        optE.Value = False
        optA.Value = False
        optL.Value = False
        optM.Value = False
        optC.Value = False
        optG.Value = False
        txtQty.Text = ""
        lblAmt.Caption = ""
End Sub
--------------------------------------------------------------------------------------------------------
Private Sub comExit_Click()
a = MsgBox("you want to depart a program", [vbYesNo], "Exit")
        If a = vbYes Then
        Unload Me
                End If
End Sub
----------------------------------------------------------------------------------------------------------
Private Sub comNewOrde_Click()
         txtQty.Text = ""
        lblAmt.Caption = ""
        lblSubTotal.Caption = ""
        lblTotal.Caption = ""
         optE.Value = False
        optA.Value = False
        optL.Value = False
        optM.Value = False
        optC.Value = False
        optG.Value = False
        List1.Clear
        List2.Clear
End Sub
----------------------------------------------------------------------------------------------------------
Private Sub comSummary_Click()
  Dim i As Integer
                    Form3.lblListProduct.Caption = ""
                    For i = 0 To List1.ListCount
                    Form3.lblListProduct.Caption = Form3.lblListProduct.Caption & List1.List(i) & vbCrLf
                    Next i
                 
                    Dim j As Integer
                    Form3.lblPriceProduct.Caption = ""
                    For j = 0 To List2.ListCount
                    Form3.lblPriceProduct.Caption = Form3.lblPriceProduct.Caption & List2.List(j) & vbCrLf
                    Next j
                 
Form3.lblPricetotal.Caption = lblSubTotal.Caption
           Form3.Show
 End Sub
----------------------------------------------------------------------------------------------------------
 Sub AddList(msg As String)
 List1.AddItem msg
  End Sub
------------------------------------------------------------------------------------------------------------
  Sub AddList1(msg As String)
 List2.AddItem msg
  End Sub
-------------------------------------------------------------------------------------------------------

วันจันทร์ที่ 17 มิถุนายน พ.ศ. 2556

Job1


ให้นักศึกษา ออกแบบ หน้าจอ(Output) ดังนี้
จากนั้นให้เขียน Code ดังต่อไปนี้

-----------------------------------------------------------------
Private Sub comCancel_Click()
If MsgBox("คุณต้องการยกเลิกการทำงานหรือไม่", vbInformation + vbYesNo, "เดียวก่อนนะ...!!!") = vbYes Then
Unload Me
End If
End Sub
Private Sub comNew_Click()
    txtUser.Text = ""
    txtPass.Text = ""
    txtUser.SetFocus
End Sub
 ----------------------------------------------------------------
Private Sub comOK_Click()
txtUser.SetFocus
Static count As Integer
Const password As String = "1234"

If txtPass.Text = password Then
MsgBox "สวัสดีคุณ " & txtUser.Text & vbCrLf & "รหัสผ่านของคุณถูกต้อง"
Form2.Show
Unload Me
ElseIf count = 2 Then
MsgBox "ป้อนรหัสผิด 3 ครั้ง ออกจากโปรแกรม", vbOKOnly, "แจ้งความผิดพลาด"
Unload Me
Else
count = count + 1
MsgBox "ป้อนรหัสผิดครั้งที่" & count, vbOKOnly, "เตือน"
End If
End Sub
-----------------------------------------------------------------
Private Sub Form_Load()
txtUser.Text = ""
txtPass.Text = ""
End Sub
 ----------------------------------------------------------------
Private Sub txtPass_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then Call comOK_Click
End Sub
---------------------------------------------------------------------------