VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)
首页 - 经验之谈 - 一个Format函数
发表评论(0)作者:不详, 平台:VB6.0+Win98, 阅读:11656, 日期:2000-11-20
A new Format function

Visual Basic 5 has the Format command that almost works the same as Print. The difference is that Format shortens the output string length if all the format characters are not used. To work around this I wrote a Public Function called FormatNum.

Public Function FormatNum(MyNumber As Double, FormatStr As String) As String

   注释: This Function returns number formatted as a string
   注释:    with the desired minimum number of characters
   注释: MyNumber - Use CDbl(MyNumber) in the function
   注释:    call to prevent type mismatch error.
   注释:
   FormatNum = Format$(MyNumber, FormatStr)
   If Len(FormatNum) < Len(FormatStr) Then
      FormatNum = Space$(Len(FormatStr) - Len(FormatNum)) & FormatNum
   End If
End Function

Use this function like this:

Print #FileNumber, FormatNum(CDbl(MyVariable), " #### ")