# Re: 有关Print out to a .txt from .mdb(不使用CrystalReport....,仅用Open ...for output as #

Posted by 小v on June 10, 1999 at 10:12:36:

In Reply to: 有关Print out to a .txt from .mdb(不使用CrystalReport....,仅用Open ...for output as # posted by Scott on June 09, 1999 at 21:53:42:

: 各位高手:
: 如何将一个.mdb转印成一个排列整齐的文字档案,目前始终遇到一个
: 瓶颈,如果是一个text结构,较没有问题,但是却毁在数字长度问题上,
: (1).使用rs.fields.size,仅回应之栏位type之常数值(X)
: (2).使用数值转换,却遇 ,a=0.19537,b=format(a,"0.00")=0.20,c=str(format(a,"0.00"))=0.2
: c值末少掉了一个"0"
: (3).数值排列却均靠左边,无法自我控制
: 123.04
: 0.61
: 23.11
: (4).又无法去抓取最大值去分析数值之长度, 2.,0.6,0.11
: 基于以上之结果,是否即宣判Open.....for output as # 无解了呢?
: (以foxpro而言,如似傻瓜软体,仅一行即可得之)

那就写个小函数自行控制数值栏位的输出:
例:
a=2.12
b=0.345
c=12
Open "C:\TTT.TXT" For Output As #1
Print #1, myFORMAT(a, "###,##0.00") & "," & myFORMAT(b, "###,##0.00") & "," & myFORMAT(c, "###,##0.00")
Close #1

Private Function myFORMAT(ByVal mS As Variant, ByVal mPICT As String) As String
Dim mN As Integer
mN = Len(mPICT)
myFORMAT = Right(String(mN, " ") & Format(mS, mPICT), mN)
End Function

Follow Ups: