Hỏi về hàm InStr khi tìm chuỗi Unicode trong chuỗi Unicode

namvh

Thành viên mới

Các bác cho hỏi: ở file trên, với code VBA như sau:
Mã:
Sub timChuoi()

    s = UniConvert("Tuwf")

    [c1] = InStr([a1], s)

    [c2] = InStr([a2], s)

End Sub

Public Function UniConvert(Text As String) As String

  Dim Telex_Type, CharCode, Temp, i As Long

  UniConvert = Text

  Telex_Type = Array("aws", "awf", "awr", "awx", "awj", "aas", "aaf", "aar", "aax", "aaj", "ees", _

      "eef", "eer", "eex", "eej", "oos", "oof", "oor", "oox", "ooj", "ows", "owf", "owr", "owx", _

      "owj", "uws", "uwf", "uwr", "uwx", "uwj", "as", "af", "ar", "ax", "aj", "aw", "aa", "dd", _

      "es", "ef", "er", "ex", "ej", "ee", "is", "if", "ir", "ix", "ij", "os", "of", "or", "ox", _

      "oj", "oo", "ow", "us", "uf", "ur", "ux", "uj", "uw", "ys", "yf", "yr", "yx", "yj")

  CharCode = Array(ChrW(7855), ChrW(7857), ChrW(7859), ChrW(7861), ChrW(7863), ChrW(7845), ChrW(7847), _

      ChrW(7849), ChrW(7851), ChrW(7853), ChrW(7871), ChrW(7873), ChrW(7875), ChrW(7877), ChrW(7879), _

      ChrW(7889), ChrW(7891), ChrW(7893), ChrW(7895), ChrW(7897), ChrW(7899), ChrW(7901), ChrW(7903), _

      ChrW(7905), ChrW(7907), ChrW(7913), ChrW(7915), ChrW(7917), ChrW(7919), ChrW(7921), ChrW(225), _

      ChrW(224), ChrW(7843), ChrW(227), ChrW(7841), ChrW(259), ChrW(226), ChrW(273), ChrW(233), ChrW(232), _

      ChrW(7867), ChrW(7869), ChrW(7865), ChrW(234), ChrW(237), ChrW(236), ChrW(7881), ChrW(297), ChrW(7883), _

      ChrW(243), ChrW(242), ChrW(7887), ChrW(245), ChrW(7885), ChrW(244), ChrW(417), ChrW(250), ChrW(249), _

      ChrW(7911), ChrW(361), ChrW(7909), ChrW(432), ChrW(253), ChrW(7923), ChrW(7927), ChrW(7929), ChrW(7925))

  Temp = Telex_Type

  For i = 0 To UBound(CharCode)

    UniConvert = Replace(UniConvert, Temp(i), CharCode(i))

    UniConvert = Replace(UniConvert, UCase(Temp(i)), UCase(CharCode(i)))

  Next i

End Function
Khi chạy sub timChuoi thì ô [c1] là 0, ô [c2] là 1; tại sao lại như vậy?
Tks & Brgds.
 
Sửa lần cuối:

Ngày Mới

SMod
Thành viên BQT
Lưu ý với bạn: Code phải được đặt trong thẻ code, không code vào Excel rồi paste lên như vậy.

Về chủ đề, Tôi kiểm tra thì thấy chữ "ừ" trong chữ "Từ" tại ô [A1] của bạn thật ra là chữ "ư" và một kí tự đặc biệt " ̀ ". Bằng chứng là khi bạn xoá từ từ, bạn sẽ thấy chữ "ừ" xoá thành chữ "ư". Do đó, Code xác định tại ô [A1] của bạn là chữ "Tư" và kí tự " ̀ "nên sẽ cho ra kết quả 0 tại ô [C1].
 
Sửa lần cuối:

namvh

Thành viên mới
Cảm ơn bác.
Newbie nên chưa phân biệt đc thẻ code & icode của 4rum, bác thông cảm.
Bác kiểm tra = mắt hay công cụ gì mà phát hiện được:
chữ "ừ" trong chữ "Từ" tại ô [A1] của bạn thật ra là chữ "ư" và một kí tự đặc biệt " ̀ "
?
Khi xóa từ từ chữ "Từ" ở ô [a1] (xóa từ phải sang trái - backspace), Excel 2016 sẽ xóa 1 phát hết chữ "ừ" luôn chứ không phải xóa dấu huyền trước như bác nói.
Còn ô [a2], trông bằng mắt thường thì chữ "Từ" ở ô [a2] cũng giống với ô [a1], chỉ khác ở format chữ.
Tks & Brgds.
 
Sửa lần cuối:

Ngày Mới

SMod
Thành viên BQT
Bạn đổi sang font Yu là thấy nó khác biệt ngay.

Bạn cần đăng nhập để thấy hình ảnh
 

NhanSu

Thành Viên Nổi Bật

Chữ "ừ" mà xóa lần đầu thành ư là font unicode tổ hợp. Font unicode hay sử dụng là loại unicode dựng sẵn.
 

namvh

