Hello!
I have the following code under my button:
It is supposed to open "Database.bin", search the file for whatever the user types into SearchBox (a text box), and add to DisplayBox (a list box) every line of that file that contains the string the user searched. However, it always returns this exception:Code:Private Sub SearchButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchButton.Click
MsgBox(SearchBox.Text())
If (File.Exists("Database.bin")) And (SearchBox.Text() <> Nothing) Then
Dim ioFile As New StreamReader("Database.bin")
Dim ioLine As String ' Holds 1 Line at a Time
Dim ioLines As String ' Holds Whole File
ioLines = ""
Do
ioLine = ioFile.ReadLine()
If (ioLine.IndexOf(SearchBox.Text()) <> -1) Then
If (ioLine <> Nothing) Then
DisplayBox.Items.Add(ioLine)
End If
End If
ioLines = ioLines & vbCrLf & ioLine
Loop Until ioLine Is Nothing
'MsgBox(ioLines)
Else
MsgBox("Database.bin is missing! Please re-download the program.")
End If
End Sub
Could someone please inform me of what is wrong and help me correct it?Code:System.NullReferenceException was unhandled
Message=Object reference not set to an instance of an object.
Source=Universal Handbook
StackTrace:
at Universal_Handbook.MainWindow.SearchButton_Click(Object sender, EventArgs e) in C:\Users\Cecil\documents\visual studio 2010\Projects\Universal Handbook\Universal Handbook\Form1.vb:line 21
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at Universal_Handbook.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
Here is Database.bin:
Help is greatly appreciated! :)Code:1010000 Long Brown Beard
1010001 Goatee
1010002 Ninja Mask for Men
1010003 5 O'Clock Shadow
1010004 General's Mustache (1)
1010005 General's Mustache (2)
1010006 Yakuza Scar
1011000 Ninja Mask for Women
1011001 SF Ninja Mask
1011002 Heart
1011003 Freckles
1012000 Battle Scar
1012001 Bindi
1012002 Leather Mask
1012003 Blush
1012004 Disguise
1012005 Bruise
1012006 Rose
1012007 Santa Beard
1012008 Censor
1012009 Kiss Mark
1012010 Hinomaru

