Category Archives: Chỉ dẫn lập trình

VBA function MoneyFromNote

Function MoneyFromNote(ByVal note As String)
    
    Dim RE As RegExp, REMatches As MatchCollection, REMatch As Match
    Set RE = CreateObject("vbscript.regexp")
    With RE
        .MultiLine = False
        .Global = True
        .IgnoreCase = True
        .Pattern = "([\+0-9\.,]+)([MK])"
    End With
    
    Set REMatches = RE.Execute(note)
    r = 0
    For i = 0 To REMatches.Count – 1
        Set REMatch = REMatches.Item(i)
        unit = REMatch.SubMatches(1)
        num = REMatch.SubMatches(0)
        
        num = Replace(num, ",", ".")
        If unit = "M" Then
            va = num * 1000000
        ElseIf unit = "K" Then
            va = num * 1000
        End If
        If Mid(num, 1, 1) = "+" Then va = 0 – va
        'MsgBox num & " " & unit & " = " & va
        r = r – va
    Next
    'MsgBox r
    MoneyFromNote = Int(r)
End Function

‘Usage example
‘=MoneyFromNote(“Quần đùi: 30K; Áo ba lỗ: 25K; Thịt ba chỉ: 15K”)
‘Sẽ thu được: -70000

Minh họa hàm MoneyFromNote trong Excel

Soi cầu xem có trúng lô

Giả sử ta có mảng kết quả xổ số thủ đô như sau:
$arrRes = array(
    'db'    => '75330',
    'nhat'  => '62216',
    'nhi'   => '38364 51570',
    'ba'  => '95807 83038 59191 80469 06604 17288',
    'tu'  => '9057 6726 9522 7774',
    'nam'  => '3582 8224 2324 2768 4067 5985',
    'sau'  => '112 908 489',
    'bay'  => '44 99 50 30',
);

Để kiểm tra xem nếu oánh 30 có trúng không thì làm thế nào biết nhanh nhất?
Một cách đơn giản và dễ hiểu nhất: Duyệt qua từng giải – Với mỗi dãy số trong giải, so khớp 2 chữ số cuối, nếu có thì trúng và break.
Cách khác:
$arrRes['bay'] .= ' ';
return (strpos('30 ', implode(' ', $arrRes)) !== false);

CURLOPT_COOKIEFILE vs CURLOPT_COOKIEJAR

CURLOPT_COOKIEFILE: The name of the file containing the cookie data. The cookie file can be in Netscape format, or just plain HTTP-style headers dumped into a file.
CURLOPT_COOKIEJAR: The name of a file to save all internal cookies to when the connection closes.

# Sẽ lấy cookie có trong file để gửi request đi
curl_setopt($curl, CURLOPT_COOKIEFILE, ‘cookie_will_be_used.txt’);

# Sẽ lưu cookie server response về
curl_setopt($curl, CURLOPT_COOKIEJAR, ‘cookie_will_be_saved.txt’);