Thành viên mới
Như vậy theo các bác, có cách nào để phát hiện chữ "Từ" trong chuỗi có font unicode tổ hợp? (tại vì có những người hay dùng unicode tổ hợp nên họ tạo ra rất nhiều file - dữ liệu dùng dạng unicode này; hiện đang phải xử lý các file đó của họ; có lẽ 1 trong các yêu cầu của họ là không được thay đổi định dạng unicode - thay font)
 

Ngày Mới

SMod
Thành viên BQT
@namvh Bạn dùng Function bên dưới để chuyển chuỗi từ Unicode tổ hợp sang Unicode dựng sẳn.
Cấu trúc hàm: SourceToDest(Chuỗi tổ hợp, 1, 1)
Lưu ý, Code này không phải của tôi.
Mã:
Public Enum convert_dest
    dst_uni = 1
    dst_vni = 2
    dst_vn3 = 3
    dst_windows1258 = 4
    dst_khongdau = 5
End Enum

Public Enum convert_source
    src_uni = 1
    src_vni = 2
    src_vn3 = 3
    src_windows1258 = 4
End Enum

Private Const s_khong_dau As String = "aaAAdDeEooOOuUaaaaaaaaaaaaaaaAAAAAAAAAAAAAAAeeeeeeeeeeEEEEEEEEEEiiiiiIIIIIoooooooooooooooOOOOOOOOOOOOOOOuuuuuuuuuuUUUUUUUUUUyyyyyYYYYY"

Private s_dung_san As String, s_to_hop As String, s_vni As String, s_vn3 As String, s_windows1258 As String
Private sort_dung_san As String, sort_vni As String, sort_vn3 As String


Private Sub InitVietnameseStr()
Dim k As Long, a() As Byte
Dim dungsan_bytes(), tohop_bytes(), vni_bytes(), vn3_bytes(), windows1258_bytes()
Dim sort_dungsan_bytes(), sort_vn3_bytes(), sort_vni_bytes()

If Len(s_dung_san) > 0 Then Exit Sub

dungsan_bytes = Array(226, 0, 3, 1, 194, 0, 2, 1, 17, 1, 16, 1, 234, 0, 202, 0, 161, 1, 244, 0, 160, 1, 212, 0, 176, 1, _
175, 1, 224, 0, 163, 30, 227, 0, 225, 0, 161, 30, 167, 30, 169, 30, 171, 30, 165, 30, 173, 30, _
177, 30, 179, 30, 181, 30, 175, 30, 183, 30, 192, 0, 162, 30, 195, 0, 193, 0, 160, 30, 166, 30, _
168, 30, 170, 30, 164, 30, 172, 30, 176, 30, 178, 30, 180, 30, 174, 30, 182, 30, 232, 0, 187, _
30, 189, 30, 233, 0, 185, 30, 193, 30, 195, 30, 197, 30, 191, 30, 199, 30, 200, 0, 186, 30, 188, _
30, 201, 0, 184, 30, 192, 30, 194, 30, 196, 30, 190, 30, 198, 30, 236, 0, 201, 30, 41, 1, 237, 0, _
203, 30, 204, 0, 200, 30, 40, 1, 205, 0, 202, 30, 242, 0, 207, 30, 245, 0, 243, 0, 205, 30, 221, _
30, 223, 30, 225, 30, 219, 30, 227, 30, 211, 30, 213, 30, 215, 30, 209, 30, 217, 30, 210, 0, _
206, 30, 213, 0, 211, 0, 204, 30, 220, 30, 222, 30, 224, 30, 218, 30, 226, 30, 210, 30, 212, 30, _
214, 30, 208, 30, 216, 30, 249, 0, 231, 30, 105, 1, 250, 0, 229, 30, 235, 30, 237, 30, 239, 30, _
233, 30, 241, 30, 217, 0, 230, 30, 104, 1, 218, 0, 228, 30, 234, 30, 236, 30, 238, 30, 232, 30, _
240, 30, 243, 30, 247, 30, 249, 30, 253, 0, 245, 30, 242, 30, 246, 30, 248, 30, 221, 0, 244, 30)

