Thursday, September 14, 2017

ການນຳໃຊ້ String Manipulation Functions (VB6 Lesson 11)

ໃນບົດຮຽນນີ້ ເຮົາຈະແນະນຳການໃຊ້ String Manipulation Functions ເຊັ່ນ: Len, Right, Left, Mid, Trim, Ltrim, Rtrim, Ucase, Lcase, Instr, Val, Str ,Chr and Asc.

1. The Len Function
ເປັນການນັບເອົາລວງຍາວ ຫລື ຈຳນວນອັກສອນ ຕ່າງໆ
syntax:

Len (“Phrase”)

ຕົວຢ່າງ:

Len (VisualBasic) = 11 ແລະ Len (welcome to VB tutorial) = 22

2. The Right Function
ເປັນການເອົາຂໍ້ມູນອອກຈາກເບື້ອງຂວາ ໂດຍລະບຸ ຕຳແຫນ່ງທີ່ຕ້ອງການ
syntax:

Right (“Phrase”, n)

ຕົວຢ່າງ:

Right(“Visual Basic”, 4) = asic

3. The Left Function
ເປັນການເອົາຂໍ້ມູນອອກຈາກເບື້ອງຊ້າຍ ໂດຍລະບຸ ຕຳແຫນ່ງທີ່ຕ້ອງການ
syntax:

Left(“Phrase”, n)

ຕົວຢ່າງ:

Left (“Visual Basic”, 4) = Visu


4. The Ltrim Function
ເປັນການລົບຂໍ້ມູນວ່າງອອກຈາກເບື້ອງຊ້າຍ
syntax:

Ltrim(“Phrase”)

ຕົວຢ່າງ:

Ltrim (“  Visual Basic”, 4)= Visual basic

5. The Rtrim Function
ເປັນການລົບຂໍ້ມູນວ່າງອອກຈາກເບື້ອງຂວາ
syntax:

Rtrim(“Phrase”)

ຕົວຢ່າງ:

Rtrim (“Visual Basic      ”, 4) = Visual basic

6. The Trim function
ເປັນການລົບຂໍ້ມູນວ່າງອອກຈາກເບື້ອງຂວາ ແລະ ຂວາ
syntax:

Trim(“Phrase”)

ຕົວຢ່າງ:

Trim (“   Visual Basic      ”) = Visual basic

7. The Mid Function
ເປັນການເອົາຂໍ້ມູນອອກ ໂດຍກຳນົດຈຸດເລີ່ມ ແລະ ຈຸດສຸດທ້າຍ ທີ່ຕ້ອງການ
syntax:

Mid(phrase, position, n)

ຕົວຢ່າງ:

Mid(“Visual Basic”, 3, 6) = ual Bas

8. The InStr function
ເປັນການຄົ້ນຫາຂໍ້ມູນ ແລະ ຄືນຄ່າເປັນຕຳແໜ່ງທີ່ຄົ້ນພົບ
syntax:

Instr (n, original phase, embedded phrase)

ຊຶ່ງ n ເປັນຈຸດທີເລີ່ມຕົ້ນຂອງຂໍ້ມູນນັ້ນ
ຕົວຢ່າງ:

Instr(1, “Visual Basic”,” Basic”)=8

9. The Ucase and the Lcase functions
ເປັນການເອົາຕົວອັກສອນ ເປັນຕົວໃຫ້ ແລະ ນ້ອຍ
ຕົວຢ່າງ:

 Ucase(“Visual Basic”) =VISUAL BASIC
Lcase(“Visual Basic”) =visual basic

10. The Str and Val functions
Str ເປັນການແປງຈາກຕົວເລກເປັນຕົວອັກສອນຫນັງສື
Val ເປັນການແປງຈາກຕົວອັກສອນຫນັງສືເປັນຕົວເລກ
11. The Chr and the Asc functions
Chr ເປັນຕົວແປງຈາກລະຫັດ ອອກເປັນຕົວອັກສອນ
ຕົວຢ່າງ

Chr(65)=A, Chr(122)=z, Chr(37)=%

Asc ເປັນຕົວແປງຈາກຕົວອັກສອນ ອອກເປັນ ລະຫັດ ຕົວເລັກ
ຕົວຢ່າງ

Asc(“B”)=66, Asc(“&”)=38 

ມີຕົວຢ່າງໂປຣແກຣມ:

Private Sub CmdASC_Click()
               TxtASC.Text = Asc(TxtCHR.Text)
             End Sub
            Private Sub CmdCHR_Click()
              TxtCHR.Text = Chr(TxtASC.Text)
            End Sub

ອອກແບບຟອມ ແລະ ຜົນອອກ:
Image does not exist: https://image.ibb.co/gTjtw5/asc_converter.jpg

ແລະ ຕົວຢ່າງໂປຣແກຣມ ຄົ້ນຫາຄຳສັບ ໂດຍໃຊ້ InStr function

ໂຄ້ດ:

Private Sub cmdSearch_Click()
Dim n, m, l As Integer
Dim myAricle, myWord As String
myArticle = TxtArticle.Text
myWord = TxtWord.Text
l = Len(myWord)
n = InStr(1, myArticle, myWord)
If n = 0 Then
LblResult.Caption = "Your word not found, try again."
Else
LblResult.Caption = "Found your word " & myWord & " at " & " Position " & n
TxtArticle.SetFocus
TxtArticle.SelStart = n - 1
TxtArticle.SelLength = Len(myWord)
End If
End Sub

ອອກແບບຟອມ ແລະ ຜົນອອກ:
Image does not exist: https://image.ibb.co/kFXwG5/word_search.jpg

Subscribe

  • RSS Atom

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