|
-
Jul 17th, 2008, 12:23 PM
#1
Thread Starter
Addicted Member
[RESOLVED] automated copy and paste
i want to create a program with has a timer, which is changeable i.e timer cam be manually changed and when the timer is up it copies a value from a text box to a label.
e.g. if timer is set to 1 min and when timer is up it copies the value in text box 1 to label1, and it keeps looping until it reaches 5 min.
the value/data in the text box is linked to a external file.
any ideas?
-
Jul 17th, 2008, 02:06 PM
#2
Re: automated copy and paste
Is this what you mean?
Code:
lblLabel.Caption = txtTextbox.Text
-
Jul 17th, 2008, 03:09 PM
#3
Thread Starter
Addicted Member
Re: automated copy and paste
what i mean is if i have a timer and set the timer to e.g. 1 min and if 1min is up it will copy first line of a text box and the next time the second line and so on. when teh form loads i want it to load a txt file which hold the data.
-
Jul 17th, 2008, 03:37 PM
#4
Re: automated copy and paste
Well here's one way to do it:
Code:
Static intLineNum as Integer
Dim strLines() as String
strLines = Split(txtTextbox.Text, vbNewLine)
If UBound(strLines) > intLineNum Then intLineNum = 0
lblLabel.Caption = strLines(intLineNum)
intLineNum = intLineNum + 1
If you don't know how to load a file, see the Files section of our Classic VB FAQs (in the FAQ forum, which is shown near the top of our home page)
-
Jul 17th, 2008, 03:40 PM
#5
Thread Starter
Addicted Member
Re: automated copy and paste
one question where would i insert that coding?
-
Jul 17th, 2008, 03:43 PM
#6
Thread Starter
Addicted Member
Re: automated copy and paste
currently i am using this timer
Code:
Private Sub Form_Load()
lblwarning.Visible = False
Timer1.Interval = 970
Hours = 0
Minutes = 0
Seconds = 0
time = 0
Show vbModeless
Refresh
end sub
Private Sub lbltime_Change()
If lbltime.Caption < "00:00:16" Then
lblwarning.Visible = True
Else
lblwarning.Visible = False
End If
If lbltime.Caption = "00:00:00" Then
MsgBox "hello"
lblwarning.Visible = False
Text11.Text = ""
Text12.Text = ""
Text11.Locked = False
Text12.Locked = False
cmdStart.Enabled = True
End If
If lblwarning.Visible = True Then
lbltime.ForeColor = &HFF&
Else
lbltime.ForeColor = &H80000012
End If
End Sub
Private Sub Timer1_Timer()
Timer1.Enabled = False
If (Format$(time, "hh") & ":" & Format$(time, "nn") & ":" & Format$(time, "ss")) <> "00:00:00" Then 'Counter to continue loop until 0
time = DateAdd("s", -1, time)
lbltime.Visible = False
lbltime.Caption = Format$(time, "hh") & ":" & Format$(time, "nn") & ":" & Format$(time, "ss")
lbltime.Visible = True
Timer1.Enabled = True
Else
'Turn off timer, set off alarm, and enable reset.
Timer1.Enabled = False
End If
End Sub
Private Sub Mydisplay()
'This code is common to all three text boxes so I
'put it in it's own sub.
'Extract the numbers from the text boxes by using
'the Val() statement.
Minutes = Val(Text11.Text)
Seconds = Val(Text12.Text)
'Convert variables to time format
time = TimeSerial(Hours, Minutes, Seconds)
'Display the converted time variable in label 1
lbltime.Caption = Format$(time, "hh") & ":" & Format$(time, "nn") & ":" & Format$(time, "ss")
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
Private Sub cmdpause_Click()
If Timer1.Enabled = True Then
Timer1.Enabled = False
Me.Caption = "Timer - Paused..."
Command1.Visible = True
cmdpause.Visible = False
Command1.SetFocus
cmdStart.Enabled = False
Else
End If
End Sub
Private Sub cmdStart_Click()
Text11.Locked = True
Text12.Locked = True
lblwarning.Visible = False
Timer1.Enabled = True
Me.Caption = "Timer"
cmdStart.Enabled = False
End Sub
Private Sub cmdStop_Click()
cmdStart.Enabled = True
Text11.Text = ""
Text12.Text = ""
Text11.Locked = False
Text12.Locked = False
cmdpause.Visible = True
Command1.Visible = False
End Sub
-
Jul 17th, 2008, 03:53 PM
#7
Re: automated copy and paste
Well you want it to happen when a Timer reaches its Interval, so put it into the TimerName_Timer event.
-
Jul 17th, 2008, 05:11 PM
#8
Re: automated copy and paste
Here's some code that might help simplify things:
Code:
Dim LineNum As Integer, StrLines() As String
Private Sub Form_Load()
Open "MyTextFile.txt" For Input As #1
Text1.Text = Input$(LOF(1), #1)
StrLines = Split(Text1.Text, vbNewLine)
ReDim Preserve StrLines(UBound(StrLines))
Label1.Caption = vbNullString
Timer1.Interval = 60000
End Sub
Private Sub Timer1_Timer()
If LineNum <= UBound(StrLines) Then
Label1.Caption = StrLines(LineNum)
LineNum = LineNum + 1
End If
End Sub
Every minute a new line is copied and pasted to the label's caption based on what is in the text box. The text box displays what is in the text file. I'll let you add the rest of the controls and code to reset the timer to display what you want after LineNum reaches 5.
-
Jul 18th, 2008, 12:56 PM
#9
Thread Starter
Addicted Member
Re: automated copy and paste
thanks the coding helped, one last question how do i link a slider to the timer i.e so if i move the slider up it adjusts the timer, and is it possible to add more than one slider to the program and possibly loop i.e slider 1 first then 2 and so on.
-
Jul 18th, 2008, 02:10 PM
#10
Re: automated copy and paste
 Originally Posted by adam786
thanks the coding helped, one last question how do i link a slider to the timer i.e so if i move the slider up it adjusts the timer, and is it possible to add more than one slider to the program and possibly loop i.e slider 1 first then 2 and so on.
Not sure you want to do that. That would complicate things may drive the user crazy. For example, if you move the slider and adjust the timer at the same time, what lines from the text box get skipped or written to the label when the timer is supposed to be controlling the text display?
-
Jul 18th, 2008, 02:36 PM
#11
Thread Starter
Addicted Member
Re: automated copy and paste
ok i understand what you are saying. on the other hand how would i make the timer inervals relate or link to a slider?
-
Jul 18th, 2008, 03:20 PM
#12
Re: automated copy and paste
 Originally Posted by adam786
ok i understand what you are saying. on the other hand how would i make the timer inervals relate or link to a slider?
Code:
Dim LineNum As Integer, StrLines() As String
Const MaxInterval = 60000 ' 60 seconds
Private Sub Form_Load()
Open "MyTextFile.txt" For Input As #1
Text1.Text = Input$(LOF(1), #1)
StrLines = Split(Text1.Text, vbNewLine)
Close
ReDim Preserve StrLines(UBound(StrLines))
Label1.Caption = vbNullString
Timer1.Interval = MaxInterval ' Once per minute
End Sub
Private Sub Slider1_Scroll()
' Once per minute to once every 5.45 seconds peak speed
Timer1.Interval = MaxInterval / (Slider1.Value + 1)
End Sub
Private Sub Timer1_Timer()
If LineNum <= UBound(StrLines) Then
Label1.Caption = StrLines(LineNum)
LineNum = LineNum + 1
End If
End Sub
The interval changes as you move the slider, starting at slowest speed. You have to get through the previous interval setting before the next one goes into affect. I think you can probably live with that.
-
Jul 19th, 2008, 09:15 AM
#13
Thread Starter
Addicted Member
Re: automated copy and paste
OK i tried to run your code and it gives me an error message
run timer error 53
file not found
and it also highlights the following code
Open "mytextfile.txt" For Input As #1
the label, text box, timer and scroll are all set to what is in the coding.
-
Jul 20th, 2008, 04:56 AM
#14
Thread Starter
Addicted Member
Re: automated copy and paste
is it possible to change the intervals i.e increase them?
-
Jul 20th, 2008, 08:42 AM
#15
Re: automated copy and paste
 Originally Posted by adam786
OK i tried to run your code and it gives me an error message
run timer error 53
file not found
and it also highlights the following code
Open "mytextfile.txt" For Input As #1
the label, text box, timer and scroll are all set to what is in the coding.
Adam, just build a sample textfile with a bunch of lines using Notepad with the file name "MyTextFile.txt" and save it to the VB6 subdirectory. Or, change "MyTextFile.txt" to the name of a text file that you already have assembled for the project.
I believe you are close to the maximum interval for a timer control. To increase that to a longer delay is feasible but would require some fancier code. I cannot imagine why it would it take longer than one minute for a user to read one line of a typical text file.
Perhaps you need a Previous command button that takes the user immediately back to the previous line if it advances to the next line too quickly and a Next command button that advances the use to the next line immediately. In short, allow the user to have some control of the speed in addition the automatic timer advance and the slider.
Finally, I recommend that you examine and report what the objective of this project is before you proceed any further on it with this forum.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|