VB编程。文本读取问题

[复制链接]
查看11 | 回复6 | 2011-5-24 12:06:44 | 显示全部楼层 |阅读模式
文本 Text1.Text 如下
1.0|9038000024674188
回复

使用道具 举报

千问 | 2011-5-24 12:06:44 | 显示全部楼层
|102501000080351
|
20000.00|Z
2.0|9038000024705788
回复

使用道具 举报

千问 | 2011-5-24 12:06:44 | 显示全部楼层
|101400000505932
|
69996.50|Z
3.0|9038000024705888
回复

使用道具 举报

千问 | 2011-5-24 12:06:44 | 显示全部楼层
|100707000057074
|
79000.00|Z
要判断有几行
并且将 20000.0069996.50 79000.00汇总生成新的文本 如下:
10070000024|100700||1007000103000010310|0|0|999||3.0|168996.50|0|0.00|20110422|20110422
回复

使用道具 举报

千问 | 2011-5-24 12:06:44 | 显示全部楼层
|
其中3.0 是行数 168996.50 是汇总金额 20110422 为日期 是从DTPicker1得到的
其他的格式不变
我源程序如下:
'添加CommonDialog1,Command1,Command2,Command3,Text1,DTPicker1
'Text1的Multiline设为True,Scrollbar看需要选择
Dim fname$, aa$
Private Sub Form_Load()
Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2 '窗体置屏幕中间
'Command1.Caption = "打开"
'Command2.Caption = "保存"
End Sub
Private Sub Command1_Click(Index As Integer)
On Error GoTo errhandler
With CommonDialog1
.CancelError = True
.InitDir = App.Path '予设存档路径
.Filter = "文档文件(*.txt)|*.txt"
.ShowOpen '或commonDialog1.Action = 1 打开文件
End With
fname = CommonDialog1.FileName

'从上面打开的记事本文件读入资料加进Text1.text
Open fname For Input As #1
Text1.Text = ""
While Not EOF(1)
Line Input #1, aa
Text1.Text = Text1.Text & Trim(aa) & vbCrLf
Wend
Close #1
errhandler:
If Err = 32755 Then '选择了取消
Exit Sub
End If
End Sub
Private Sub Command2_Click(Index As Integer)
On Error GoTo errhandler
With CommonDialog1
.CancelError = True
.InitDir = App.Path '予设存档路径
.Filter = "文档文件(*.txt)|*.txt"
.ShowSave '或commonDialog1.Action = 2 保存文件
End With
fname = CommonDialog1.FileName

'将Text1.text写入上面选择的文件中
Open fname For Output As #1
Print #1, Text1.Text
Close #1
errhandler:
If Err = 32755 Then '选择了取消
Exit Sub
End If
End Sub
Private Sub 关闭_Click()
End
End Sub
请高手指点:
或发邮件到我邮箱 [email protected]
没有人回答啊。能帮我解决的我追加高分的啊

回复

使用道具 举报

千问 | 2011-5-24 12:06:44 | 显示全部楼层
写了一小段代码吧数据给你分割开来 后面自己处理吧' 设置“CancelError”为 TrueCommonDialog1.CancelError = TrueOn Error GoTo ErrHandler' 设置标志CommonDialog1.Flags = cdlOFNHideReadOnly' 设置过滤器CommonDialog1.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*|"' 指定缺省的过滤器CommonDialog1.FilterIndex = 2' 显示“打开”对话框CommonDialog1.ShowOpen' 显示
回复

使用道具 举报

千问 | 2011-5-24 12:06:44 | 显示全部楼层
private sub command1_click() dim msg() as string '打开文件 open "c:\文本文件.txt" for input as #1 line input #1,rs msg=split(rs,"chr(5)") label1.caption=msg(0) label2
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行