473,394 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

filewatch and notifyicon = trubble ?

I have tried to find the error in the code below but I always get "

An unhandled exception of type 'System.NullReferenceException' occurred in
Unknown Module.

Additional information: Object reference not set to an instance of an
object." and then

"There is no source code avaliable for the current location."
I know what it means but i have commented out more or less every line and
still got the message. I suspext the notifyicon part. I also have a module
that contains

"

Public LookPath, ToPath As String

Public AllDirs As Boolean

Public Sub readReg()

Dim rk As RegistryKey

Dim config As New frmConfig

rk = Registry.LocalMachine.OpenSubKey("SOFTWARE\Watcher ", True)

LookPath = rk.GetValue("Lookpath") ', TextBox1.Text)

If Not LookPath = "" Then

LookPath = rk.GetValue("Lookpath")

ToPath = rk.GetValue("ToPath")

AllDirs = rk.GetValue("AllDirs")

rk.Close()

Else

config.Show()

End If

End Sub

"

This is the main program

Imports System.IO

Imports System.ComponentModel

Imports System.Drawing

Imports System.Windows.Forms

Imports System.Resources

Public Class frmEzView

Inherits System.Windows.Forms.Form

Const CSTRFILELOC As String = "Make sure cascade.js, ezcascade.bat,
tilehorz.js" & ControlChars.NewLine & _

"eztilehorz.bat, tilevert.js and
eztilevert.bat" & ControlChars.NewLine & _

"are in the same directory as the .EXE
file."

Private mEzIcon As New
Icon(GetType(frmEzView).Assembly.GetManifestResour ceStream("EzView.customwiz.ico"))

Private m_WatchDirectory As String

Private WithEvents m_FileSystemWatcher As FileSystemWatcher

Dim fslog As New log

Private Sub Initializenotifyicon()

notifyicon = New System.Windows.Forms.NotifyIcon

notifyicon.Icon = mEzIcon

notifyicon.Text = "Right Click for the menu"

notifyicon.Visible = True

Dim mnuItms(5) As MenuItem

mnuItms(0) = New MenuItem("About Watcher", New
EventHandler(AddressOf Me.AboutSelect))

mnuItms(0).DefaultItem = True

mnuItms(1) = New MenuItem("Cascade Windows", New
EventHandler(AddressOf Me.CascadeSelect))

mnuItms(2) = New MenuItem("Setting", New EventHandler(AddressOf
Me.Setting))

mnuItms(3) = New MenuItem("View Log", New EventHandler(AddressOf
Me.fLog))

mnuItms(4) = New MenuItem("-")

mnuItms(5) = New MenuItem("Exit", New EventHandler(AddressOf
Me.ExitSelect))

Dim notifyiconMnu As ContextMenu = New ContextMenu(mnuItms)

notifyicon.ContextMenu = notifyiconMnu

End Sub

Public Sub AboutSelect(ByVal sender As Object, ByVal e As
System.EventArgs)

Dim frmAboutEzView As New frmAboutEzView()

frmAboutEzView.ShowDialog()

End Sub

Public Sub CascadeSelect(ByVal sender As Object, ByVal e As
System.EventArgs)

Try

Shell("ezcascade.bat")

Catch err As Exception

MessageBox.Show("Error: " & err.Message & ControlChars.NewLine &
_

"Source: " & err.Source & ControlChars.NewLine &
ControlChars.NewLine & _

CSTRFILELOC, "ERROR", MessageBoxButtons.OK,
MessageBoxIcon.Error)

End Try

End Sub

Public Sub TileHorzSelect(ByVal sender As Object, ByVal e As
System.EventArgs)

Try

Shell("eztilehorz.bat")

Catch err As Exception

MessageBox.Show("Error: " & err.Message & ControlChars.NewLine &
_

"Source: " & err.Source & ControlChars.NewLine &
ControlChars.NewLine & _

CSTRFILELOC, "ERROR", MessageBoxButtons.OK,
MessageBoxIcon.Error)

End Try

End Sub

Public Sub Setting(ByVal sender As Object, ByVal e As System.EventArgs)

Dim appSett As New frmConfig

appSett.Show()

End Sub

Public Sub fLog(ByVal sender As Object, ByVal e As System.EventArgs)

fslog.Show()

End Sub

Public Sub ExitSelect(ByVal sender As Object, ByVal e As
System.EventArgs)

notifyicon.Visible = False

Me.Close()

End Sub

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

Me.Hide()

Initializenotifyicon()

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer

Friend WithEvents notifyicon As System.Windows.Forms.NotifyIcon

Friend WithEvents lstFile As System.Windows.Forms.ListBox

<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

Me.components = New System.ComponentModel.Container

Me.notifyicon = New System.Windows.Forms.NotifyIcon(Me.components)

Me.lstFile = New System.Windows.Forms.ListBox

Me.SuspendLayout()

'

'notifyicon

'

Me.notifyicon.Text = ""

Me.notifyicon.Visible = True

'

'lstFile

'

Me.lstFile.Dock = System.Windows.Forms.DockStyle.Fill

