用vb 写txt文件怎样才能实现数据的右对齐?

来源:百度知道 编辑:UC知道 时间:2024/06/14 17:42:34
如题,比如
1233 322222
45 3310

在写入数值时使用 Format 函数:
Format(x,String(n,"@"))
此函数的执行结果就是左侧空格的右对齐文本,
其中 x 是要转化的数字(或文本),n 是数字(或文本)的最大位数
例如,当 x = 200,n = 5 时,此函数的执行结果为:
  200

Dim s As String
Dim s1 As String
Dim s2 As String
Open "c:\1.txt" For Outut As #1

s1 = "1233 322222"
s2 = "45 3310"

s = s1
s = Space$(20 - Lenb(s)) & s
Printf #1, s
s = s2
s = Space$(20 - Lenb(s)) & s
Printf #1, s

Close #1

Text1.Alignment = 1
0左 1右 2中

Private Sub Command1_Click()

Dim hFile As Long
Dim pFile As String
Dim a, tmp
Dim s As String
Dim i As Long, j As Long

a = Array("1233 322222", "45 3310")
pFile = "d:\test.txt"
hFile = FreeFile
Open pFile For Output As hFile
For i = 0 To UBound(a)
tmp = Split(a