1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Dịch vụ bảo mật website - tối ưu hóa website - sửa lỗi website
  3. - Chào Guest! Bạn vui lòng đọc qua NỘI QUY của HVN trước khi làm 1 việc gì đó để tránh bị hệ thống xóa tài khoản không thông báo.
    Bạn có thể thao khảo qua các cập nhật mới nhất của HVN tại đây
    - Nếu Bạn là Khách bạn không thể xem các chủ đề mới nhất bằng Thống kê, Và bạn chỉ được đọc 5 bài Viết Của HVN mà thôi. Để tiếp tục vui lòng đăng ký thành viên TẠI ĐÂY

    - Đăng nhập để ẩn quảng cáo.

[Visual Basic] Chuyển Số Thành Chữ

Discussion in 'Visual Basic 6.0' started by Hackerpro536, Aug 25, 2013.

Lượt xem: 251

Thread Status:
Not open for further replies.
  1. Hackerpro536

    Hackerpro536 Administrative Staff Member Administrator Moderator
    • 113/113

    Joined:
    Aug 30, 2012
    Messages:
    6,736
    Likes Received:
    6,070
    Gender:
    Male
    Đây là code tôi viết.khi nhập vào số nó sẽ chuyển thành chữ.!
    Ae leech xin ghi rõ nguồn nhé.chúc ae học tốt.
    PHP:
    <span class="syntaxdefault">PublicFunction ChuyenSo</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">ByVal GiaTri AsString</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> ByVal DonVi AsString</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> AsString<br />Static Ones</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">0 To 11</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> AsString<br />Static Teens</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">0 To 9</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> AsString<br />Static Tens</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">0 To 9</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> AsString<br />Static Thousands</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">0 To 4</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> AsString</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> bInit AsBoolean<br />Dim i AsInteger</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> bAllZeros AsBoolean</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> bShowThousands AsBoolean<br />Dim StrVal AsString</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> StrBuff AsString</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> StrTemp AsString<br />Dim nCol AsInteger</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> nChar AsInteger<br />Dim J AsInteger<br /></span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Len</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">CStr</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">CLng</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">GiaTri</span><span class="syntaxkeyword">)))<br /></span><span class="syntaxdefault">Debug</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">Assert</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">GiaTri </span><span class="syntaxkeyword">>=</span><span class="syntaxdefault"> 0</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">If bInit </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> FalseThen<br /></span><span class="syntaxstring">'Bắt đầu tạo mảng<br />bInit = True<br />Ones(0) = "Không"<br />Ones(1) = "Một"<br />Ones(2) = "Hai"<br />Ones(3) = "Ba"<br />Ones(4) = "Bốn"<br />Ones(5) = "Năm"<br />Ones(6) = "Sáu"<br />Ones(7) = "Bảy"<br />Ones(8) = "Tám"<br />Ones(9) = "Chín"<br />Ones(10) = "Mốt"<br />Ones(11) = "Tư"<br />Teens(0) = "Mười"<br />Teens(1) = "Mười Một"<br />Teens(2) = "Mười Hai"<br />Teens(3) = "Mười Ba"<br />Teens(4) = "Mười Bốn"<br />Teens(5) = "Mười Năm"<br />Teens(6) = "Mơừi Sáu"<br />Teens(7) = "Mười Bảy"<br />Teens(8) = "Mơừi Tám"<br />Teens(9) = "Mười Chín"<br />Tens(0) = ""<br />Tens(1) = "Mười"<br />Tens(2) = "Hai Mươi"<br />Tens(3) = "Ba Mươi"<br />Tens(4) = "Bốn Mươi"<br />Tens(5) = "Năm Mươi"<br />Tens(6) = "Sáu Mươi"<br />Tens(7) = "Bảy Mươi"<br />Tens(8) = "Tám Mươi"<br />Tens(9) = "Chín Mươi"<br />Thousands(0) = ""<br />Thousands(1) = "Nghìn"'<br /></span><span class="syntaxdefault">Thousands</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">2</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxstring">"Triệu"<br /></span><span class="syntaxdefault">Thousands</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">3</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxstring">"Tỉ"<br /></span><span class="syntaxdefault">Thousands</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">4</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxstring">"Nghìn"<br /></span><span class="syntaxkeyword">EndIf<br /></span><span class="syntaxdefault">OnErrorGoTo Err2TextTrap<br />StrVal </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> CStr</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">CLng</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">GiaTri</span><span class="syntaxkeyword">))<br /></span><span class="syntaxstring">'Tất cả cả số đều là Zero<br />bAllZeros = True<br />For i = Len(StrVal) To 1 Step -1<br />'</span><span class="syntaxdefault">Lấy từng kí số<br />nChar </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Val</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">Mid</span><span class="syntaxkeyword">$(</span><span class="syntaxdefault">StrVal</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> i</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 1</span><span class="syntaxkeyword">))<br /></span><span class="syntaxstring">'Tìm số cột cho kí số<br />nCol = (Len(StrVal) - i) + 1<br />SelectCase (nCol Mod 3)<br />Case 1 '</span><span class="syntaxdefault">Trường hợp là 1<br />bShowThousands </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> True<br />If i </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> 1 Then<br /></span><span class="syntaxstring">'Số đầu tiên<br />StrTemp = Ones(nChar) & " "<br />ElseIf Mid$(StrVal, i - 1, 1) ="1"Then<br />'</span><span class="syntaxdefault">Các số sau ở trong hàng mười<br />StrTemp </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Teens</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">nChar</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">&</span><span class="syntaxdefault"> </span><span class="syntaxstring">" "<br /></span><span class="syntaxdefault"></span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> i </span><span class="syntaxkeyword">-</span><span class="syntaxdefault"> 1 </span><span class="syntaxstring">'Giữ lại các số có hai con số<br />ElseIf nChar > 0 Then<br />'</span><span class="syntaxdefault">Các số có một con số<br />StrTemp </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Ones</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">nChar</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">&</span><span class="syntaxdefault"> </span><span class="syntaxstring">" "<br /></span><span class="syntaxkeyword">Else<br /></span><span class="syntaxdefault">bShowThousands </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> False<br />If Mid</span><span class="syntaxkeyword">$(</span><span class="syntaxdefault">StrVal</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> i </span><span class="syntaxkeyword">-</span><span class="syntaxdefault"> 1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 1</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword"><></span><span class="syntaxdefault"> </span><span class="syntaxstring">"0"</span><span class="syntaxdefault">Then<br />bShowThousands </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> True<br />ElseIf i </span><span class="syntaxkeyword">></span><span class="syntaxdefault"> 2 Then<br />If Mid</span><span class="syntaxkeyword">$(</span><span class="syntaxdefault">StrVal</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> i </span><span class="syntaxkeyword">-</span><span class="syntaxdefault"> 2</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 1</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword"><></span><span class="syntaxdefault"> </span><span class="syntaxstring">"0"</span><span class="syntaxdefault">Then bShowThousands </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> True<br /></span><span class="syntaxkeyword">EndIf<br /></span><span class="syntaxdefault">StrTemp </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxstring">""<br /></span><span class="syntaxkeyword">EndIf<br /></span><span class="syntaxdefault">If bShowThousands Then<br />If nCol </span><span class="syntaxkeyword">></span><span class="syntaxdefault"> 1 Then<br />StrTemp </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> StrTemp </span><span class="syntaxkeyword">&</span><span class="syntaxdefault"> Thousands</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">nCol </span><span class="syntaxkeyword">\</span><span class="syntaxdefault"> 3</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">If bAllZeros Then<br />StrTemp </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> StrTemp </span><span class="syntaxkeyword">&</span><span class="syntaxdefault"> </span><span class="syntaxstring">" "<br /></span><span class="syntaxkeyword">Else<br /></span><span class="syntaxdefault">StrTemp </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> StrTemp </span><span class="syntaxkeyword">&</span><span class="syntaxdefault"> </span><span class="syntaxstring">", "<br /></span><span class="syntaxkeyword">EndIf<br />EndIf<br /></span><span class="syntaxdefault">bAllZeros </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> False<br /></span><span class="syntaxkeyword">EndIf<br /></span><span class="syntaxdefault">StrBuff </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> StrTemp </span><span class="syntaxkeyword">&</span><span class="syntaxdefault"> StrBuff<br />Case 2<br />If nChar </span><span class="syntaxkeyword">></span><span class="syntaxdefault"> 0 Then<br />If Mid</span><span class="syntaxkeyword">$(</span><span class="syntaxdefault">StrVal</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> i </span><span class="syntaxkeyword">+</span><span class="syntaxdefault"> 1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 1</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword"><></span><span class="syntaxdefault"> </span><span class="syntaxstring">"0"</span><span class="syntaxdefault">Then<br />StrBuff </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Tens</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">nChar</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">&</span><span class="syntaxdefault"> </span><span class="syntaxstring">" "</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">&</span><span class="syntaxdefault"> StrBuff<br /></span><span class="syntaxkeyword">Else<br /></span><span class="syntaxdefault">StrBuff </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Tens</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">nChar</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">&</span><span class="syntaxdefault"> </span><span class="syntaxstring">" "</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">&</span><span class="syntaxdefault"> StrBuff<br /></span><span class="syntaxkeyword">EndIf<br />EndIf<br /></span><span class="syntaxdefault">Case 0<br />If nChar </span><span class="syntaxkeyword">></span><span class="syntaxdefault"> 0 Then StrBuff </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Ones</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">nChar</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">&</span><span class="syntaxdefault"> </span><span class="syntaxstring">" Trăm "</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">&</span><span class="syntaxdefault"> StrBuff<br />EndSelect<br />Next<br />StrBuff </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Trim</span><span class="syntaxkeyword">$(</span><span class="syntaxdefault">StrBuff</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">If </span><span class="syntaxkeyword">((</span><span class="syntaxdefault">Mid</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">StrBuff</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> Len</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">StrBuff</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">-</span><span class="syntaxdefault"> 3</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">=</span><span class="syntaxdefault">Ones</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">)))</span><span class="syntaxdefault"> And </span><span class="syntaxkeyword">(</span><span class="syntaxdefault"></span><span class="syntaxkeyword">></span><span class="syntaxdefault"> 2</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> Then _<br />StrBuff </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Mid</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">StrBuff</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> Len</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">StrBuff</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">-</span><span class="syntaxdefault"> 3</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">&</span><span class="syntaxdefault"> Ones</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">10</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">If </span><span class="syntaxkeyword">((</span><span class="syntaxdefault">Mid</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">StrBuff</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> Len</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">StrBuff</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">-</span><span class="syntaxdefault"> 3</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">=</span><span class="syntaxdefault">Ones</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">4</span><span class="syntaxkeyword">)))</span><span class="syntaxdefault"> And </span><span class="syntaxkeyword">(</span><span class="syntaxdefault"></span><span class="syntaxkeyword">></span><span class="syntaxdefault"> 2</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> Then _<br />StrBuff </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Mid</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">StrBuff</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> Len</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">StrBuff</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">-</span><span class="syntaxdefault"> 3</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">&</span><span class="syntaxdefault"> Ones</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">11</span><span class="syntaxkeyword">)<br /></span><span class="syntaxstring">' If ((Right$(StrBuff, 3) = Ones(4)))Then _<br />'</span><span class="syntaxdefault">StrTemp </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Left</span><span class="syntaxkeyword">$(</span><span class="syntaxdefault">StrBuff</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> Len</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">StrBuff</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">-</span><span class="syntaxdefault"> 3</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">&</span><span class="syntaxdefault"> Ones</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">11</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">StrBuff </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> UCase</span><span class="syntaxkeyword">$(</span><span class="syntaxdefault">Mid</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">StrBuff</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 1</span><span class="syntaxkeyword">))</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">&</span><span class="syntaxdefault"> Mid</span><span class="syntaxkeyword">$(</span><span class="syntaxdefault">StrBuff</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 2</span><span class="syntaxkeyword">)<br /></span><span class="syntaxstring">'StrBuff = " Và " & Format((mVarStr - CLng(mVarStr))* 100, "00") & "/100"<br />If (CDbl(GiaTri) - CLng(GiaTri) > 0) Then StrBuff = StrBuff _<br />& " ( Và " & Format((GiaTri - CLng(GiaTri)) * 100, "00") &"/100)"<br />Err2Text:<br />ChuyenSo = UCase(Mid(StrBuff, 1, 1)) & LCase(Mid(StrBuff, 2) & " " & Trim(DonVi))<br />ExitFunction<br />Err2TextTrap:<br />StrBuff = "Số quá lớn hoặc định dạng sai"<br />Resume Err2Text<br />EndFunction</span>
    [ Bài viết từ Mobile Device ]
     
Tin đăng được kiểm duyệt. Tất cả Bài viết và Tài khoản của Bạn sẽ bị xóa nếu:

✓ Không được bình luận vào các bài viết quá lâu quá 3 tháng so với hiện tại (đào top)
✓ Tiêu đề tin đăng Viết hoa (Không được viết hoa tiêu đề)
✓ Đăng tin bài không đúng chuyên mục nhiều lần.
✓ Đăng bài nội dung nhằm SEO, chèn từ khóa không liên quan đến bài viết vào diễn đàn.
✓ Nội dung bài viết không Logic, Tin đăng có nhiều khoảng trống
✓ Cố tình Spam, đăng nội dung không theo quy định tại diễn đàn.

Thread Status:
Not open for further replies.

Share This Page

Users Viewing Thread (Users: 0, Guests: 0)