ໃນ Visual Basic 6 ມີ Built-in Functions , Funcrion ແມ່ນມີຄ້າຍຄື procedure ຈຸດປະສົງຫລັກຂອງ Function ແມ່ນ ຮັບຂໍ້ມູນຈາກ ຜູ້ໃຊ້ ແລະ ຄືນຄ່ານັ້ນອອກມາ
ໃນ Visual Basic 6 ມີ Built-in Functions ມີ 2 ແບບ
syntax:
FunctionName (arguments)
guments ເປັນຄ່າທີ່ ປ້ອນໃສ່ ແລະ ຜ່ານ Funcrion
ໃນບົດຮຽນນີ້ເຮົາຈະຮຽນສອງ Funcrion ຄື MsgBox( ) ແລະ InputBox ( )
1. MsgBox ( ) Function
ຮູບແບບໂຄ້ດ
yourMsg=MsgBox(Prompt, Style Value, Title)
ຄ່າຂອງ Style Value:
Image does not exist: https://image.ibb.co/gQyApF/Style_Values.png
ຕົວຢ່າງ:
yourMsg=MsgBox( "Click OK to Proceed", 1, "Startup Menu") and yourMsg=Msg("Click OK to Proceed". vbOkCancel,"Startup Menu")
yourMsg ແມ່ນຕົວປ່ຽນທີ່ຮັບຄ່າມາຈາກ MsgBox Function ຊື່ງຄ່າທີ່ໄດ້ຮັບມີຫລາຍຄ່າດັ່ງລຸ່ມນີ້
Image does not exist: https://image.ibb.co/mS1uzF/msgbox_return.png
ຕົວຢ່າງໂປຣແກຣມ
Image does not exist: https://image.ibb.co/j9vnKF/msgbox1.jpg
Private Sub Test_Click() Dim testmsg As Integer testmsg = MsgBox("Click to test", 1, "Test message") If testmsg = 1 Then Display.Caption = "Testing Successful" Else Display.Caption = "Testing fail" End If End Sub
ນອກນັ້ນຍັງມີ Named Constant ດັັ່ງລຸ່ມນີ້
Image does not exist: https://image.ibb.co/czGzYa/named_cons.png
ຕົວຢ່າງ
Private Sub test2_Click() Dim testMsg2 As Integer testMsg2 = MsgBox("Click to Test", vbYesNoCancel + vbExclamation, "TestMessage") If testMsg2 = 6 Then display2.Caption ="Testing successful" ElseIf testMsg2 = 7 Then display2.Caption = "Are you sure?" Else display2.Caption ="Testing fail" End If End Sub
ຜົນໄດ້ຮັບ
Image does not exist: https://image.ibb.co/d1XZzF/msgbox5_popup.jpg
2. The InputBox( ) Function
ແບບໂຄ້ດ
myMessage=InputBox(Prompt, Title, default_text, x-position, y-position)
Prompt - The message displayed normally as a question asked. Title - The title of the Input Box. default-text - The default text that appears in the input field where users can use it as his intended input or he may change to the message he wish to key in. x-position and y-position - the position or the coordinate of the input box.
ຕົວຢ່າງ:
Image does not exist: https://image.ibb.co/gACTRv/inputbox.jpg
Private Sub OK_Click() Dim userMsg As String userMsg = InputBox("What is your message?", "Message Entry Form", "Enter your messge here", 500, 700) If userMsg <>"" Then message.Caption = userMsg Else message.Caption = "No Message" End If End Sub
ເມື່ອເຮົາກົດ OK ຈະສະແດງຟອມນີ້
Image does not exist: https://image.ibb.co/cicOta/inputbox2.jpg