Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Problem with my application after changing some project settings

Posted on 2005-05-12
21
Medium Priority
?
234 Views
Last Modified: 2012-05-05
I stupidly changed the properties in one of my programs now it seems i have really messed things up.

What i did was right click on the on the directory under Solution in the solution explorer panel.
Then i changed both the assembly name and the root namespace.

I then realized this messed things up and i first went through the code changing the project name in lines like
    Friend WithEvents Loc1DS1 As WindowsApplication4.loc1DS
    Friend WithEvents Loc2DS1 As WindowsApplication4.loc2DS
    Friend WithEvents Loc3DS1 As WindowsApplication4.loc3DS

When this did not make the code work i went back and changed everything back to it's original settings including everything i changed in the code and the assembly name and root namespace. What the heck did i do, i can't figure it out.

now i keep getting this error

An unhandled exception of type 'System.NullReferenceException' occurred in WindowsApplication4.exe

Additional information: Object reference not set to an instance of an object.
0
Comment
Question by:ethnarch
  • 14
  • 7
21 Comments
 
LVL 2

Author Comment

by:ethnarch
ID: 13990288
oh i get the error when i debug it by hitting f5
0
 
LVL 8

Expert Comment

by:doobdave
ID: 13994238
Hi ethnarch,
I will try to assist you if you could clarify a couple of points for me:

Where in your code does this exception occur (what line)?

How many projects in your solution?
Are they all in the same namespace?

Regards,
David
0
 
LVL 2

Author Comment

by:ethnarch
ID: 13994414
it doesn't occur on a line it occurs the second that i hit f5
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 2

Author Comment

by:ethnarch
ID: 13994419
i had left everything in it's default up until i did the above I was just trying to change it, not knowing it would be my undoing i only changed the project properties, and there is only one project in the solution
0
 
LVL 2

Author Comment

by:ethnarch
ID: 13994424
to add one more thing it is a single form application, it's a very simple program that just looks up barcodes numbers in a database and shows it to the user.
0
 
LVL 8

Expert Comment

by:doobdave
ID: 13994582
Hi again ethnarch,

So, you hit F5, and you get an exception message box straight away?

Do you have a Sub Main() in this project?
In your project properties, what is the Stratup object set to?

Does the exception message indicate a line where the exception is occurring?

Aer you running it in Debug or Release mode?

David
0
 
LVL 2

Author Comment

by:ethnarch
ID: 13997529
---I hit f5 and maybe about a few nano seconds go by, hehe or about a second so it runs some code i am assuming

---there is no sub main in my project

---the startup object is set to form 1

---no it does not indicate a line

---I was running it in release mode so then i tried changing it back to debug and It gave me different error message

An unhandled exception of type 'System.NullReferenceException' occurred in WindowsApplication4.exe
Additional information: Object reference not set to an instance of an object.

, where it pointed out this line of code
DataSet11.Clear()

---Which happens to be inside this Function
 Sub setData(ByVal OkToFilter As Boolean)
        DataSet11.Clear()
        DataAdapColl(locNo).Fill(DataSet11)
        Dim dv1 = New DataView(DataSet11.Tables("MenuItem"))
        DataGrid1.DataSource = dv1

        If OkToFilter = True Then
            dv1.Rowfilter = ComboBox2.Text & " LIKE '%" & TextBox1.Text & "%'"
        End If

    End Sub

---So i tried to fix that error by changing it to this

    Sub setData(ByVal OkToFilter As Boolean)
        DataSet11 = New DataSet1() '<-----------------My attempt at fixing the problem
        DataSet11.Clear()
        DataAdapColl(locNo).Fill(DataSet11)
        Dim dv1 = New DataView(DataSet11.Tables("MenuItem"))
        DataGrid1.DataSource = dv1

        If OkToFilter = True Then
            dv1.Rowfilter = ComboBox2.Text & " LIKE '%" & TextBox1.Text & "%'"
        End If

    End Sub

---Then it gave me this error
An unhandled exception of type 'System.IndexOutOfRangeException' occurred in microsoft.visualbasic.dll
Additional information: Collection index must be in the range 1 to the size of the collection.

--on this line of code

DataAdapColl(locNo).Fill(DataSet11)

---which is in the function listed above and here is where the DataAdapColl and locNo originates and is setup

Public Class Form1
    Inherits System.Windows.Forms.Form

    Dim srchColName As String
    Dim locNo As Integer = 2
    Dim DataAdapColl As New Collection()
    Dim dv1 As New DataView()

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ComboBox1.Items.Add("Warehouse")
        ComboBox1.Items.Add("Gotham 1 (loc 1)")
        ComboBox1.Items.Add("Gotham 2 (loc 2)")
        ComboBox1.Text = "Gotham 1 (loc 1)"

        ComboBox2.Items.Add("PLU")
        ComboBox2.Items.Add("Description")
        DataAdapColl.Add(SqlDataAdapter2)
        DataAdapColl.Add(SqlDataAdapter3)
        DataAdapColl.Add(SqlDataAdapter4)
        setData(False)

---so now you should have all the code up until the setdata function i first mentioned above is called
0
 
LVL 8

Expert Comment

by:doobdave
ID: 14010289
Hi again ethnarch,

now we are getting somewhere.
The fact that you had your project set to Release mode meant that you weren't able to see the exact exception, and is also the reason why it didn't give a line where the error occurred.

I agree with the step you took to correct the initial exception (the dataset was = Nothing).

Now it seems that the variable "locNo" has a value outside the range of the DataAdaptColl collection.
The value must be anywhere from 1 to the number of items in the collection (collections are 1-based, unlike arrays).

Can you set a breaKpoint on the line where the exception is occurring, and when te debugger stops there, hover over the variable (locNo) to see its value.
Is it greater than 0 (zero)?
Is it less than DataAdaptColl.Count?

Regards,
David
0
 
LVL 2

Author Comment

by:ethnarch
ID: 14012522
---locNo is set to 2, i have that set as the default in the beginning of the Form Class before any code is run like this

Public Class Form1
    Inherits System.Windows.Forms.Form

    Dim srchColName As String
    Dim locNo As Integer = 2
    Dim DataAdapColl As New Collection()
    Dim dv1 As New DataView()

--- It's strange that it's out of range unless this code is incorrect
        DataAdapColl.Add(SqlDataAdapter2)
        DataAdapColl.Add(SqlDataAdapter3)
        DataAdapColl.Add(SqlDataAdapter4)

--- there should be a total of 3 items in the collection i tried changing the value of LocNo to 1 but i still get the same error.
0
 
LVL 2

Author Comment

by:ethnarch
ID: 14012572
Ok so i put a msg box with DataAdapColl.Count in it and it reads 0.  Somehow my add commands are not working on form load.

0
 
LVL 2

Author Comment

by:ethnarch
ID: 14013595
and just to add one more point, even when i put the msg box right after DataAdapColl.Add() it still reads 0
0
 
LVL 8

Expert Comment

by:doobdave
ID: 14016771
Ok,
Are the objects "SqlDataAdapter1", "SqlDataAdapter2", "SqlDataAdapter3" all set to instances of objets before you add them to the collection? ie. They are NOT NOTHING?
0
 
LVL 2

Author Comment

by:ethnarch
ID: 14017532
This code is in the windows form generated code section i think this is what you mean
        Me.SqlDataAdapter2 = New System.Data.SqlClient.SqlDataAdapter()
        Me.SqlDataAdapter3 = New System.Data.SqlClient.SqlDataAdapter()
        Me.SqlDataAdapter4 = New System.Data.SqlClient.SqlDataAdapter()

The form load function exists after the windows form generated code. I don't know if this even matters since it's not called till the form loads but i just figured i would let you know anyway.
0
 
LVL 2

Author Comment

by:ethnarch
ID: 14022726
Some more information that might be useful.

I tried putting a breakpoint on every line of my form code to see what would happen and it's almost as if it skips over lines of code. The last time it stops is on this line of code --ComboBox1.Text = "Gotham 1 (loc 1)"

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ComboBox1.Items.Add("Warehouse")
        ComboBox1.Items.Add("loc 1")
        ComboBox1.Items.Add("loc 2")
        ComboBox1.Text = "loc 1" '<-----------From this point on it skips and doesn't stop at the breakpoints

        ComboBox2.Items.Add("PLU")
        ComboBox2.Items.Add("Description")
        DataAdapColl.Add(SqlDataAdapter2)
        DataAdapColl.Add(SqlDataAdapter3)
        DataAdapColl.Add(SqlDataAdapter4)
        MsgBox(DataAdapColl.Count)
        'ComboBox2.Items.Add("Description")
        srchColName = "PLU"
        setData(False)
        'ComboBox2.Items.Add("693 8th Avenue")
    End Sub