tohop_bytes = Array(226, 0, 3, 1, 194, 0, 2, 1, 17, 1, 16, 1, 234, 0, 202, 0, 161, 1, 244, 0, _
160, 1, 212, 0, 176, 1, 175, 1, 97, 0, 0, 3, 97, 0, 9, 3, 97, 0, 3, 3, 97, 0, 1, 3, 97, 0, 35, 3, 226, 0, _
0, 3, 226, 0, 9, 3, 226, 0, 3, 3, 226, 0, 1, 3, 226, 0, 35, 3, 3, 1, 0, 3, 3, 1, 9, 3, 3, 1, 3, 3, 3, 1, 1, 3, _
3, 1, 35, 3, 65, 0, 0, 3, 65, 0, 9, 3, 65, 0, 3, 3, 65, 0, 1, 3, 65, 0, 35, 3, 194, 0, 0, 3, 194, 0, 9, 3, 194, _
0, 3, 3, 194, 0, 1, 3, 194, 0, 35, 3, 2, 1, 0, 3, 2, 1, 9, 3, 2, 1, 3, 3, 2, 1, 1, 3, 2, 1, 35, 3, 101, 0, 0, _
3, 101, 0, 9, 3, 101, 0, 3, 3, 101, 0, 1, 3, 101, 0, 35, 3, 234, 0, 0, 3, 234, 0, 9, 3, 234, 0, 3, 3, 234, 0, _
1, 3, 234, 0, 35, 3, 69, 0, 0, 3, 69, 0, 9, 3, 69, 0, 3, 3, 69, 0, 1, 3, 69, 0, 35, 3, 202, 0, 0, 3, 202, 0, _
9, 3, 202, 0, 3, 3, 202, 0, 1, 3, 202, 0, 35, 3, 105, 0, 0, 3, 105, 0, 9, 3, 105, 0, 3, 3, 105, 0, 1, 3, _
105, 0, 35, 3, 73, 0, 0, 3, 73, 0, 9, 3, 73, 0, 3, 3, 73, 0, 1, 3, 73, 0, 35, 3, 111, 0, 0, 3, 111, 0, 9, 3, _
111, 0, 3, 3, 111, 0, 1, 3, 111, 0, 35, 3, 161, 1, 0, 3, 161, 1, 9, 3, 161, 1, 3, 3, 161, 1, 1, 3, 161, 1, _
35, 3, 244, 0, 0, 3, 244, 0, 9, 3, 244, 0, 3, 3, 244, 0, 1, 3, 244, 0, 35, 3, 79, 0, 0, 3, 79, 0, 9, 3, 79, 0, _
3, 3, 79, 0, 1, 3, 79, 0, 35, 3, 160, 1, 0, 3, 160, 1, 9, 3, 160, 1, 3, 3, 160, 1, 1, 3, 160, 1, 35, 3, 212, _
0, 0, 3, 212, 0, 9, 3, 212, 0, 3, 3, 212, 0, 1, 3, 212, 0, 35, 3, 117, 0, 0, 3, 117, 0, 9, 3, 117, 0, 3, 3, _
117, 0, 1, 3, 117, 0, 35, 3, 176, 1, 0, 3, 176, 1, 9, 3, 176, 1, 3, 3, 176, 1, 1, 3, 176, 1, 35, 3, 85, 0, _
0, 3, 85, 0, 9, 3, 85, 0, 3, 3, 85, 0, 1, 3, 85, 0, 35, 3, 175, 1, 0, 3, 175, 1, 9, 3, 175, 1, 3, 3, 175, 1, _
1, 3, 175, 1, 35, 3, 121, 0, 0, 3, 121, 0, 9, 3, 121, 0, 3, 3, 121, 0, 1, 3, 121, 0, 35, 3, 89, 0, 0, 3, 89, _
0, 9, 3, 89, 0, 3, 3, 89, 0, 1, 3, 89, 0, 35, 3)

vni_bytes = Array(97, 0, 226, 0, 97, 0, 234, 0, 65, 0, 194, 0, 65, 0, 202, 0, 241, 0, 32, 0, 209, 0, _
32, 0, 101, 0, 226, 0, 69, 0, 194, 0, 244, 0, 32, 0, 111, 0, 226, 0, 212, 0, 32, 0, 79, 0, 194, 0, _
246, 0, 32, 0, 214, 0, 32, 0, 97, 0, 248, 0, 97, 0, 251, 0, 97, 0, 245, 0, 97, 0, 249, 0, 97, 0, 239, 0, _
97, 0, 224, 0, 97, 0, 229, 0, 97, 0, 227, 0, 97, 0, 225, 0, 97, 0, 228, 0, 97, 0, 232, 0, 97, 0, 250, 0, _
97, 0, 252, 0, 97, 0, 233, 0, 97, 0, 235, 0, 65, 0, 216, 0, 65, 0, 219, 0, 65, 0, 213, 0, 65, 0, 217, 0, _
65, 0, 207, 0, 65, 0, 192, 0, 65, 0, 197, 0, 65, 0, 195, 0, 65, 0, 193, 0, 65, 0, 196, 0, 65, 0, 200, 0, _
65, 0, 218, 0, 65, 0, 220, 0, 65, 0, 201, 0, 65, 0, 203, 0, 101, 0, 248, 0, 101, 0, 251, 0, 101, 0, _
245, 0, 101, 0, 249, 0, 101, 0, 239, 0, 101, 0, 224, 0, 101, 0, 229, 0, 101, 0, 227, 0, 101, 0, _
225, 0, 101, 0, 228, 0, 69, 0, 216, 0, 69, 0, 219, 0, 69, 0, 213, 0, 69, 0, 217, 0, 69, 0, 207, 0, _
69, 0, 192, 0, 69, 0, 197, 0, 69, 0, 195, 0, 69, 0, 193, 0, 69, 0, 196, 0, 236, 0, 32, 0, 230, 0, _
32, 0, 243, 0, 32, 0, 237, 0, 32, 0, 242, 0, 32, 0, 204, 0, 32, 0, 198, 0, 32, 0, 211, 0, 32, 0, 205, 0, _
32, 0, 210, 0, 32, 0, 111, 0, 248, 0, 111, 0, 251, 0, 111, 0, 245, 0, 111, 0, 249, 0, 111, 0, 239, 0, _
244, 0, 248, 0, 244, 0, 251, 0, 244, 0, 245, 0, 244, 0, 249, 0, 244, 0, 239, 0, 111, 0, 224, 0, _
111, 0, 229, 0, 111, 0, 227, 0, 111, 0, 225, 0, 111, 0, 228, 0, 79, 0, 216, 0, 79, 0, 219, 0, 79, 0, _
213, 0, 79, 0, 217, 0, 79, 0, 207, 0, 212, 0, 216, 0, 212, 0, 219, 0, 212, 0, 213, 0, 212, 0, 217, 0, _
212, 0, 207, 0, 79, 0, 192, 0, 79, 0, 197, 0, 79, 0, 195, 0, 79, 0, 193, 0, 79, 0, 196, 0, 117, 0, _
248, 0, 117, 0, 251, 0, 117, 0, 245, 0, 117, 0, 249, 0, 117, 0, 239, 0, 246, 0, 248, 0, 246, 0, _
251, 0, 246, 0, 245, 0, 246, 0, 249, 0, 246, 0, 239, 0, 85, 0, 216, 0, 85, 0, 219, 0, 85, 0, 213, 0, _
85, 0, 217, 0, 85, 0, 207, 0, 214, 0, 216, 0, 214, 0, 219, 0, 214, 0, 213, 0, 214, 0, 217, 0, 214, 0, _
207, 0, 121, 0, 248, 0, 121, 0, 251, 0, 121, 0, 245, 0, 121, 0, 249, 0, 238, 0, 32, 0, 89, 0, 216, 0, _
89, 0, 219, 0, 89, 0, 213, 0, 89, 0, 217, 0, 244, 30, 32, 0)
  
