Results 1 to 7 of 7

Thread: running forms in class library

  1. #1
    New Member
    Join Date
    May 12
    Posts
    4

    running forms in class library

    hi this is vinod kumar

    i have a query iam able to add items in listbox from form 2 to form1 from windows application in vb.net
    but iam unable to add items in listbox from form 2 to form1 why can any one tell please its urgent

  2. #2
    Loquacious User Shaggy Hiker's Avatar
    Join Date
    Aug 02
    Location
    Idaho
    Posts
    20,410

    Re: running forms in class library

    We'd have to see the code to be certain. The basic task should be entirely possible as long as you have valid instances of the two forms. Are you getting error messages? If so, what are they?
    My usual boring signature: Nothing

  3. #3
    New Member
    Join Date
    May 12
    Posts
    4

    Re: running forms in class library

    iam getting an error message as object refernce not set to instance of an object
    Last edited by vinodyadav21; Jun 21st, 2012 at 06:24 AM.

  4. #4
    New Member
    Join Date
    May 12
    Posts
    4

    Re: running forms in class library

    if we run from class library we will specify
    in form2 when icall from1
    iam writing

    form1 i have one listbox(already i have some items)
    and form 2 i have another listbox

    from this listbox iam adding some more items in form1 listbox

    dim form1 as new form1
    form1=new form1

    form1.listbox1.items.add(listbox1.selecteditem)

    iam unable to add the items in the listbox of form1

    when iam debugging iam getting the items in listbox of form1 is 0 please can any one help

  5. #5
    Loquacious User Shaggy Hiker's Avatar
    Join Date
    Aug 02
    Location
    Idaho
    Posts
    20,410

    Re: running forms in class library

    Whenever you get that particular error, examine the line that throws the error. One of the objects is Nothing, and that's the problem. However, there is a chance that in this case you might not know which line actually threw the exception.

    I'm not sure whether the code you just posted is related to the earlier issue, or not, but it has a few problems. The first thing is that you did this:

    Dim form1 as New Form1

    That will work, but it's a bad idea. If you have a form type called Form1, then there is already a default instance of that form that is also called form1. So, you are now creating an instance of Form1 called Form1 though there could also be a default instance called Form1. That's just asking for trouble. Give the variable a name that is different from the type, otherwise you are hoping that the compiler will correctly understand you. It might, but why guess?

    Next, you are creating the New Form, but in the next line you are creating ANOTHER new form and assigning it to the variable. This isn't technically wrong, it is just wasteful. That creates one form, then immediately throws it out (though it doesn't dispose of it), and creates a different form. Twice the memory for no added benefit.

    Third, you then add something to the form1.Listbox. That's where the default instance could really cause you trouble, because the comiler may very well be showing the wrong form. Changing the name of the form so that it is not the same as the class type (not Form1), may make the problem go away. If not, then show us what you have changed it to.

    Also, you mentioned a form2, but didn't show anything like that. That makes me think that the default instance is the problem.
    My usual boring signature: Nothing

  6. #6
    New Member
    Join Date
    May 12
    Posts
    4

    Re: running forms in class library

    then how would i get the values of form1 in form 2 and how can i add i add values in form1 from form2 if idint decalare form1 when running in class library, can u provide nay sample program for calling form 1 in form 2
    thanks

    regards vinod kumar

  7. #7
    Loquacious User Shaggy Hiker's Avatar
    Join Date
    Aug 02
    Location
    Idaho
    Posts
    20,410

    Re: running forms in class library

    Are both form1 and form 2 found in the dll?

    Aside from that, I'm not quite sure what you are asking for, but I suspect that the misconception might be due to a reliance on default instances of forms. Therefore, I think I ought to ask whether you know what a default instance is, and whether you know that you are NOT using them (they are do nothing but cause confusion, so it is best never to use them)?
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •