Copy to Clipboard

haleswd
08-27-2003, 06:12 AM
I am a total newbie to VB programming. I got the program and took off. I have never programmed before, so I am a total novice. I have a little program that I am writing, but I have came across 2 little problems, which I am sure if very simple, but like I said, I am a newbie. When I hit a command button, I want to copy the text from a textbox and put it in the clipboard, so that I can flip to a Windows 2K application and paste it. I can't figure out how to do it. Also, I need to format labels and text boxes so that there is only 4 characters after the decimal. But I cannot figure out how to format it so that this happens. Can anyone please help a newbie. Thanks for your time.

Anz
08-27-2003, 06:45 AM
to format the value i would do this, but i bet there's a better way :rolleyes:


Private Function rFormat(rData As String) As String
If InStr(1, rData, ",", vbTextCompare) > 0 Then
rFormat = Mid(rData, 1, InStr(1, rData, ",", vbTextCompare) + 4)
End If
End Function

Lachy
08-27-2003, 06:56 AM
To copy to clipboard:


Clipboard.SetText "Your variable or string here"

Anz
08-27-2003, 07:01 AM
i tried it out with word and i needed to clear the clipboard first or didn't alway's work...


Clipboard.Clear
Clipboard.SetText "1234,5678", vbCFText

haleswd
08-27-2003, 07:22 AM
i made a quick test program with a text box and a command button, and i put the following lines of code in the click command of the button. i run the program, type something in the text field, hit the button and i get this error. please help


runtime error 424
object required


Private Sub cmdcopy_Click()
clipboard.Clear
clipboard.SetText "txtcopy.Text"
End Sub

Private Sub cmdcopy_Click()
clipboard.SetText "txtcopy.Text"
End Sub

Private Sub cmdcopy_Click()
clipboard.Clear
clipboard.SetText txtcopy.Text
End Sub

Private Sub cmdcopy_Click()
clipboard.SetText txtcopy.Text
End Sub

Private Sub cmdcopy_Click()
clipboard.Clear
clipboard.SetText txtcopy
End Sub


_________________________________________________________
i tried it out with word and i needed to clear the clipboard first or didn't alway's work...


Clipboard.Clear
Clipboard.SetText "1234,5678", vbCFText

Anz
08-27-2003, 07:47 AM
i tried but i don't get any error's...

be shure u have a textbox called -> txtcopy

what version of vb are u using???

(Ps: the quotes are not needed, exept if u want "txtcopy.text" to b the value)

haleswd
08-27-2003, 07:53 AM
at home i have visual basic 6, but i am at work, and i am not allowed to install it on my work pc, so i am testing this out on excel 2000's visual basic editor, but so far everything that i have done in it, works the same as what i do at my house. and i did name the txt box txtcopy, so i am not sure what to do now.


i tried but i don't get any error's...

be shure u have a textbox called -> txtcopy

what version of vb are u using???

(Ps: the quotes are not needed, exept if u want "txtcopy.text" to b the value)

Anz
08-27-2003, 08:01 AM
i am testing this out on excel 2000's visual basic editor

behole the origin of ur error :)

Anz
08-27-2003, 08:25 AM
the textboxes are not the same in excell i think, or the syntax is different,...

try copying the value of a cell in the clipboard in stead...

something like:


Sub CmdCopy()
Sheets("Sheet1").select

clipboard.Clear
clipboard.SetText Cells(1, 1)
End Sub

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum