Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clipboard Paste Help VB6

Status
Not open for further replies.

AlfredSpecial

Programmer
Joined
Apr 4, 2005
Messages
161
Location
GB
What i am trying to do is copy text into various textboxes in a VB6 application.

example:
I copy data in an excel spreadsheet say from A1 to A50 to my clipboard.I now want a command button in my VB6 application that will paste this data into the following text boxes text1 to text50.

The code below will just put all of my clipboard into Text1.

Text1.SelText = Clipboard.GetText()

Any help appreciated

 
Here's a routine I wrote to parse up each column in a row (or rows) from an excel paste to the clipboard. Copy the clipboard to a string first, then call this routine for each column/row. Note: a newline will be returned at the end of each row.

Code:
Function ParseExcel(cutStr As String) As String

'   Parses lines pasted to the clipboard from Excel
'   Cells are separated by tabs, lines are separated by cr/lf

    Dim nlpos As Integer
    Dim tabpos As Integer
    
    If Len(cutStr) = 0 Then
    
'   We're done

        ParseExcel = ""
        Exit Function
    End If
        
'   Get positions of tab and newline, process based on which is first

    tabpos = InStr(1, cutStr, Chr(9))
    nlpos = InStr(1, cutStr, vbNewLine)
    If tabpos < nlpos And tabpos > 0 Then
        ParseExcel = Left(cutStr, tabpos - 1)
        cutStr = Mid(cutStr, tabpos + 1)
    ElseIf tabpos = 0 And nlpos = 0 Then
    
'   Handles non-Excel entry

        ParseExcel = cutStr
        cutStr = ""
    Else
        If nlpos = 1 Then
    
'   Got end of the line, return it

            ParseExcel = vbNewLine
            cutStr = Mid(cutStr, 3)
            Exit Function
        End If
        
'   Return element, but don't remove end of the line

        ParseExcel = Left(cutStr, nlpos - 1)
        cutStr = Mid(cutStr, nlpos)
    End If

End Function

"I think we're all Bozos on this bus!" - Firesign Theatre [jester]
 
Thanks ArtieChoke but im not sure what to do with this to get each row into a different text box?

 
The easiest way to do it is with a control array of text boxes. Then you can use a loop and call this routine each time you want to fill another text box. Have you considered a flex grid for this? It will look similar to an excel spreadsheet.

"I think we're all Bozos on this bus!" - Firesign Theatre [jester]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top