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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Putting Text on the clipboard 1

Status
Not open for further replies.

KingofSnake

Programmer
Jul 25, 2000
73
US
How could I make a program put text on the clipboard, so the user could then paste it on some text editor?
KingOfSnake - The only sports drink with ice crystals
(and marshmellos!)
 
To use the Clipboard for text, have menu options for Cut, Copy and Paste, and use the following code:

Private Sub mnuCopy_Click()
Clipboard.Clear
Clipboard.SetText Text1.SelText
End Sub

Private Sub mnuCut_Click()
Clipboard.Clear
Clipboard.SetText Text1.SelText
Text1.SelText = ""
End Sub

Private Sub mnuPaste_Click()
Text1.SelText = Clipboard.GetText()
End Sub


Simon
 
Hey, thanks Simon. I have another question: Why is this not working. I am using the dir function to get all the filenames of the mp3 files in a directory and put them in the dynamic array files$(). The problem is that it gets the files in random order, and it doesn't get all of the files. I don't understand why it does this thought, I've made another progam using the Dir function and it worked like a charm.

Private Sub cmdGetNames_Click()

ChDir$ txtDir.Text
Dim files$()
ReDim files$(1)
i = 1
files$(i) = Dir("*.mp3")
Do
i = i + 1
fle = Dir
If fle <> &quot;&quot; Then
ReDim Preserve files$(i)
files$(i) = fle
End If
Loop While fle <> &quot;&quot;

End Sub
KingOfSnake - The only sports drink with ice crystals
(and marshmellos!)
 
And about the clipboard, I have an array. How do I copy multiple lines to the clipboard, for example:

01 Song 1.mp3
02 Song 2.mp3

How could I put that on the clipboard in that format, rather that &quot;01 Song 1.mp302 Song 2.mp3&quot;?

Alternativley, how can I put multiple lines on a text box?

PS: Sorry for all the questions. I'll try to answer some soon :)
KingOfSnake - The only sports drink with ice crystals
(and marshmellos!)
 
I have just tested the code you are using and it worked just fine - all files returned, and in alphabetical order.
However, I can shorten the loop to the following:

fle = Dir(&quot;*.txt&quot;) ' no mp3's to test on!!
Do Until fle = &quot;&quot;
ReDim Preserve files(UBound(files) + 1)
files(UBound(files)) = fle
fle = Dir
Loop


Try this to see if you get any different results.

Simon
 
To have multiple lines in a text box, set the MultiLine property to True.
To append a new line to the text box (in code) use:

Text1.Text = Text1.Text &amp; vbCrLf &amp; &quot;new line&quot;

To copy multiple elements of your array to the clipboard, try this:

ClipBoard.SetText files(1) &amp; vbCrLf &amp; files(2) &amp; vbCrLf &amp; ...

Simon
 
Thanks for the help Swilliams. Don't know what I would do without ya!
KingOfSnake - The only sports drink with ice crystals
(and marshmellos!)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top