Thursday, September 7, 2017

ການນຳໃຊ້ if ແລະ iff() function (VB6 Lesson 7)

ໃນບົດຮຽນກ່ອນ ພວກເຮົາໄດ້ຮຽນກ່ຽວກັບວິທີການຂຽນໂຄດໃນ Visual basic 6 ແຕ່ໃນບົດນີ້ແມ່ນຮຽນຮູ້ ກ່ຽວກັບ ການນຳໃຊ້ if ແລະ iff() function
1. Conditional Operators

ແມ່ນເຄື່ອງໝາຍສະແດງເຖິງເງື່ອນໄຊໜຶ່ງທີ່ໃຊ້ ໃນ Visual Basic 6
Image does not exist: https://image.ibb.co/hiZceF/vb6_operator.png

2. Logical Operators
ເປັນເງື່ອນໄຂເພີ່ມໃນ Visual Basic 6
Image does not exist: https://image.ibb.co/bZhPRv/Logical_Operators.png

3 ການໃຊ້ If…..Then…..Else ກັບ Operators

ຕົວຢ່າງແບບຂຽນໂຄດ

If conditions Then
VB expressions 
Else
VB expressions 
End If

ຂ້າງລຸ່ມນີ້ເປັນຕົວຢ່າງໂປຣແກຣມ ໃຊ້ If…..Then…..Else ກັບ Operators

Private Sub OK_Click()
Dim username, password As String
username = "John123"
password = "qwertyupi#@"
If UsrTxt.Text = username And pwTxt.Text = password Then
MsgBox ("Sign in sucessful")
ElseIf UsrTxt.Text <> username Or pwTxt.Text <> password Then
MsgBox ("Sign in failed")
End If
End Sub

ຜົນໄດ້ຮັບ
Image does not exist: https://image.ibb.co/hYWLYa/vb6fig7_1.jpg

4. ການໃຊ້ IIf() Function
ມີຮູບແບບໂຄດ

IIf(x, y, z)

IIF(x>y, expression 1, expression 2) function ຈະປະເມີນຄ່າຂອງ x ແລະ y, ຖ້າ x>y. ເມື່ອນັ້ນ expression 1 ເປັນ true, ຖ້າບໍ່ດັ່ງນັ້ນ expression 2 ແມ່ນ true ເໝືອນກັນ
ຕົວຢ່າງ:

Private Sub CmdNumeric_Click()
Dim x, y, a, b, ans As Double
x = InputBox("Enter a number")
y = InputBox("Enter another number")
a = Val(x)
b = Val(y)
ans = IIf(a < b, b - a, a * b)
MsgBox ans
End Sub
Private Sub CmdString_Click()
Dim A, B, C As String
A = InputBox("Enter a word")
B = InputBox("Enter another word")
C = IIf(A < B, A, B)
MsgBox C
End Sub

Image does not exist: https://image.ibb.co/eScSDa/iif1.jpg

Subscribe

  • RSS Atom

ອອນລາຍ: 1 | ມື້ນີ້: 13 | ວານນີ້: 25 | ທິດນີ້: 93 | ເດືອນນີ້: 872 | ປີນີ້: 11832 | ລວມ: 78935