|
-
Feb 16th, 2000, 11:51 PM
#1
Thread Starter
New Member
Vb 5.0 in Windows NT 4.
I'm trying to copy from the clipboard, then split the text into separate lines.
Txt = Clipboard.GetText
pos = 1
While Txt <> "" And pos <= Len(Txt)
tempstr = Mid(Txt, pos, InStr(pos, Txt, vbCrLf))
pos = pos + Len(tempstr) + 1
' do something with the line
Wend
I want tempstr to hold each line from the clip board.
Then I want to do something with each line.
The problem is that the vbCrLf is only recognized correctly the first time. On the second line, tempstr ends up actually having 3 lines in it instead of only one.
Anyone know what I'm doing wrong? I know that pos=pos+len(tempstr)+1 might not be exactly right, but the problem I'm having doesn't seem to be related to that.
Wade
-
Feb 17th, 2000, 12:15 PM
#2
Try this:
Code:
txt = Clipboard.GetText
pos = 1
While txt <> "" And pos <= Len(txt)
If InStr(pos, txt, vbCrLf) < InStr(pos, txt, ChrW(13)) Then
tempstr = Mid(txt, pos, (InStr(pos, txt, vbCrLf) - pos))
Else
tempstr = Mid(txt, pos, (InStr(pos, txt, ChrW(13)) - pos))
End If
pos = pos + Len(tempstr) + 1
MsgBox tempstr
Wend
The instr returns the location number and in the mid function you were setting it as the length of the string you wanted giving you a much longer string every time. Subtracting the pos value from the instr gives you the accurate length.
------------------
Boothman
There is a war out there, and it is about who controls the information, it's all about the information.
-
Feb 17th, 2000, 12:23 PM
#3
Thread Starter
New Member
Originally posted by Boothman_7:
Try this:
<edited...>
The instr returns the location number and in the mid function you were setting it as the length of the string you wanted giving you a much longer string every time. Subtracting the pos value from the instr gives you the accurate length.
Thanks! Logic errors strike again! 
Wade
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|