vn3_bytes = Array(169, 0, 168, 0, 162, 0, 161, 0, 174, 0, 167, 0, 170, 0, 163, 0, 172, 0, 171, 0, _
165, 0, 164, 0, 173, 0, 166, 0, 181, 0, 182, 0, 183, 0, 184, 0, 185, 0, 199, 0, 200, 0, 201, 0, _
202, 0, 203, 0, 187, 0, 188, 0, 189, 0, 190, 0, 198, 0, 181, 0, 182, 0, 183, 0, 184, 0, 185, 0, _
199, 0, 200, 0, 201, 0, 202, 0, 203, 0, 187, 0, 188, 0, 189, 0, 190, 0, 198, 0, 204, 0, 206, 0, _
207, 0, 208, 0, 209, 0, 210, 0, 211, 0, 212, 0, 213, 0, 214, 0, 204, 0, 206, 0, 207, 0, 208, 0, _
209, 0, 210, 0, 211, 0, 212, 0, 213, 0, 214, 0, 215, 0, 216, 0, 220, 0, 221, 0, 222, 0, 215, 0, _
216, 0, 220, 0, 221, 0, 222, 0, 223, 0, 225, 0, 226, 0, 227, 0, 228, 0, 234, 0, 235, 0, 236, 0, _
237, 0, 238, 0, 229, 0, 230, 0, 231, 0, 232, 0, 233, 0, 223, 0, 225, 0, 226, 0, 227, 0, 228, 0, _
234, 0, 235, 0, 236, 0, 237, 0, 238, 0, 229, 0, 230, 0, 231, 0, 232, 0, 233, 0, 239, 0, 241, 0, _
242, 0, 243, 0, 244, 0, 245, 0, 246, 0, 247, 0, 248, 0, 249, 0, 239, 0, 241, 0, 242, 0, 243, 0, _
244, 0, 245, 0, 246, 0, 247, 0, 248, 0, 249, 0, 250, 0, 251, 0, 252, 0, 253, 0, 254, 0, 250, 0, _
251, 0, 252, 0, 253, 0, 244, 30)

