By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,222 Members | 1,728 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,222 IT Pros & Developers. It's quick & easy.

filewatch and notifyicon = trubble ?

P: n/a
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
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.