Results 1 to 9 of 9

Thread: how to replace text stored in clipboard??

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Location
    germany
    Posts
    10

    Unhappy

    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
    der nico kann nich lesen und schreiben

  2. #2
    Lively Member
    Join Date
    Mar 2000
    Posts
    81
    can't you use myVariable = clipboard.gettext and then manipulate the string variable "myVariable" using those trendy Replace(), InStr(), etc. string manipulation functions?

  3. #3
    Lively Member
    Join Date
    Mar 2000
    Posts
    81
    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

  4. #4

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Location
    germany
    Posts
    10

    erm...

    i dont have the replace function.
    der nico kann nich lesen und schreiben

  5. #5
    Guest
    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

  6. #6

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Location
    germany
    Posts
    10

    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
    der nico kann nich lesen und schreiben

  7. #7
    Guest
    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

  8. #8

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Location
    germany
    Posts
    10

    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.
    der nico kann nich lesen und schreiben

  9. #9
    Guest
    When it crashes, what lines does it select (or is the error)?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width