windows1258_bytes = Array(226, 0, 32, 0, 3, 1, 32, 0, 194, 0, 32, 0, 2, 1, 32, 0, 17, 1, 32, 0, 16, 1, 32, 0, 25, 1, 32, 0, 24, 1, 32, 0, 81, 1, 32, 0, 244, 0, 32, 0, _
80, 1, 32, 0, 212, 0, 32, 0, 253, 0, 32, 0, 221, 0, 32, 0, 97, 0, 26, 1, 97, 0, 71, 1, 97, 0, 98, 1, 97, 0, 27, 1, 97, 0, 72, 1, 226, 0, 26, 1, 226, 0, 71, 1, 226, 0, _
98, 1, 226, 0, 27, 1, 226, 0, 72, 1, 3, 1, 26, 1, 3, 1, 71, 1, 3, 1, 98, 1, 3, 1, 27, 1, 3, 1, 72, 1, 65, 0, 26, 1, 65, 0, 71, 1, 65, 0, 98, 1, 65, 0, 27, 1, 65, 0, 72, 1, _
194, 0, 26, 1, 194, 0, 71, 1, 194, 0, 98, 1, 194, 0, 27, 1, 194, 0, 72, 1, 2, 1, 26, 1, 2, 1, 71, 1, 2, 1, 98, 1, 2, 1, 27, 1, 2, 1, 72, 1, 101, 0, 26, 1, 101, 0, 71, 1, _
101, 0, 98, 1, 101, 0, 27, 1, 101, 0, 72, 1, 25, 1, 26, 1, 25, 1, 71, 1, 25, 1, 98, 1, 25, 1, 27, 1, 25, 1, 72, 1, 69, 0, 26, 1, 69, 0, 71, 1, 69, 0, 98, 1, 69, 0, 27, 1, _
69, 0, 72, 1, 24, 1, 26, 1, 24, 1, 71, 1, 24, 1, 98, 1, 24, 1, 27, 1, 24, 1, 72, 1, 105, 0, 26, 1, 105, 0, 71, 1, 105, 0, 98, 1, 105, 0, 27, 1, 105, 0, 72, 1, 73, 0, 26, _
1, 73, 0, 71, 1, 73, 0, 98, 1, 73, 0, 27, 1, 73, 0, 72, 1, 111, 0, 26, 1, 111, 0, 71, 1, 111, 0, 98, 1, 111, 0, 27, 1, 111, 0, 72, 1, 81, 1, 26, 1, 81, 1, 71, 1, 81, 1, _
98, 1, 81, 1, 27, 1, 81, 1, 72, 1, 244, 0, 26, 1, 244, 0, 71, 1, 244, 0, 98, 1, 244, 0, 27, 1, 244, 0, 72, 1, 79, 0, 26, 1, 79, 0, 71, 1, 79, 0, 98, 1, 79, 0, 27, 1, _
79, 0, 72, 1, 80, 1, 26, 1, 80, 1, 71, 1, 80, 1, 98, 1, 80, 1, 27, 1, 80, 1, 72, 1, 212, 0, 26, 1, 212, 0, 71, 1, 212, 0, 98, 1, 212, 0, 27, 1, 212, 0, 72, 1, 117, 0, _
26, 1, 117, 0, 71, 1, 117, 0, 98, 1, 117, 0, 27, 1, 117, 0, 72, 1, 253, 0, 26, 1, 253, 0, 71, 1, 253, 0, 98, 1, 253, 0, 27, 1, 253, 0, 72, 1, 85, 0, 26, 1, 85, 0, _
71, 1, 85, 0, 98, 1, 85, 0, 27, 1, 85, 0, 72, 1, 221, 0, 26, 1, 221, 0, 71, 1, 221, 0, 98, 1, 221, 0, 27, 1, 221, 0, 72, 1, 121, 0, 26, 1, 121, 0, 71, 1, 121, 0, 98, 1, _
121, 0, 27, 1, 121, 0, 72, 1, 89, 0, 26, 1, 89, 0, 71, 1, 89, 0, 98, 1, 89, 0, 27, 1, 89, 0, 72, 1)

sort_dungsan_bytes = Array(48, 0, 49, 0, 50, 0, 51, 0, 52, 0, 53, 0, 54, 0, 55, 0, 56, 0, 57, 0, _
58, 0, 59, 0, 60, 0, 61, 0, 62, 0, 63, 0, 64, 0, 91, 0, 92, 0, 93, 0, 94, 0, 95, 0, 123, 0, 124, 0, _
125, 0, 126, 0, 97, 0, 224, 0, 163, 30, 227, 0, 225, 0, 161, 30, 3, 1, 177, 30, 179, 30, 181, 30, _
175, 30, 183, 30, 226, 0, 167, 30, 169, 30, 171, 30, 165, 30, 173, 30, 98, 0, 99, 0, 100, 0, 17, 1, _
101, 0, 232, 0, 187, 30, 189, 30, 233, 0, 185, 30, 234, 0, 193, 30, 195, 30, 197, 30, 191, 30, _
199, 30, 102, 0, 103, 0, 104, 0, 105, 0, 236, 0, 201, 30, 41, 1, 237, 0, 203, 30, 106, 0, 107, 0, _
108, 0, 109, 0, 110, 0, 111, 0, 242, 0, 207, 30, 245, 0, 243, 0, 205, 30, 244, 0, 211, 30, 213, _
30, 215, 30, 209, 30, 217, 30, 161, 1, 221, 30, 223, 30, 225, 30, 219, 30, 227, 30, 112, 0, 113, _
0, 114, 0, 115, 0, 116, 0, 117, 0, 249, 0, 231, 30, 105, 1, 250, 0, 229, 30, 176, 1, 235, 30, 237, _
30, 239, 30, 233, 30, 241, 30, 118, 0, 119, 0, 120, 0, 121, 0, 243, 30, 247, 30, 249, 30, 253, 0, _
245, 30, 122, 0, 65, 0, 192, 0, 162, 30, 195, 0, 193, 0, 160, 30, 2, 1, 176, 30, 178, 30, 180, 30, _
174, 30, 182, 30, 194, 0, 166, 30, 168, 30, 170, 30, 164, 30, 172, 30, 66, 0, 67, 0, 68, 0, 16, 1, _
69, 0, 200, 0, 186, 30, 188, 30, 201, 0, 184, 30, 202, 0, 192, 30, 194, 30, 196, 30, 190, 30, 198, _
30, 70, 0, 71, 0, 72, 0, 73, 0, 204, 0, 200, 30, 40, 1, 205, 0, 202, 30, 74, 0, 75, 0, 76, 0, 77, 0, 78, _
0, 79, 0, 210, 0, 206, 30, 213, 0, 211, 0, 204, 30, 212, 0, 210, 30, 212, 30, 214, 30, 208, 30, _
216, 30, 160, 1, 220, 30, 222, 30, 224, 30, 218, 30, 226, 30, 80, 0, 81, 0, 82, 0, 83, 0, 84, 0, 85, _
0, 217, 0, 230, 30, 104, 1, 218, 0, 228, 30, 175, 1, 234, 30, 236, 30, 238, 30, 232, 30, 240, 30, _
86, 0, 87, 0, 88, 0, 89, 0, 242, 30, 246, 30, 248, 30, 221, 0, 244, 30, 90, 0)

