首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

如何循环引用文本文件中的每一行数字

2012-01-21 
怎么循环引用文本文件中的每一行数字?我的文本文件中的内容如下:1234567234567678945612345..........我想

怎么循环引用文本文件中的每一行数字?
我的文本文件中的内容如下:
1234567
234567
6789456
12345
..........
 
我想每次引用一行数字生成如下的内容:
ADD XXX:1234567
MOD XXX:1234567
CHK XXX:1234567
ADD XXX:234567
MOD XXX:234567
CHK XXX:234567
...............


原始的文本文件是存在的,我想引用后生成一个新的文本文件。如何操作呢,请高手指教!!!!

[解决办法]

VB code
Private Sub Command1_Click()    Call BuildNewFile("X:\Temp\1.txt", "X:\Temp\2.txt")End SubPrivate Sub BuildNewFile(strINfile$, strOUTfile$)    Dim iFa&, iFb&, strInput$    iFa = FreeFile()    Open strINfile For Input As #iFa    iFb = FreeFile()    Open strOUTfile For Output As #iFb    While Not EOF(iFa)        Line Input #iFa, strInput        If (Len(strInput) > 0) Then            Print #iFb, "ADD XXX:"; strInput            Print #iFb, "MOD XXX:"; strInput            Print #iFb, "CHK XXX:"; strInput        End If    Wend    CloseEnd Sub
[解决办法]
VB codePrivate Sub Command1_Click()
Call BuildNewFile("X:\Temp\1.txt", "X:\Temp\2.txt")
End Sub

Private Sub BuildNewFile(strINfile$, strOUTfile$)
Dim iFa&, iFb&, strInput$
iFa = FreeFile()
Open strINfile For Input As #iFa
iFb = FreeFile()
Open strOUTfile For Output As #iFb
While Not EOF(iFa)
Line Input #iFa, strInput
If (Len(strInput) > 0) Then
Print #iFb, "ADD XXX:"; strInput & ",ABC;"
Print #iFb, "MOD XXX:"; strInput & ",ACD;"
Print #iFb, "CHK XXX:"; strInput & ",ACE;"
End If
Wend
Close
End Sub
[解决办法]
Sub Command1_Click()
Call BuildNewFile("d:\Temp\1.txt", "d:\Temp\2.txt")
End Sub

Private Sub BuildNewFile(strINfile$, strOUTfile$)
Dim iFa&, iFb&, strInput$, v
iFa = FreeFile()
Open strINfile For Input As #iFa
iFb = FreeFile()
Open strOUTfile For Output As #iFb
While Not EOF(iFa)
Line Input #iFa, strInput
v = Split(strInput, Chr(32))
  
If (Len(strInput) > 0) Then
Print #iFb, "ADD XXX:"; v(0) & ","; v(1); "ABC;"
Print #iFb, "MOD XXX:"; v(0) & ","; v(1); "ACD;"
Print #iFb, "CHK XXX:"; v(0) & ","; v(1); "ACE;"
End If
Wend
Close
End Sub

热点排行