Thứ Năm, 16 tháng 5, 2013

Code đọc số nguyên dương có 3 chữ số



Private Sub Command1_Click()
Dim a As String, b As String, c As String
Dim dv As Integer, chuc As Integer, tram As Integer
tram = Text1.Text \ 100
chuc = (Text1.Text Mod 100) \ 10
dv = (Text1.Text Mod 100) Mod 10
Select Case tram
Case 0
a = " "
Case 1
a = " Mét tr¨m "
Case 2
a = " Hai tr¨m "
Case 3
a = " Ba tr¨m "
Case 4
a = " Bèn tr¨m "
Case 5
a = " N¨m tr¨m "
Case 6
a = " S¸u tr¨m "
Case 7
a = " B¶y tr¨m "
Case 8
a = " T¸m tr¨m "
Case 9
a = " ChÝn tr¨m "
End Select
Select Case chuc
Case 0
If tram = 0 Then
b = ""
ElseIf tram <> 0 And dv = 0 Then
b = ""
Else
b = "linh "
End If
Case 1
b = "m­êi "
Case 2
b = "hai m­¬i "
Case 3
b = "ba m­¬i "
Case 4
b = "bèn m­¬i "
Case 5
b = "n¨m m­¬i "
Case 6
b = "s¸u m­¬i "
Case 7
b = "b¶y m­¬i "
Case 8
b = "t¸m m­¬i "
Case 9
b = "chÝn m­¬i "
End Select
Select Case dv
Case 0
c = ""
Case 1
If chuc = 0 Or chuc = 1 Then
c = "mét"
Else
c = "mèt"
End If
Case 2
c = "hai"
Case 3
c = "ba"
Case 4
c = "bèn"
Case 5
c = "n¨m"
Case 6
c = "s¸u"
Case 7
c = "b¶y"
Case 8
c = "t¸m"
Case 9
c = "chÝn"
End Select
Label2.Caption = a & b & c
End Sub

Private Sub Command2_Click()
Text1.Text = " "
Label2.Caption = " "
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
End If

End Sub





Code giải phương trình bậc 2




Private Sub Command1_Click()
Dim d As Single
d = b * b - 4 * a * c
If a = 0 Then
MsgBox ("PT co nghiem duy nhat ")
Text1.Text = -c / b
Else
If d < 0 Then
MsgBox (" PT vo nghiem")
ElseIf d = 0 Then
MsgBox ("PT co nghiem kep")
Text1.Text = -b / (2 * a)
Text2.Text = -b / (2 * a)
Else
MsgBox (" PT co 2 nghiem phan biet ")
Text1.Text = -b + Sqr(d) / 2 * a
Text2.Text = -b - Sqr(d) / 2 * a
End If
End If
End Sub


Private Sub Command2_Click()
a = " "
b = " "
c = " "
Text1.Text = " "
Text2.Text = " "

End Sub



Private Sub a_KeyPress(KeyAscii As Integer)
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
End If

End Sub


Private Sub b_KeyPress(KeyAscii As Integer)
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
End If

End Sub

Private Sub c_KeyPress(KeyAscii As Integer)
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
End If
End Sub





Thứ Ba, 14 tháng 5, 2013

code tính tuổi theo năm sinh của bạn




Private Sub Command1_Click()
Dim a As Byte, b As Byte, can As String, chi As String
a = Text1.Text Mod 10
b = Text1.Text Mod 12
Select Case a
Case 0
can = "Canh"
Case 1
can = "T©n"
Case 2
can = "Nh©m"
Case 3
can = "Quý"
Case 4
can = "Gi¸p"
Case 5
can = "Êt"
Case 6
can = "BÝnh"
Case 7
can = "§inh"
Case 8
can = "MËu"
Case 9
can = "Kû"
End Select
Select Case b
Case 0
chi = "Th©n"
Case 1
chi = "DËu"
Case 2
chi = "TuÊt"
Case 3
chi = "Hîi"
Case 4
chi = "Tý"
Case 5
chi = "Söu"
Case 6
chi = "DÇn"
Case 7
chi = "M·o"
Case 8
chi = "Th×n"
Case 9
chi = "Tþ"
Case 10
chi = "Ngä"
Case 11
chi = "Mïi"

End Select
Label2.Caption = "B¹n tuæi " & " " & can & " " & chi
End Sub

Thứ Năm, 9 tháng 5, 2013

Code so sánh Max Min


Private Sub Command1_Click()
Dim a As Long, b As Long, c As Long, LN As Long, NN As Long
a = Text1.Text
b = Text2.Text
c = Text3.Text
If a >= b Then
 LN = a
 NN = b
If c >= LN Then LN = c
If c <= NN Then NN = c
Text4.Text = LN
Text5.Text = NN
Else
 LN = b
 NN = a
If c >= LN Then LN = c
If c <= NN Then NN = c
Text4.Text = LN
Text5.Text = NN
End If
End Sub

Private Sub Command2_Click()
Text4.Text = " "
Text5.Text = " "
Text1.Text = " "
Text2.Text = " "
Text3.Text = " "
End Sub


Private Sub Text1_KeyPress(KeyAscii As Integer)
 ' ma Ascii cua 0 la 48, cua 9 la 57
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
End If
End Sub



Private Sub Text2_KeyPress(KeyAscii As Integer)
 ' ma Ascii cua 0 la 48, cua 9 la 57
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
End If
End Sub



Private Sub Text3_KeyPress(KeyAscii As Integer)
 ' ma Ascii cua 0 la 48, cua 9 la 57
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
End If
End Sub




code thiết kế lựa chọn check va option


de bai
thiet ke luc chon check va option )



Private Sub Check1_Click()
If Check1.Value = 1 Then
Label1.FontBold = True
Check4.Value = 0
Else
Check1.Value = 0
Label1.FontBold = False
End If
End Sub
Private Sub Check2_Click()
If Check2.Value = 1 Then
Label1.FontItalic = True
Check4.Value = 0
Else
Check1.Value = 0
Label1.FontItalic = False
End If
End Sub

Private Sub Check3_Click()
If Check3.Value = 1 Then
Label1.FontUnderline = True
Check4.Value = 0
Else
Check1.Value = 0
Label1.FontUnderline = False
End If
End Sub

Private Sub Check4_Click()
If Check4.Value = 1 Then
Check1.Value = 0
Check2.Value = 0
Check3.Value = 0
Label1.FontBold = False
Label1.FontItalic = False
Label1.FontUnderline = False
End If
End Sub

Private Sub Option1_Click()
If Option1.Value = True Then
Label1.ForeColor = vbRed
End If
End Sub

Private Sub Option2_Click()
If Option2.Value = True Then
Label1.ForeColor = &H8000000D
End If
End Sub

Private Sub Option3_Click()
If Option3.Value = True Then
Label1.ForeColor = vbYellow
End If
End Sub

Private Sub Option4_Click()
If Option4.Value = True Then
Label1.ForeColor = &H80000012
End If
End Sub

Kiem tra số chẵn số lẻ



" de bai " kiem tra so la so  chan hay so le

Private Sub Command1_Click()
Dim n As Integer
n = Text1.Text
If n Mod 2 = 1 Then
MsgBox ("so " & Text1.Text & " la so le ")
Text1.Text = " "
Else
MsgBox ("so " & Text1.Text & "  la so chan ")
Text1.Text = " "
End If
End Sub

Tính tổng 2 số


code " tinh tong 2 so "

Private Sub Command1_Click()
Dim a As Long, b As Long, c As Long
a = Text1.Text
b = Text2.Text
c = a + b
Text3.Text = c
End Sub
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End Sub