|
Hi Dave (that's my name too )
I found a nice program at this link: "http://abstractvb.com/code.asp?A=1081" by someone named Jayesh Jain where I thought his coding technique was useful.
I agree very much with you that the FSW class is not very well documented, particularly in how various combinations of "OR" statements can be expected to behave when messing around with files.
In Jain's code, he uses a combination of "ORing" the .DirectoryName, .Filename, and finally the .Attributes enumerators to define his .NotifyFilter property, e.g.:
mw.NotifyFilter = NotifyFilters.DirectoryName
mw.NotifyFilter = mw.NotifyFilter Or NotifyFilters.FileName
mw.NotifyFilter = mw.NotifyFilter Or NotifyFilters.Attributes
(where mw is an instance of FileSystemWatcher)
he then defines the following handlers:
AddHandler mw.Changed, AddressOf logchange
AddHandler mw.Created, AddressOf logchange
AddHandler mw.Deleted, AddressOf logchange
AddHandler mw.Renamed, AddressOf logrename
and then the following routines (the .Renamed event passes a different signature and thus needs it's own subroutine):
Private Sub logchange(ByVal source As Object, ByVal e As _
System.IO.FileSystemEventArgs)
If e.ChangeType = IO.WatcherChangeTypes.Changed Then
txt_folderactivity.Text &= "File " & e.Name & _
" has been changed" & vbCrLf
End If
If e.ChangeType = IO.WatcherChangeTypes.Created Then
txt_folderactivity.Text &= "File " & e.Name & _
" has been created" & vbCrLf
End If
If e.ChangeType = IO.WatcherChangeTypes.Deleted Then
txt_folderactivity.Text &= "File " & e.Name & _
" has been deleted" & vbCrLf
End If
End Sub
Public Sub logrename(ByVal source As Object, ByVal e As System.IO.RenamedEventArgs)
txt_folderactivity.Text &= "File" & e.OldName & " has been renamed to " & e.Name & vbCrLf
End Sub
I played with this a little, and came up with this logic table:
1) Files streamed into a folder will trigger both the .changed and .created events
2) Files streamed over an already existing files will trigger (2) .changed events
3) Files that are deleted will trigger only the .deleted event
4) Files that have their names changed will trigger both the .renamed and .changed events
5) Files that are dragged/droped into the folder will trigger both a .created and .changed event
6) Files that are created within the folder by right-clicking-->Add new, will trigger only the .created event
7) Files that exist within the directory and are dragged out of it will trigger a .deleted event
8) Opening, editing, and saving changes to a file will trigger (2) .changed events
As you can see, many of these actions will only trigger the .changed event once (1, 4, and 5),...so if place your "log to file" code in the "e.ChangeType = IO.WatcherChangeTypes.Changed" If-then statement above, you should only get (1) entry.
Anyway, that's how I use this class,..just play with it until the actions you expect only cause a single .change event to trigger,..
oh well,...not as "clean" an approach as i'd prefer,.but hopefully it'll work for you!!
-Dave
Dave
|
|
|
|
|
Dave,
Thanks for getting back with me. Much appreciated.
Anyway. I must of read an article similar to Jayesh Jain on another interent site before because I had been also playing with simialar example.
Anyway, Jain code works the sameway with the "Change Events" you are correct about limiting the number of "Notifyfilters" to use. I disagree on how Jain uses the following example set for the filter.
wf.NotifyFilter = wf.NotifyFilter Or IO.NotifyFilters.FileName
wf.NotifyFilter = wf.NotifyFilter Or IO.NotifyFilters.Attributes
These statements cause the "FileSystemWatcher" to change more then once for a single change on the file.
Instead use this ....
wf.NotifyFilter = IO.NotifyFilters.FileName
wf.NotifyFilter = IO.NotifyFilters.Attributes
Also, the programmer needs to decide what kind of event to watch for ie. "Change" or "Created". I would not use both for the same "FileSystemWatcher" class.
I used the "wf.NotifyFilter = IO.NotifyFilters.LastAccess" instead of Jain's example because it still detect the events without the "change" events occuring mupliple times.
Keep intouch and I will continue to look for your comments.
Below is what I had came up with...
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
wf = New System.IO.FileSystemWatcher
On Error Resume Next
wf.Path = Me.txtWatchPath.Text
wf.Filter = Me.txtBoxFilter.Text
wf.NotifyFilter = IO.NotifyFilters.LastAccess Or IO.NotifyFilters.FileName
' add the handler to each event
AddHandler wf.Changed, AddressOf logChange
' add the rename handler as the signature is different
AddHandler wf.Renamed, AddressOf logRename
AddHandler wf.Error, AddressOf errorlogChange
On Error Resume Next
If Me.chkWatchsubDirecties.Checked = True Then
wf.IncludeSubdirectories = True
Else
wf.IncludeSubdirectories = False
End If
wf.EnableRaisingEvents = True
Me.btnStart.Enabled = False
Me.btnStop.Enabled = True
Me.txtBoxFilter.ReadOnly = True
' Turn off the update of the display on the click of the control.
Me.chkWatchsubDirecties.AutoCheck = False
End Sub
Private Sub errorlogChange(ByVal source As Object, ByVal e As ErrorEventArgs)
Dim sMessages As String
' Show that an error has been detected.
If TypeOf e.GetException Is InternalBufferOverflowException Then
Me.txtFolderActivity.Text &= ( _
"The file system watcher experienced an internal buffer overflow: " _
+ e.GetException.Message)
End If
End Sub
Private Sub logChange(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs)
If e.ChangeType = IO.WatcherChangeTypes.Changed Then
' Specify what is done when a file is changed, created, or deleted.
Me.txtFolderActivity.Text &= "File name is: " + e.FullPath & " has been changed" & _
" @" & TimeString & ControlChars.NewLine
End If
'If e.ChangeType = WatcherChangeTypes.Created Then
' Me.txtFolderActivity.Text &= "File name is: " + e.FullPath & " has been created" & ControlChars.NewLine
'End If
'If e.ChangeType = WatcherChangeTypes.Deleted Then
' Me.txtFolderActivity.Text &= "File name is: " + e.FullPath & " has been deleted" & ControlChars.NewLine
'End If
End Sub
Private Sub logRename(ByVal source As Object, ByVal e As System.IO.RenamedEventArgs)
Me.txtFolderActivity.Text &= ("File: " & e.OldName & " has been renamed to: " & e.Name & " " & ControlChars.NewLine)
End Sub
Dave
|
|
|
|
|
Hi again Dave,
Here's another way to define the .NotifyFilters property that performs well:
wf.NotifyFilter = 0
wf.NotifyFilter = mw.NotifyFilter Or NotifyFilters.FileName
It handles calling the wf.created, wf.deleted, wf.changed, and wf.renamed events in a surprisinly logical way. Here is the action - logic table:
Action: Triggers
drag/drop a file into the watched directory wf.Created
drag/drop a file onto an existing file in the directory wf.Deleted and wf.Created
drag a file out of the watched directory wf.Deleted
stream a file into the watched directory wf.Created
copy and paste a file into the watched directory wf.Created
Right-click and "Delete" a file in the directory wf.Deleted
Your suggestion of just using wf.NotifyFilter= IO.NotifyFilters.LastAccess also gives single event triggers but doesn't trigger for some actions.
Action: Triggers
drag/drop a file into the watched directory wf.Changed
drag/drop a file onto an existing file in the directory wf.Changed
drag a file out of the watched directory <no triggers="">
stream a file into the watched directory wf.Changed
copy and paste a file into the watched directory <no triggers="">
Right-click and "Delete" a file in the directory <no triggers="">
I didn't care much for the combination of IO.NotifyFilters.LastAccess OR IO.NotifyFilters.Filename as the logic table yielded too many "multiple" events:
Action: Triggers
drag/drop a file into the watched directory wf.Created then wf.Changed
drag/drop a file onto an existing file in the directory wf.Deleted then wf.Created then wf.Changed
drag a file out of the watched directory wf.Deleted
stream a file into the watched directory wf.Created
copy and paste a file into the watched directory wf.Created
Right-click and "Delete" a file in the directory wf.Deleted
Well,...at this point,..I'm feeling a little better about how to use this object. Thanks for the exchange of information. It was very useful!
-Dave
|
|
|
|
|
Does anyone have an example on how I can populate a DataGrid using an ADO connection?
Thank you,
Quecumber256
|
|
|
|
|
Hi, i create a menu from a database using datareader
then i 'm adding a handler for click event.
now iwant inside the handler procedure to get the text of the menuitem who called the handler and that's exactly my problem.
this is my code
Public Sub devsubmenu()
Dim cmddev As New OleDbCommand("Select modelname from devicetbl",OleDbConnection1)
OleDbConnection1.Open()
Dim dtread As OleDbDataReader = cmddev.ExecuteReader()
devmnu.MenuItems.Clear()
Do While dtread.Read
Dim ChildMenu As New MenuItem
ChildMenu.Text = dtread.Item("modelname").ToString()
AddHandler ChildMenu.Click, AddressOf model_click
devmnu.MenuItems.Add(ChildMenu)
Loop
OleDbConnection1.Close()
End Sub
End Sub
Private Sub model_click(ByVal sender As System.Object, ByVal e As System.EventArgs)
' HERE I WANT TO TAKE THE MENUITEM (SENDER) TEXT AND PUT IT IN A TEXT BOX
End Sub
any ideas ?
|
|
|
|
|
I've got a very weird problem, when I run the following code the
ComboBox (Me.cmbInputDevice) is always empty. The ComboBox is on a
UserControl in a Class Library. I'm using VS.NET 2003 with SourceSafe
6.0d (the problem occurs whether the code is checked in or out)
If I step through the code, The line
Me.cmbInputDevice.DataSource = dv
Executes fine (ie, doesn't error), but on the next line (after an
F8/F11) Me.cmbInputDevice.DataSource is still equal to Nothing.
dv is definately not Nothing, and is definately not empty (I can view
it's contents in the Command Window)
*if* I delete the combo box from the control, and add a new one, give it
the same name, etc, it works for a while, but then goes back to
not-working after an unknown period. This isn't any kind of practical
solution.
Sql.GetDeviceTable() returns a valid & populated DataTable
[VB.NET] (Native Language)
Dim dt As DataTable = Sql.GetDeviceTable()
Dim dr As DataRow = dt.NewRow()
dr("ID") = DBNull.Value
dr("Description") = "<none>"
dt.Rows.Add(dr)
Dim dv As DataView = dt.DefaultView
dv.Sort = "Description"
dv.ApplyDefaultSort = True
Me.cmbInputDevice.DataSource = dv
Me.cmbInputDevice.DisplayMember = "Description"
Me.cmbInputDevice.ValueMember = "ID"
[C#] (Translation)
DataTable dt = Sql.GetDeviceTable();
DataRow dr = dt.NewRow();
dr("ID") = DBNull.Value;
dr("Description") = "<none>";
dt.Rows.Add(dr);
DataView dv = dt.DefaultView;
dv.Sort = "Description";
dv.ApplyDefaultSort = True;
this.cmbInputDevice.DataSource = dv;
this.cmbInputDevice.DisplayMember = "Description";
this.cmbInputDevice.ValueMember = "ID";
Hiren
-- modified at 14:04 Tuesday 9th May, 2006
|
|
|
|
|
Just make shorting property false.
this.cmbInputDevice.Sorted=False
IT works.....
etettr
|
|
|
|
|
Dear friends,
I have one VB form with two picture boxes on it. I have a picture in of the picture box and the other is empty. How can I cut the part of the picture inside the first picture box and paste that in the the second picture box. How can I pass the dimension from where to where I need to cut the picture. Please help me out in this matter. I really need to cut picture in lots of pieces and put them in seperate picture boxes for some special purpose.
Your quick response will be highly appreciated.
Thanks and Regards
Murtuza Patel
|
|
|
|
|
The easiest way is to not use the picture box control. If you handle your apps 'paint' event and draw the bitmap yourself, you can draw the parts where-ever you like, without having to actually chop up your source bitmap into lots of bitmaps.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi,
I've been banging my head on the keyboard for a few days now searching for a solution to my problem. Iv'e searched Google for a solution but I can't seem to find any.
The node information is stored in a MySQL database using the nodes.fullpath command or like this:
lvl1\lvl2\lvl3
Now, I've seen and tried to use the treeview.nodes.add(1).nodes.add(2).nodes.add(3) with a split command but because I don't know how many levels there are before hand this makes a giant select case that makes me cry each time I see it.
I want the routine to check if the level exists then add it if it doesn't and/or move to the next level. (Geez it sounds so simple writen like that...)
Here is the routine I'm using
Dim SQL As String = "Select * from troubleshooting order by node_path asc"<br />
Dim StrNodePath As String<br />
Dim nNode As TreeNode<br />
Dim BolNew As Boolean = True<br />
Dim X As Integer<br />
Dim StrNode As String<br />
<br />
<br />
RSProbleme = ReturnForm.StrConn.Execute(SQL)<br />
<br />
Do Until RSProbleme.EOF = True<br />
<br />
StrNodePath = RSProbleme("node_path").Value<br />
aNodePath = Split(StrNodePath, "\")<br />
<br />
For X = 0 To UBound(aNodePath)<br />
BolNew = True<br />
For Each nNode In TrVProbleme.Nodes<br />
<br />
If nNode.Text = aNodePath(X) Then<br />
BolNew = False<br />
End If<br />
<br />
Next<br />
If BolNew = True Then<br />
nNode.Nodes.Add(aNodePath(X)) <-- This is the line that gives me trouble<br />
End If<br />
Next<br />
<br />
RSProbleme.MoveNext()<br />
Loop
When adding it gives me the error, "Object reference not set to an instance of an object." and using the variable watch in VS it says that nNode = Nothing.
Any help will be greatly appreciated. (My head hurts from all that banging...)
Thanks
For every action there is an equal and opposite malfunction
|
|
|
|
|
I am guessing that you created a treeview called TrVProbleme in your application. If you have not added any nodes to the treeview - then nNode will be nothing. You might want to try changeing the statement nNode.Nodes.Add(aNodePath(X)) to TrVProbleme.Nodes.Add(aNodePath(X))
Hope this helps
Digicd1
|
|
|
|
|
Indeed you are correct; while I did not change the line as you suggested I've added a If... End If checking if this was a root node or not then added your line.
(Can't believe it was so simple grr...)
Thanks a bunch!
Raist
For every action there is an equal and opposite malfunction
-- modified at 12:12 Wednesday 10th May, 2006
|
|
|
|
|
hi!
have u finish adding nodes to a treeview control?
can u help me!
can u give me ur code and the code in SQL!
i need it badly!
i hope u can help me!
thanks a lot!
coder
|
|
|
|
|
What kind of code are you interested in and what is the purpose?(what is it supposed to do?)
Raist
For every action there is an equal and opposite malfunction
|
|
|
|
|
good morning! a code that will retrieve the data from database or using query!
i will use the treeview for making a organizational chart!
one main ParentNode(Division),childnode(Department) and subchildnode(Section)
Thanks for ur kindheart!
"Giving something does not reduce what you have but gain more!"
coder
|
|
|
|
|
Good morning!The code that i will use is all that name in the node that wiil display is came from the database,
or using query!
i will use it in making organizational chart!
the content is i have a parentnode(Division), Chilnode(Department) and SubChildnode(Section).
thanks!
" Giving something to anyone is not reducing what u have instead you gain more!"
coder
|
|
|
|
|
Hi!
The following code selects a row from a table. If the row exists then it is updated otherwise a new row is added to the table.
How can I write this code using ADO.NET 2.0?
Dim rsRequest As New ADODB.Recordset<br />
rsRequest.Open "Select Form_No, User_ID, Status, Request_Date from tbl_ReExport_Info Where Form_No = '" & txtFormNo.Text & "' And User_ID = '" & txtUserID.Text & "'", cnnADO, adOpenDynamic, adLockOptimistic<br />
With rsRequest<br />
If .EOF = True Then .AddNew<br />
!Form_No = txtFormNo.Text<br />
!User_ID = txtUserID.Text<br />
!Status = 0<br />
!Request_Date = Now<br />
.Update<br />
End With<br />
Thank You
Gulfraz Khan
|
|
|
|
|
Can anyone tell me a way, or give me a class, that will allow me to handle Complex numbers, i.e. square roots of negative numbers. If it's important, I am using the Visual Basic 2005 Express Edition. Also, if relevant, I am trying to program the general solution to a cubic polynomial. I only started learning VB four days ago and have, as such, limited experience, so any help is hugely appreciated.
|
|
|
|
|
Hopefully this article here can give you a head start (It is in C# though)
http://msdn2.microsoft.com/en-us/library/6fbs5e2h.aspx
|
|
|
|
|
Thanks for the link, really appreciate the help. Only problem is that, as I started programming last Saturday, I don't really have the know how to translate what's there to VB. If anyone has any VB links, particularly ones that are designed to explain how to program a class or function in the first place, I would be eternally grateful.
|
|
|
|
|
I run my vb.net windows application that has crystal report in a pc it runs perfectly well and i am able to see the reports , but when i take setup of the application and run in same pc i get error "load report failed".
I have added the following to setup project
atl.msm
Crystal_Database_Access2003.msm
Crystal_Database_Access2003_enu.msm
Crystal_Managed2003.msm
Crystal_regwiz2003.msm
CrystalReports10_NET_EmbeddedReporting.msm
VC_User_ATL71_RTL_X86_---.msm
VC_User_CRT71_RTL_X86_---.msm
VC_User_STL71_RTL_X86_---.msm
apphelp.dll
msado25.tlb
I have added the following references
CrystalDecisions.CrystalReports.Engine
CrystalDecisions.ReportAppServer.ClientDoc
CrystalDecisions.ReportSource
CrystalDecisions.Shared
i am also adding
the reports ,
source files from "Project Name" and
primary output from "Project Name"
I don't understand what could be the problem as i am using the same pc.
If any of you know the solution do tell me.
Thanks in advance,
sarah
-- modified at 11:06 Tuesday 9th May, 2006
|
|
|
|
|
Don't really know that much about Crystal, but I've seen this problem a lot. Usually affects older operating systems (Win 98/ME/NT) in my experience, and is down to a missing DBGHELP.DLL file.
Visit:
http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=CD1FC4B2-0885-47F4-AF45-7FD5E14DB6C0
to see if this helps.
|
|
|
|
|
hi,
can anybody help me how to export crystal report from vb in pdf format.
plz help me.
|
|
|
|
|
are you using WindowsApp or WebApp??
|
|
|
|
|
i am using windowsapp
means their are 3-4 formats in which i am able to send the report but in pdf it's not.
|
|
|
|