CSDN博客

img davidnim

Notes中人民币大写换算的实现

发表于2003/2/17 11:13:00  1327人阅读

'调用按钮的代码:
Sub Click(Source As Button)
 Dim w As New notesUIWorkspace 
 Dim ui As notesUIdocument
 Dim jineStr As String
 
 Set ui = w.currentDocument
 Call ui.refresh
 jineStr = ui.fieldGetText("jine")
 Call ui.fieldSetText("dxje",TurnResult(jineStr))
 Call ui.refresh
End Sub


'换算函数
Function TurnResult(numStr As String) As String
 Dim digi As Integer
 Dim numLen As Integer
 
 numLen = Len(numStr)
 intStr = Left(numStr,(numLen - 3))  '取整数部分
 digStr = Right(numStr,2)    '取小数部分
 
 numLen = Len(intStr)
 digi_old = 9
 '处理整数部分转换
 While numLen <> 0
  digi = Cint(Left(intStr,1))
  If numLen<5 Then  '完元以下的换算
   If digi_old = 0 And digi = 0 And numLen<>1 Then
    TurnResult = TurnResult
   Else
    If digi = 0 And numLen <> 1 Then
     TurnResult = TurnResult + numToBigWrite(digi)
    Elseif digi = 0 And digi_old = 0 And numLen = 1  Then
     TurnResult = Left(TurnResult,Len(TurnResult)-1) + Unit(numLen)
    Elseif digi = 0 And digi_old <> 0 And numLen = 1  Then
     TurnResult = TurnResult + Unit(numLen)
    Else
     TurnResult = TurnResult + numToBigWrite(digi) + Unit(numLen)
    End If
   End If
  Else     '万元以上的换算
   If digi_old = 0 And digi = 0 And numLen<>5 Then
    TurnResult = TurnResult
   Else
    If digi = 0 And numLen <> 5 Then
     TurnResult = TurnResult + numToBigWrite(digi)
    Elseif digi = 0 And digi_old = 0 And numLen = 5  Then
     TurnResult = Left(TurnResult,Len(TurnResult)-1) + Unit(numLen)
    Elseif digi = 0 And digi_old <> 0 And numLen = 5  Then
     TurnResult = TurnResult + Unit(numLen)
    Else
     TurnResult = TurnResult + numToBigWrite(digi) + Unit(numLen)
    End If
   End If
  End If
  
  digi_old = digi
  intStr = Right(intStr,numLen - 1)
  numLen = Len(intStr)
 Wend
 '小数部分的数值转换
 TurnResult = TurnResult + numToBigWrite(Cint(Left(digStr,1))) + Unit(-1) + _
 numToBigWrite(Cint(Right(digStr,1))) + Unit(-2) + "整"
 
End Function


'单位转换函数
Function Unit(bit As Integer) As String
 Select Case bit
 Case -1
  Unit="角"
 Case -2
  Unit="分"
 Case 1
  Unit="元"
 Case 2
  Unit="拾"
 Case 3
  Unit="佰"
 Case 4
  Unit="仟"
 Case 5
  Unit="万"
 Case 6
  Unit="拾" 
 Case 7
  Unit="佰"
 Case 8
  Unit="仟"  
 Case 9
  Unit="亿"
 Case Else
  Unit="无效"+Cstr(bit)
 End Select 
End Function

0 0

相关博文

我的热门文章

img
取 消
img