0
 
LVL 8

Accepted Solution

by:
doobdave earned 1000 total points
ID: 14025230
Hi again ethnarch,

I suggest you wrap the above code inside of a Try...Catch block as follows:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  Try
        ComboBox1.Items.Add("Warehouse")
        ComboBox1.Items.Add("loc 1")
        ComboBox1.Items.Add("loc 2")
        ComboBox1.Text = "loc 1" '<-----------From this point on it skips and doesn't stop at the breakpoints

        ComboBox2.Items.Add("PLU")
        ComboBox2.Items.Add("Description")
        DataAdapColl.Add(SqlDataAdapter2)
        DataAdapColl.Add(SqlDataAdapter3)
        DataAdapColl.Add(SqlDataAdapter4)
        MsgBox(DataAdapColl.Count)
        'ComboBox2.Items.Add("Description")
        srchColName = "PLU"
        setData(False)
        'ComboBox2.Items.Add("693 8th Avenue")
  Catch Ex as Exception
    Messagebox.Show(Ex.ToString)  
  End Try
End Sub

This will let us know when and what exception occurs.

Also, have you tried stepping through the code line by line? ie. Set a breakpoint on the first line, and then press F8 or F11 to go through each line of code. You can then hover over variables with the mouse pointer to see their values and if they are what you expect them to be.

Regards,
David
0
 
LVL 2

Author Comment

by:ethnarch
ID: 14025424
I did go through it line by line hence the previous statement
                         Qoute "I tried putting a breakpoint on every line of my form code to see what would happen and
                                   it's almost as if it skips over lines of code. The last time it stops is on this line of code --
                                   ComboBox1.Text = "Gotham 1 (loc 1)"

Maybe i am misunderstanding you?
0
 
LVL 8

Expert Comment

by:doobdave
ID: 14025644
Yep, the method I suggested is different from putting a breakpoint on every line.
Using your method, if an exception occurs, any breakpoints after that will not be hit (as I suspect is happening).
Are you pressing the 'Play' button or hitting F5? They both continue execution until the next breakpoint, except ni the circumstance I just mentioned.

If you keep pressing F8 or F11, it will 'step-thruogh' the code liine by line, so you will see exactly which line is causing problems.

Did you implement the Try..Catch?
0
 
LVL 2

Author Comment

by:ethnarch
ID: 14026793
i just tried the catch, it only gives me the error on the collection being out of range so i am taking a guess it has to do with the sqlAdapters i am going to try remaking them when i get time and start from scratch maybe some settings i can't see got changed when i changed the properties of my project.
0
 
LVL 2

Author Comment

by:ethnarch
ID: 14038602
Ok i solved it by just recoding that part of my project. I got rid of the collection and instead had the DataAdapter refill the Dataset everytime just changing the SQL Query instead of having different DataAdapters for each set of data, which is the right way to do it anyway.

Thankyou for the help though i'll give you the points for the effort.
0
 
LVL 2

Author Comment

by:ethnarch
ID: 14038612
i do have another question however though, do you know a source online or any books that explain Try catch statements they are really useful and i really don't know much about them.
0
 
LVL 8

Expert Comment

by:doobdave
ID: 14043741
Hi again,
yep, I think it's really important to understand Try..Catch blocks.

It is formally known as "Structured Exception Handling", as opposed to the old VB6 unstructured (On Error...).

I normally have one in every sub and function.

Here's some links to get you started:

http://www.c-sharpcorner.com/vbnet/vbarticles/VBASPExHSSK.asp

http://www.vbdotnetheaven.com/Code/Jun2003/2009.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcn7/html/vaconintrotoexceptionhandling.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcn7/html/vaconerrorhandlingusingtrycatchfinally.asp

Definition:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vastmTryCatchFinally.asp

HTH

David
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Integration Management Part 2
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month15 days, 4 hours left to enroll

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question