sort_vn3_bytes = Array(48, 0, 49, 0, 50, 0, 51, 0, 52, 0, 53, 0, 54, 0, 55, 0, 56, 0, 57, 0, 58, 0, 59, _
0, 60, 0, 61, 0, 62, 0, 63, 0, 64, 0, 91, 0, 92, 0, 93, 0, 94, 0, 95, 0, 123, 0, 124, 0, 125, 0, 126, 0, _
97, 0, 181, 0, 182, 0, 183, 0, 184, 0, 185, 0, 168, 0, 187, 0, 188, 0, 189, 0, 190, 0, 198, 0, 169, _
0, 199, 0, 200, 0, 201, 0, 202, 0, 203, 0, 98, 0, 99, 0, 100, 0, 174, 0, 101, 0, 204, 0, 206, 0, 207, _
0, 208, 0, 209, 0, 170, 0, 210, 0, 211, 0, 212, 0, 213, 0, 214, 0, 102, 0, 103, 0, 104, 0, 105, 0, _
215, 0, 216, 0, 220, 0, 221, 0, 222, 0, 106, 0, 107, 0, 108, 0, 109, 0, 110, 0, 111, 0, 223, 0, 225, _
0, 226, 0, 227, 0, 228, 0, 171, 0, 229, 0, 230, 0, 231, 0, 232, 0, 233, 0, 172, 0, 234, 0, 235, 0, _
236, 0, 237, 0, 238, 0, 112, 0, 113, 0, 114, 0, 115, 0, 116, 0, 117, 0, 239, 0, 241, 0, 242, 0, 243, _
0, 244, 0, 173, 0, 245, 0, 246, 0, 247, 0, 248, 0, 249, 0, 118, 0, 119, 0, 120, 0, 121, 0, 250, 0, _
251, 0, 252, 0, 253, 0, 254, 0, 122, 0, 65, 0, 181, 0, 182, 0, 183, 0, 184, 0, 185, 0, 161, 0, 187, _
0, 188, 0, 189, 0, 190, 0, 198, 0, 162, 0, 199, 0, 200, 0, 201, 0, 202, 0, 203, 0, 66, 0, 67, 0, 68, _
0, 167, 0, 69, 0, 204, 0, 206, 0, 207, 0, 208, 0, 209, 0, 163, 0, 210, 0, 211, 0, 212, 0, 213, 0, 214, _
0, 70, 0, 71, 0, 72, 0, 73, 0, 215, 0, 216, 0, 220, 0, 221, 0, 222, 0, 74, 0, 75, 0, 76, 0, 77, 0, 78, 0, _
79, 0, 223, 0, 225, 0, 226, 0, 227, 0, 228, 0, 164, 0, 229, 0, 230, 0, 231, 0, 232, 0, 233, 0, 165, _
0, 234, 0, 235, 0, 236, 0, 237, 0, 238, 0, 80, 0, 81, 0, 82, 0, 83, 0, 84, 0, 85, 0, 239, 0, 241, 0, _
242, 0, 243, 0, 244, 0, 166, 0, 245, 0, 246, 0, 247, 0, 248, 0, 249, 0, 86, 0, 87, 0, 88, 0, 89, 0, _
250, 0, 251, 0, 252, 0, 253, 0, 254, 0, 90, 0)

