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

Send value (from label or textbox) to clipboard?? 1

Status
Not open for further replies.

ViperGTS

Programmer
Jun 4, 2002
18
US
I have a count-up timer that I built using VB6. I have all of the proposed functions working, save one.
I would like to have the accumulated time (currently displayed in a 'label' sent (automatically) to the clipboard so that I can paste that value into a record of time spent on a project.
The 'send to clipboard' event would take place when I click the 'Stop' button (which haults the count and awaits user-input to restart from the current value or to be reset to 00:00:00 for a new count).
I have tried to modify source code (that was supposed to send to clipboard) that I have gleaned from other sources but, nothing seems to work. I have since removed the attempts from my code and didn't have sense enough to keep them :(
I am very 'green' in VB but nonetheless happy with my project thus far - mainly because it works!!
I am looking for a reference to (or I am looking for help writing) the necessary code. I have included what I have so far (save the portion that I dismembered and dumped!)

Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Private Sub Form_Load()
lblTicker1.Caption = "00:00:00" 'Formats the label view
SetWindowText LvTimer3.hwnd, "Live Timer 3"
End Sub
Private Sub tmrStart1_Click()
tmrTicker1.Enabled = True 'Start timer and then . . .
'Form1.WindowState = 1 'Minimizes form to the Task Bar. NOTE: timer is still counting
LvTimer3.WindowState = vbMinimized
End Sub
Private Sub tmrStop1_Click()
tmrTicker1.Enabled = False 'Stops timer; but keeps app live on desktop
'<--Clicking Start again will reactivate timer starting @ the current count value. You can restart the count multiple times always beginning with the last value counted.-->
End Sub
Private Sub tmrClose1_Click()
End ' Closes the Application
End Sub
Private Sub tmrClear1_Click()
' Clear the current value of timer
lblTicker1.Caption = &quot;00:00:00&quot; 'Resets Timer to zero for next count.
txtTicker1.Text = &quot;00:00:00&quot; 'Resets Textbox to zero for next count.
tmrTicker1.Enabled = False
End Sub
Private Sub tmrTicker1_Timer() 'Timer for &quot;count-up&quot;
lblTicker1.Caption = Format(TimeValue(lblTicker1.Caption) + TimeValue(&quot;00:00:01&quot;), &quot;hh:mm:ss&quot;) 'Formats the display view and always adds &quot;1&quot; to time.
txtTicker1.Text = Format(TimeValue(lblTicker1.Caption) + TimeValue(&quot;00:00:01&quot;), &quot;hh:mm:ss&quot;) 'Formats the display view and always adds &quot;1&quot; to time.
End Sub 'Oz; 1-June-2002

Thank you, in advance!

ViperGTS
 
Take a look at Clipboard.GetText and Clipboard.SetText. They are built in functions of VB. Hope this helps If you choose to battle wits with the witless be prepared to lose.
[machinegun][ducky]
 
foada, thanx for the tip but I am considering myself to be 'clipboard challanged' at this point. I have tried several combinations of the get and set for the clipboard but haven't managed to get it to work. I did however crash my timer app a couple of times (which was at least more than was happening with previous code for this purpose LOL!)
Thanx again,

Viper
 
OK Here is aquick example for you.

With a new project add a label named lblCount, a label named lblResult, a timer named tmr, and a command button named cmdStop then drop this code into the form

Option Explicit
Dim iX As Long

Private Sub cmdStop_Click()
iX = 0
Clipboard.SetText lblCount.Caption
lblresult.Caption = Clipboard.GetText
End Sub

Private Sub tmr_Timer()
iX = iX + 1
lblCount.Caption = CStr(iX)
End Sub

That should get you pointed in the right direction. Hiope this helps [spin]

If you choose to battle wits with the witless be prepared to lose.
[machinegun][ducky]
 
Oh yeah, set the timer interval to some other value than the default '0' [roll2]
If you choose to battle wits with the witless be prepared to lose.
[machinegun][ducky]
 
After I posted a response last eve, I went to VB and persued the tweaking again. Eventually I ended up with the result that I was looking for. I cannot believe it!! However, were it not for your original response I would not have gone the direction that I did. The code ends up to be as follows:

For the timer Start-->
Private Sub tmrStart1_Click()
tmrTicker1.Enabled = True 'Start timer and then . . .
Clipboard.Clear 'Clears the clipboard

For the timer Stop I chose-->
tmrTicker1.Enabled = False 'Stop
Clipboard.SetText txtTicker1 'Copy the current count

And this proves to work well. As the timer is set up to resume it's count if the Start button is pressed again, the only thing that I need to do is resolve the difference between Start and Stop (when I am running a continuation of the same count) and having the correct info on the clipboard at that time. But that will not be an issue now.
Hopefully I will not need error handlers - I haven't run into any errors and I have done most everything backward and incorrect that I can think of without issue.

I will take your suggested code (above) and save it for future use as I intend to refine the process a bit.

ThanX! Again!!

ViperGTS
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top