-
my problem is : i need to know how to replace text that got stored to the clipboard with clipboard.settext .
the problem is that i need to replace certain letters in the text in the clipboard and then let it write to another textbox.
thanks for your response
-
can't you use myVariable = clipboard.gettext and then manipulate the string variable "myVariable" using those trendy Replace(), InStr(), etc. string manipulation functions?
-
Is this what you're looking for?
Code:
Private Sub Command1_Click()
Dim clipboardData As String
'get the data from the clipboard
clipboardData = Clipboard.GetText
'replace the letter a with the letter b
Replace clipboardData, "a", "b"
'display the result in a textbox
Text1.Text = clipboardData
End Sub
-
erm...
i dont have the replace function.
-
The Replace function is for VB6. If you do not have VB6, here is the replacement for it:
Code:
Public Function Replace(sIn As String, sFind As String, sReplace As String, Optional nStart As Long = 1, Optional nCount As Long = -1, Optional bCompare As VbCompareMethod = vbBinaryCompare) As String
Dim nC As Long, nPos As Integer, sOut As String
sOut = sIn
nPos = InStr(nStart, sOut, sFind, bCompare)
If nPos = 0 Then GoTo EndFn:
Do
nC = nC + 1
sOut = Left(sOut, nPos - 1) & sReplace & Mid(sOut, nPos + Len(sFind))
If nCount <> -1 And nC >= nCount Then Exit Do
nPos = InStr(nStart, sOut, sFind, bCompare)
Loop While nPos > 0
EndFn:
Replace = sOut
End Function
-
didnt work :(
this is my sourcecode :
Public Function Replace(sIn As String, sFind As String, sReplace As String, Optional nStart As Long = 1, Optional nCount As Long = -1, Optional bCompare As VbCompareMethod = vbBinaryCompare) As String
Dim nC As Long, nPos As Integer, sOut As String
sOut = sIn
nPos = InStr(nStart, sOut, sFind, bCompare)
If nPos = 0 Then GoTo EndFn:
Do
nC = nC + 1
sOut = Left(sOut, nPos - 1) & sReplace & Mid(sOut, nPos + Len(sFind))
If nCount <> -1 And nC >= nCount Then Exit Do
nPos = InStr(nStart, sOut, sFind, bCompare)
Loop While nPos > 0
EndFn:
Replace = sOut
End Function
Private Sub Command1_Click()
Dim clipboardData As String
Clipboard.SetText (Text1.Text)
clipboardData = Clipboard.GetText
'replace the letter a with the letter b
Replace clipboardData, "1", "2"
Text2.Text = Clipboard.GetText
End Sub
but it wont work :(
im using vb 5
-
Why are you not just replacing what's in text1?
Code:
Text1.text = Replace(Text1.text, "1", "2")
Text2.Text = Text1.text
If you want to stick to the clipboard, try this:
Code:
Private Sub Command1_Click()
Dim clipboardData As String
Clipboard.SetText (Text1.Text)
clipboardData = Clipboard.GetText
clipboardData = Replace(clipboardData, "1", "2")
Clipboard.SetText (clipboardData)
Text2.Text = Clipboard.GetText
End Sub
-
it wont work ...
i did it an it worked well, thank you so long, but after i tried it with some letters from lowercase to uppercase with about 12 of them the programm allways crashes.
-
When it crashes, what lines does it select (or is the error)?