sort_vni_bytes = Array(48, 0, 32, 0, 49, 0, 32, 0, 50, 0, 32, 0, 51, 0, 32, 0, 52, 0, 32, 0, 53, 0, 32, 0, 54, 0, 32, 0, 55, 0, 32, 0, 56, 0, 32, 0, 57, 0, 32, 0, 58, 0, 32, 0, 59, 0, 32, 0, 60, 0, 32, 0, 61, 0, _
32, 0, 62, 0, 32, 0, 63, 0, 32, 0, 64, 0, 32, 0, 91, 0, 32, 0, 92, 0, 32, 0, 93, 0, 32, 0, 94, 0, 32, 0, 95, 0, 32, 0, 123, 0, 32, 0, 124, 0, 32, 0, 125, 0, 32, 0, 126, 0, 32, 0, 97, 0, 32, 0, 97, 0, 248, 0, 97, _
0, 251, 0, 97, 0, 245, 0, 97, 0, 249, 0, 97, 0, 239, 0, 97, 0, 234, 0, 97, 0, 232, 0, 97, 0, 250, 0, 97, 0, 252, 0, 97, 0, 233, 0, 97, 0, 235, 0, 97, 0, 226, 0, 97, 0, 224, 0, 97, 0, 229, 0, 97, 0, 227, 0, _
97, 0, 225, 0, 97, 0, 228, 0, 98, 0, 32, 0, 99, 0, 32, 0, 100, 0, 32, 0, 241, 0, 32, 0, 101, 0, 32, 0, 101, 0, 248, 0, 101, 0, 251, 0, 101, 0, 245, 0, 101, 0, 249, 0, 101, 0, 239, 0, 101, 0, 226, 0, 101, _
0, 224, 0, 101, 0, 229, 0, 101, 0, 227, 0, 101, 0, 225, 0, 101, 0, 228, 0, 102, 0, 32, 0, 103, 0, 32, 0, 104, 0, 32, 0, 105, 0, 32, 0, 236, 0, 32, 0, 230, 0, 32, 0, 243, 0, 32, 0, 237, 0, 32, 0, 242, 0, _
32, 0, 106, 0, 32, 0, 107, 0, 32, 0, 108, 0, 32, 0, 109, 0, 32, 0, 110, 0, 32, 0, 111, 0, 32, 0, 111, 0, 248, 0, 111, 0, 251, 0, 111, 0, 245, 0, 111, 0, 249, 0, 111, 0, 239, 0, 111, 0, 226, 0, 111, 0, _
224, 0, 111, 0, 229, 0, 111, 0, 227, 0, 111, 0, 225, 0, 111, 0, 228, 0, 244, 0, 32, 0, 244, 0, 248, 0, 244, 0, 251, 0, 244, 0, 245, 0, 244, 0, 249, 0, 244, 0, 239, 0, 112, 0, 32, 0, 113, 0, 32, 0, 114, _
0, 32, 0, 115, 0, 32, 0, 116, 0, 32, 0, 117, 0, 32, 0, 117, 0, 248, 0, 117, 0, 251, 0, 117, 0, 245, 0, 117, 0, 249, 0, 117, 0, 239, 0, 246, 0, 32, 0, 246, 0, 248, 0, 246, 0, 251, 0, 246, 0, 245, 0, 246, _
0, 249, 0, 246, 0, 239, 0, 118, 0, 32, 0, 119, 0, 32, 0, 120, 0, 32, 0, 121, 0, 32, 0, 121, 0, 248, 0, 121, 0, 251, 0, 121, 0, 245, 0, 121, 0, 249, 0, 238, 0, 32, 0, 122, 0, 32, 0, 65, 0, 32, 0, 65, 0, 216, _
0, 65, 0, 219, 0, 65, 0, 213, 0, 65, 0, 217, 0, 65, 0, 207, 0, 65, 0, 202, 0, 65, 0, 200, 0, 65, 0, 218, 0, 65, 0, 220, 0, 65, 0, 201, 0, 65, 0, 203, 0, 65, 0, 194, 0, 65, 0, 192, 0, 65, 0, 197, 0, 65, 0, 195, _
0, 65, 0, 193, 0, 65, 0, 196, 0, 66, 0, 32, 0, 67, 0, 32, 0, 68, 0, 32, 0, 209, 0, 32, 0, 69, 0, 32, 0, 69, 0, 216, 0, 69, 0, 219, 0, 69, 0, 213, 0, 69, 0, 217, 0, 69, 0, 207, 0, 69, 0, 194, 0, 69, 0, 192, 0, _
69, 0, 197, 0, 69, 0, 195, 0, 69, 0, 193, 0, 69, 0, 196, 0, 70, 0, 32, 0, 71, 0, 32, 0, 72, 0, 32, 0, 73, 0, 32, 0, 204, 0, 32, 0, 198, 0, 32, 0, 211, 0, 32, 0, 205, 0, 32, 0, 210, 0, 32, 0, 74, 0, 32, 0, 75, 0, _
32, 0, 76, 0, 32, 0, 77, 0, 32, 0, 78, 0, 32, 0, 79, 0, 32, 0, 79, 0, 216, 0, 79, 0, 219, 0, 79, 0, 213, 0, 79, 0, 217, 0, 79, 0, 207, 0, 79, 0, 194, 0, 79, 0, 192, 0, 79, 0, 197, 0, 79, 0, 195, 0, 79, 0, 193, _
0, 79, 0, 196, 0, 212, 0, 32, 0, 212, 0, 216, 0, 212, 0, 219, 0, 212, 0, 213, 0, 212, 0, 217, 0, 212, 0, 207, 0, 80, 0, 32, 0, 81, 0, 32, 0, 82, 0, 32, 0, 83, 0, 32, 0, 84, 0, 32, 0, 85, 0, 32, 0, 85, 0, 216, _
0, 85, 0, 219, 0, 85, 0, 213, 0, 85, 0, 217, 0, 85, 0, 207, 0, 214, 0, 32, 0, 214, 0, 216, 0, 214, 0, 219, 0, 214, 0, 213, 0, 214, 0, 217, 0, 214, 0, 207, 0, 86, 0, 32, 0, 87, 0, 32, 0, 88, 0, 32, 0, 89, 0, _
32, 0, 89, 0, 216, 0, 89, 0, 219, 0, 89, 0, 213, 0, 89, 0, 217, 0, 206, 0, 32, 0, 90, 0, 32, 0)

    ReDim a(268)
    For k = 0 To 267
        a(k) = dungsan_bytes(k)
    Next k
    s_dung_san = a
  
    For k = 0 To 267
        a(k) = vn3_bytes(k)
    Next k
    s_vn3 = a
  
    ReDim a(508)
    For k = 0 To 507
        a(k) = tohop_bytes(k)
    Next k
    s_to_hop = a
  
    ReDim a(536)
    For k = 0 To 535
        a(k) = vni_bytes(k)
    Next k
    s_vni = a
  
    For k = 0 To 535
        a(k) = windows1258_bytes(k)
    Next k
    s_windows1258 = a
  
    ReDim a(424)
    For k = 0 To 423
        a(k) = sort_dungsan_bytes(k)
    Next k
    sort_dung_san = a
  
    For k = 0 To 423
        a(k) = sort_vn3_bytes(k)
    Next k
    sort_vn3 = a
  
    ReDim a(848)
    For k = 0 To 847
        a(k) = sort_vni_bytes(k)
    Next k
    sort_vni = a
  
    Erase a, dungsan_bytes, tohop_bytes, vni_bytes, vn3_bytes, sort_dungsan_bytes, sort_vn3_bytes, sort_vni_bytes
End Sub

Public Function SourceToDest(ByVal text As String, source As convert_source, dest As convert_dest) As String
Dim s As String, temp As String
Dim n As Long, index As Long, k As Long
Dim nr As Long
    If source = dest And source <> src_uni Then
        SourceToDest = text
        Exit Function
    End If
    InitVietnameseStr
  
    text = text & " "
    s = ""
    n = 1
    k = Len(text)
      
    While n < k
        nr = 0
        Select Case source
            Case src_uni, src_vni, src_windows1258:
                kytu2 = Mid(text, n, 2)
                If source = src_uni Then
                    index = InStr(1, s_to_hop, kytu2)
                    If index > 14 Then
                        nr = (index + 15) \ 2
                        n = n + 2
                    End If
                    If nr = 0 Then
                        kytu2 = Mid(kytu2, 1, 1)
                        nr = InStr(1, s_dung_san, kytu2)
                        n = n + 1
                    End If
                Else
                    If source = src_vni Then
                        temp = s_vni
                    Else
                        temp = s_windows1258
                    End If
                  
                    index = InStr(1, temp, kytu2)
                    If index Mod 2 = 1 Then
                        nr = (index + 1) \ 2
                        n = n + 2
                    End If
                    If nr = 0 Then
                        kytu2 = Mid(kytu2, 1, 1)
                        index = InStr(1, temp, kytu2 & " ")
                        If index > 0 Then nr = (index + 1) \ 2
                        n = n + 1
                    End If
                End If
            Case Else
                kytu2 = Mid(text, n, 1)
                index = InStr(1, s_vn3, kytu2)
                If index > 0 Then nr = index
                n = n + 1
        End Select
      
        If nr > 0 Then
            Select Case dest
                Case dst_uni: kytu2 = Mid(s_dung_san, nr, 1)
                Case dst_vni: kytu2 = Trim(Mid(s_vni, 2 * nr - 1, 2))
                Case dst_vn3: kytu2 = Mid(s_vn3, nr, 1)
                Case dst_windows1258: kytu2 = Trim(Mid(s_windows1258, 2 * nr - 1, 2))
                Case dst_khongdau: kytu2 = Mid(s_khong_dau, nr, 1)
            End Select
        End If
      
        s = s & kytu2
    Wend

    SourceToDest = s
End Function
Và trong thủ tục timchuoi, bạn sửa lại thành như thế này
Mã:
Sub timChuoi()
    s = UniConvert("Tuwf")
    [c1] = InStr(SourceToDest([a1], 1, 1), s)
    [c2] = InStr(SourceToDest([a2], 1, 1), s)
End Sub
Làm vậy hàm sẽ tự động chuyển sang Unicode dựng sẵn bất kể ban đầu bạn đang sài Unicode gì.
Bạn cần đăng nhập để thấy hình ảnh
 
Top