Me.lstFile.Location = New System.Drawing.Point(0, 0)

Me.lstFile.Name = "lstFile"

Me.lstFile.Size = New System.Drawing.Size(336, 160)

Me.lstFile.TabIndex = 1

'

'frmEzView

'

Me.AccessibleRole = System.Windows.Forms.AccessibleRole.None

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.ClientSize = New System.Drawing.Size(336, 160)

Me.ControlBox = False

Me.Controls.Add(Me.lstFile)

Me.Enabled = False

Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None

Me.MaximizeBox = False

Me.MinimizeBox = False

Me.Name = "frmEzView"

Me.Opacity = 0

Me.ShowInTaskbar = False

Me.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide

Me.StartPosition = System.Windows.Forms.FormStartPosition.Manual

Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

fslog.lstFiles.Items.Add(Now.ToString() & " Starting")

readReg()

fslog.lstFiles.Items.Add(Now.ToString() & " Init " & LookPath)

fslog.lstFiles.Items.Add(Now.ToString() & " Init " & ToPath)

fslog.lstFiles.Items.Add(Now.ToString() & " Starting")

readReg()

fslog.lstFiles.Items.Add(Now.ToString() & " Init " & LookPath)

fslog.lstFiles.Items.Add(Now.ToString() & " Init " & ToPath)

m_WatchDirectory = LookPath

m_FileSystemWatcher = New FileSystemWatcher(m_WatchDirectory,"*.*")
m_FileSystemWatcher.NotifyFilter = 0

m_FileSystemWatcher.NotifyFilter = m_FileSystemWatcher.NotifyFilter
Or NotifyFilters.FileName

m_FileSystemWatcher.EnableRaisingEvents = True

m_FileSystemWatcher.IncludeSubdirectories = AllDirs

MsgBox(m_WatchDirectory)

ProcessExistingFiles(m_WatchDirectory)

End Sub

Private Sub m_FileSystemWatcher_Created(ByVal sender As Object, ByVal e As
System.IO.FileSystemEventArgs) Handles m_FileSystemWatcher.Created

ProcessFile(e.FullPath, e.Name)

End Sub

Private Sub ProcessExistingFiles(ByVal directory_name As String)

Dim dir_info As New DirectoryInfo(directory_name)

dim file_infos As FileInfo() = dir_info.GetFiles()

For Each fi As FileInfo In file_infos

ProcessFile(fi.FullName, fi.Name)

Next fi

End Sub

' Process a file.

Private Sub ProcessFile(ByVal file_name As String, ByVal shName As
String)

Dim wfile As File

fslog.lstFiles.Items.Add(Now.ToString() & " Processed " & file_name)

If shName = "Thumbs.db" Then ' = LCase(file_name) Then

Exit Sub

End If

MsgBox(file_name & " " & ToPath & "\" & shName)

Try

wfile.Delete(ToPath & "\" & shName)

wfile.Copy(file_name, ToPath & "\" & shName)

wfile.Delete(file_name)

Catch e As Exception

Console.WriteLine("The process failed: {0}", e.ToString())

End Try

End Sub

Private Sub lstFiles_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles lstFile.SelectedIndexChanged

End Sub

End Class
Jul 21 '05 #1
0 1569

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Phil Galey | last post by:
VB.NET 2002 on Windows 2000 SP 3 When I start my program, the NotifyIcon appears in the tray, as it should. However, when I close the program, the NotifyIcon remains until I hover over it with...
2
by: Rob Mayo | last post by:
OK, maybe this is my opinion, maybe these are bugs. Given the folowing: I have a NotifyIcon on my Form, a Context menu associated with the NotifyIcon, and a MenuItem on the ContextMenu set as...
3
by: Glen | last post by:
Can anyone tell me if there is a workable method to get the mouse cursor position on the screen or the NotifyIcon position? I need to display a context menu for the NotifyIcon when clicked and I'd...
2
by: Derrick | last post by:
I've been working on an application which has a NotifyIcon (system tray icon), and a corresponding ContextMenu. I want to be able to update this menu dynamically. However, when I make changes to...
0
by: petterl | last post by:
I have tried to find the error in the code below but I always get " An unhandled exception of type 'System.NullReferenceException' occurred in Unknown Module. Additional information: Object...
3
by: Rudy | last post by:
Hello all! This is what I want to do, looking the for the best way to do this. I have a text file that gets created and placed in a folder. I would like to have a watch for that file when it pops...
0
by: Rudy | last post by:
Hello all! I am having problem wih filewatch, I think. Basicly I have a trigger that creates a file. Filewatch looks for a modified date on the file, than when it see's it, it should pop up a...
3
by: =?Utf-8?B?UnVkeQ==?= | last post by:
Hello All! I may have posted this problem before, but it was awhile ago. I'm working in VS 2003. I have 10 file watch process going. It seems that I can only about 6or 7 to run at the same...
1
by: \Ji Zhou [MSFT]\ | last post by:
Hello Jason, Thanks for using Microsoft Newsgroup Support Service, my name is Ji Zhou and I will be working on this issue with you. I have tried to but cannot reproduce your issue on my side....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.