VB读取文件复制粘贴问题

建立一个ini或txt的文件,然后vb读取和复制,从第一行读取,然后读取第二行直到文件里完(我打算这样,用timer来控制因为我用了鼠标定位,所以要有时间,比如:现在读取文件第一行,自动到剪贴板,然后鼠标到达指定的位子,然后时间到,就粘贴,然后又读取第二行如此循环)

第1个回答  2010-07-07
可以利用鼠标的单击事件处理这个任务,那样效果会更好。不用等待时间。
鼠标到达指定的位子,然后单击右键就粘贴,然后又读取第二行如此循环。
第2个回答  2010-07-07
不知道你的目的是啥 但是如果是文本或者ini的话可以用open函数 将文本放到本地变量方法如下
dim nN as strint,nM as string
Open "路径.txt/路径.ini" For Input As #1
nN=""
While Not EOF(1)
nM = ""
Line Input #1, nM
If nM <> "" Then
nN = nN & nM & vbCrLf
End If
Wend
Close #1
'最后文本的内容就到了nN变量中了.
第3个回答  2010-07-07
Option Explicit
Dim TxtLine() As String
Dim LineCount As Long

Private Sub TxtFile_Array(Path As String, TxtLine() As String)
Dim InputData As String
Dim TempInputData As String
Open Path For Input As #2
Do While Not EOF(2)
Line Input #2, InputData
TempInputData = Trim(InputData)
If TempInputData <> "" Then
ReDim Preserve TxtLine(LineCount) As String
TxtLine(LineCount) = TempInputData
LineCount = LineCount + 1
End If
Loop
Close #2
End Sub

Private Sub Form_Load()
Dim Path As String
Path = App.Path & "\test.txt"
TxtFile_Array Path, TxtLine
End Sub

Private Sub Timer1_Timer()
Static n As Long
n = n + 1
Clipboard.Clear
Clipboard.SetText TxtLine(n - 1)
Print Clipboard.GetText
SendKeys "^V"
If n >= LineCount Then n = 0
End Sub

参考资料:hyyly520 专门解答 MATLAB VB 基础问题

本回答被提问者采纳
相似回答