|
|
Hi,
This is an easy one, I think.
I have written a procedure behind a button e.g.
Private Sub btnProcess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProcess.Click
I want to call this procedure from a timer function, how is this done?
Thanks in advance.
|
|
|
|
|
How would you call any subroutine?
The best things in life are not things.
|
|
|
|
|
1.
why would you put code in a button click handler, if what you want is have it executed by a timer tick handler?
2.
you can simulate a button being clicked by calling Button.PerformClick
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.3
|
|
|
|
|
You don't put the code in the Button Click event handler. You put code in its own Sub, then call it from the Button Click handler and the Timer Tick event handler.
|
|
|
|
|
just call btnProcess.PerformClick() in timer.tick event.
or
btnProcess_Click(sender, nothing) in timer.tick event.
|
|
|
|
|
That's the very wrong way to do it. It's lazy and leads to other possible issues that can't be traced down easily.
If there is code that needs to be executed from multiple places you stick it in its own method with a name that has meaning as to what the code does. You don't "hide" it inside an event handler.
|
|
|
|
|
its up to the developer to decide... and ofcourse the one who asked this question knows how to move all the statements in the button's click event to a sub-routine and call the same sub-routine in the button's click event. its that simple..let them do in their own way. can you describe why it is wrong way?
|
|
|
|
|
|
<br />
Option Explicit<br />
Dim DB As ADODB.connection<br />
Dim strString As String<br />
Dim rs As ADODB.recordset<br />
Dim cs As ADODB.connection<br />
Dim ks As ADODB.recordset<br />
Private Const CB_SHOWDROPDOWN As Long = &H14F<br />
Private Const CB_GETDROPPEDSTATE As Long = &H157<br />
Private Drop As Boolean<br />
Private Const CB_FINDSTRING = &H14C<br />
Private Const CB_SELECTSTRING = &H14D<br />
Private Const CB_LIMITTEXT = &H141<br />
Private Const CB_ERR = (-1)<br />
Private Sub db_conn()<br />
Set DB = New ADODB.connection<br />
<br />
DB.CursorLocation = adUseClient<br />
<br />
DB.Open "PROVIDER = Microsoft.Jet.OLEDB.4.0;Data Source =" & App.Path & "\Medrar.mdb;"<br />
End Sub<br />
Private Sub cmdAcchu_Click()<br />
Dim obj, rs As ADODB.recordset, SQL As String<br />
<br />
Set rs = New ADODB.recordset<br />
<br />
<br />
Set rs = New ADODB.recordset<br />
strString = " SELECT cusname,idnumb,mobi,pron,proc,blkno,lannum,sqland,cost,comiso,addit,deduc,gtot,vali,rename" & _<br />
" From reser" & _<br />
" WHERE reno = '" & Combo1.Text & "' "<br />
<br />
<br />
rs.Open strString, DB, adOpenStatic<br />
' Set rs = db.Execute(strString)<br />
'With reportPS<br />
If Not rs.EOF Then<br />
Set Reservation.DataSource = rs.DataSource<br />
<br />
<br />
'-----------------------------------------------------------------------------------------------'<br />
'PageHeader<br />
Reservation.Sections("PageHeader").Controls("lblcusname").Caption = CStr(rs!cusname)<br />
Reservation.Sections("PageHeader").Controls("lblidnumber").Caption = CStr(rs!idnumb)<br />
Reservation.Sections("PageHeader").Controls("lblmobile").Caption = CStr(rs!mobi)<br />
Reservation.Sections("PageHeader").Controls("lblPron").Caption = CStr(rs!pron)<br />
Reservation.Sections("PageHeader").Controls("lblProc").Caption = CStr(rs!proc)<br />
Reservation.Sections("PageHeader").Controls("lblBlkno").Caption = CStr(rs!blkno)<br />
Reservation.Sections("PageHeader").Controls("lblLn").Caption = CStr(rs!lannum)<br />
Reservation.Sections("PageHeader").Controls("lblsql").Caption = CStr(rs!sqland)<br />
Reservation.Sections("PageHeader").Controls("lblcost").Caption = CStr(rs!cost)<br />
Reservation.Sections("PageHeader").Controls("lbCommi").Caption = CStr(rs!comiso)<br />
Reservation.Sections("PageHeader").Controls("lblAdd").Caption = CStr(rs!Addit)<br />
Reservation.Sections("PageHeader").Controls("lblDed").Caption = CStr(rs!deduc)<br />
Reservation.Sections("PageHeader").Controls("lblGt").Caption = CStr(rs!Gtot)<br />
Reservation.Sections("PageHeader").Controls("lblVali").Caption = CStr(rs!vali)<br />
Reservation.Sections("PageHeader").Controls("lblrname").Caption = CStr(rs!rename)<br />
Reservation.Sections("PageHeader").Controls("lblcname").Caption = CStr(rs!cusname)<br />
Reservation.Sections("PageHeader").Controls("lblvali1").Caption = CStr(rs!vali)<br />
'-----------------------------------------------------------------------------------------------'<br />
<br />
<br />
Reservation.Refresh<br />
Reservation.Show vbModal<br />
<br />
<br />
End If<br />
'End With<br />
<br />
<br />
'For Each obj In reportPS.Sections("PageHeaders").Controls<br />
' If TypeOf obj Is RptTextBox Then<br />
' obj.DataMember = rs.DataMember<br />
<br />
'End If<br />
'Next<br />
<br />
<br />
End Sub<br />
Private Sub cmdbye_Click()<br />
Unload FrmResPrnt<br />
End Sub<br />
Private Sub Combo1_Click()<br />
Dim cnemployee As New ADODB.connection<br />
Dim rsemployee As New ADODB.recordset<br />
<br />
Call connection(cnemployee, App.Path & "\Medrar.mdb", "endromida")<br />
Call recordset(rsemployee, cnemployee, "SELECT * FROM Reser WHERE Reno ='" & Combo1.Text & "'")<br />
<br />
If rsemployee.RecordCount = 0 Then<br />
MsgBox "The record you requested could not be found.", vbExclamation, "Medrar"<br />
Exit Sub<br />
End If<br />
<br />
With rsemployee<br />
<br />
<br />
End With<br />
<br />
Set cnemployee = Nothing<br />
Set rsemployee = Nothing<br />
End Sub<br />
Private Sub Combo1_KeyPress(KeyAscii As Integer)<br />
Dim t$, rez&, l&<br />
Combo1.SelText = ""<br />
t$ = Combo1.Text & Chr$(KeyAscii)<br />
rez& = SendMessage(Combo1.hwnd, CB_FINDSTRING, -1, ByVal t$)<br />
If rez& <> CB_ERR Then<br />
l& = Len(t$)<br />
Combo1.Text = Combo1.list(rez&)<br />
Combo1.ListIndex = rez&<br />
KeyAscii = 0<br />
Combo1.SelStart = l&<br />
Combo1.SelLength = Len(Combo1.Text) - l&<br />
End If<br />
Dropdown<br />
End Sub<br />
Private Sub Combo1_LostFocus()<br />
Dim t$, rez&<br />
t$ = Combo1.Text<br />
rez& = SendMessage(Combo1.hwnd, CB_FINDSTRING, -1, ByVal t$)<br />
End Sub<br />
Private Sub Dropdown()<br />
If Drop Then<br />
If SendMessage(Combo1.hwnd, CB_GETDROPPEDSTATE, 0, ByVal 0&) = 0 Then<br />
Call SendMessage(Combo1.hwnd, CB_SHOWDROPDOWN, 1&, 0&)<br />
End If<br />
End If<br />
End Sub<br />
Private Sub res()<br />
Set cs = CreateObject("Adodb.connection")<br />
cs.Provider = "Microsoft.jet.oledb.4.0"<br />
cs.Open App.Path & "\Medrar.mdb"<br />
Set ks = New ADODB.recordset<br />
ks.Open "Select reno from reser", cs, adOpenKeyset, adLockOptimistic<br />
While Not ks.EOF<br />
Combo1.AddItem ks.Fields("Reno")<br />
ks.MoveNext<br />
Wend<br />
ks.Close<br />
Set ks = Nothing<br />
Drop = True<br />
End Sub<br />
Private Sub Form_Load()<br />
Call res<br />
End Sub<br />
<br />
Run Time Error:3709
|
|
|
|
|
please read my sig.
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.3
|
|
|
|
|
Maybe this[^] will help you... or even us.
|
|
|
|
|
First, you'll have to find out what's causing the error; Knowledge Base[^]
Next, you fix it
Bastard Programmer from Hell
|
|
|
|
|
Are there no bounds to your wisdom at all?
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.3
|
|
|
|
|
MY GOD MAN! HOW DARE YOU SEARCH THE SACRED KNOWLEDGE BASE!
Stay away from me. I don't want to get hit by the lightning that's coming for you.
|
|
|
|
|
|
Hi,
I get the following message when I try and delete a file.
"System.IO.IOException - The process cannot access the file 'filename' because it is being used by another process."
My cut down code is as follows
Dim aryFi As IO.FileInfo() = diFolder.GetFiles("*.pdf")
For Each fi In aryFi
sFileName = fi.Name
fi.delete
Next
Basically what I am doing is that depending what file is in the folder, delete it once I get various information about it that file. The above code is a cut down version. What other way would you delete a file or is this the best way. If so, what am I doing wrong.
Thanks in advance.
modified on Wednesday, May 25, 2011 8:30 AM
|
|
|
|
|
The "other process" still has the file open. There's no way to delete it until the other process closes the file.
You could force it closed using some hacked techniques, but that'll only crash the other process that still has it open.
|
|
|
|
|
Hi,
that is one of the more confusing Windows/.NET error messages. The "other process" may well be your own process, it really should say "some process".
So it could be as well your own process having read or written the file, or having interrogated the file system about its characteristics. Make sure you don't have open streams, files, fileinfo's, etc; close and dispose them before executing the code that throws the exception.
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.3
|
|
|
|
|
Maybe it should just say "... is currently in use."
Panic, Chaos, Destruction.
My work here is done.
or "Drink. Get drunk. Fall over." - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
Have a bit more patience with newbies. Of course some of them act dumb -- they're often *students*, for heaven's sake. -- (Terry Pratchett, alt.fan.pratchett)
|
|
|
|
|
Yes and no. Shortening the message is one way of improving the probability it hits the truth, but then it is also less informative. I'd rather have it say: "the file is currently in use, either by your own process or by some other process." That way, the reader knows he has to actually look for two quite different possibilities.
And then, of course, they should put in some more effort and find out which of those two it is, and provide the more specific message; either "the file is currently in use by your own process", or "the file is currently in use by another process (processname, processID)". But that would be helping the user, something Windows isn't inclined to do much.
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.3
|
|
|
|
|
Hi,
I have a project created using vb.net 2005. I need to collect data and generate a input file for a EXE file which will take 2 min to execute the exe file.
I also create a form with progressbar and Stop button, since I cannot get status of the EXE file, I just set the value of the progressbar from 1 ~ 100 then repeat. codes as the following
Dim p As New System.Diagnostics.Process()
p.StartInfo.FileName = Application.StartupPath & "\" & sAppPath
p.StartInfo.Arguments = fileName
'Do not use the system shell to start the program this is so we can hide the command dos window
p.StartInfo.UseShellExecute = False
p.StartInfo.WorkingDirectory = strOutputFilePath
' Show no dos window if false
p.StartInfo.CreateNoWindow = True
p.StartInfo.RedirectStandardOutput = True
Dim progBarFrm As New FormProgressBar
progBarFrm.Show()
p.Start
''''''''''''''
But when I run the above code, the progressbar value doesn't change. But if I comment out p.Start line, the progressbar works fine.
How can I show the progressbar while the process is running, if you have some sample, that's best.
Thanks!
|
|
|
|
|
You can show the progress bar all you want. You don't haven't shown any code that updates the progress bar at all.
p.Start is not a blocking call, so your process will launch and run independent of this code.
|
|
|
|
|
On top of what Dave said, please use PRE tags when showing code snippets, that will improve readability.
And tell us where that code is sitting; and if threads are involved, we need to know that too.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Davd and Luc,
Thanks for your reply.
Acutally my code is like the following, I didn't use thread, I am not familiar with it.
Dim progBarFrm As New FormProgressBar
progBarFrm.Show()
try
p.Start()
Catch ex As Exception
ShowValidationMessage("Unexception error is caught, please close WinTAP and try again.", "Error")
progBarFrm.Close()
Return
End Try
rtnStr = p.StandardOutput.ReadToEnd()
p.WaitForExit(5400000)
If Not p.HasExited Then
p.Kill()
End If
progBarFrm.Close()
|
|
|
|
|