dcsimg
Results 1 to 23 of 23

Thread: (VB 2005) Form Immobiliser

  1. #1

    Thread Starter
    Hyperactive Member Tarablue's Avatar
    Join Date
    Feb 2007
    Location
    Somewhere West of GMT
    Posts
    398

    (VB 2005) Form Immobiliser

    Hi All,

    In my Project Solution I have several smaller projects, one of which is called Start Up. In this area I have a Class Module that holds my Form Immobiliser coding. This all works just fine IF I keep all my other forms in the Start Up area where the Form Immobiliser resides.

    If I place a form in another project area and try to access the Form Immobiliser using the following coding:-

    Code:
    Private immobiliser As New FormImmobiliser(Me)
    I get the error that FormImmobiliser is is not defined.

    Can anyone assist in showing me how to overcome this problem.

    Best Rgds,
    Tarablue

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: (VB 2005) Form Immobiliser

    Have you set a reference to your Form Immobiliser project in your other project?

  3. #3

    Thread Starter
    Hyperactive Member Tarablue's Avatar
    Join Date
    Feb 2007
    Location
    Somewhere West of GMT
    Posts
    398

    Re: (VB 2005) Form Immobiliser

    Hi Joacim Andersson,

    Yes, my SAF Project, where the form I want to freeze is located, is referenced back to the StartUp project, where the FormImmobiliser coding is located.

    I should have mentioned, in passing, that I have not hit my keyboard to work on my program for just under a year and I'm very, very rusty, so please be kind and understanding of me.

    Best Rgds,
    Tarablue

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: (VB 2005) Form Immobiliser

    I still not sure that I understand you correctly. To be able to use a class from another project you must compile that class as a Class Library and not as a regular EXE file because classes in an EXE are private to that project. The SAF Project need to have a reference to the StartUp project and not the other way around.

  5. #5
    Hyperactive Member BadgerBadger's Avatar
    Join Date
    Aug 2009
    Location
    Wales
    Posts
    382

    Re: (VB 2005) Form Immobiliser

    If it is just a class then you can add that class to your other project without compiling it to a library.

    Right click on solution explorer, add, existing item (select your FormImmobiliser class).
    "The only thing that interferes with my learning is my education."

  6. #6
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,705

    Re: (VB 2005) Form Immobiliser

    First up, there's not really such thing as a "class module". Classes and modules are two different things so it must be one or the other. Saying "class module" is like saying "structure class".

    As for the issue, if the error says that FormImmobiliser is not defined then either you haven't referenced the library it's defined in or else you haven't imported the namespace it's a member of. As JA says, to use separate projects you would have to have one project that compiled to a DLL and the other compile to an EXE. The EXE project would first have to reference the DLL project so that it knew the FormImmobiliser class existed. If you then wanted to refer to the FormImmobiliser class unqualified, you'd have to import the namespace that it's a member of. The namespace would, by default, match the name of the project.

  7. #7
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: (VB 2005) Form Immobiliser

    Quote Originally Posted by jmcilhinney View Post
    First up, there's not really such thing as a "class module". Classes and modules are two different things so it must be one or the other. Saying "class module" is like saying "structure class".
    Well, that's not really correct. I don't really want to start a semantic discussion here but class modules are actually a correct term. The "pure" code modules that you also can use in VB are actually being compiled as a static class behind the scenes (together with a global imports statement).

  8. #8

    Thread Starter
    Hyperactive Member Tarablue's Avatar
    Join Date
    Feb 2007
    Location
    Somewhere West of GMT
    Posts
    398

    Re: (VB 2005) Form Immobiliser

    Hi All,

    I'll get back to you, I need to go back and think about;

    1/ What I'm trying to acheive

    2/ How best to describe it so as not to confuse everyone.

    Thanks for your time - back soon, I hope

    Best Rgds,
    Tarablue

  9. #9
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,795

    Re: (VB 2005) Form Immobiliser

    if the FormImmobiliser is in a different project from where you are trying to use it... then after referencing it, you need to do one of two things.... either fully qualify the class with the project name (Startup.FormImmobiliser) ... OR import your Startup at the top of your class. The reason it is still "not defined" is because it isn't within the current scoping.

    If you type
    Private immobiliser As New Startup.FormImmobiliser(Me)
    It should appear as soon as you hit the "." after startup.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  10. #10
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,705

    Re: (VB 2005) Form Immobiliser

    Quote Originally Posted by Joacim Andersson View Post
    The "pure" code modules that you also can use in VB are actually being compiled as a static class behind the scenes (together with a global imports statement).
    So are they module modules?

  11. #11
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: (VB 2005) Form Immobiliser

    No, they are in fact class modules too.

  12. #12

    Thread Starter
    Hyperactive Member Tarablue's Avatar
    Join Date
    Feb 2007
    Location
    Somewhere West of GMT
    Posts
    398

    Re: (VB 2005) Form Immobiliser

    Hi All,

    OK just got back to the computer.

    What I have is this:-

    I start out with a Solution named Project1. Below this I have a set of Classes each named after a product with one name StartUp. In the StartUp class I have Input Forms and some Splash Screens/Forms and the imfamous FormImmobiliser. This StartUp Class references back to all the other Classes so if I try to reference back to the StartUp Class I get the Circular Dependency error.

    Now if I try to access the FormImmobiliser from another class I get the error mentioned in my original thread. I tried the idea proposed by techgnome without success.

    My main aim is to try and limit the amount of duplicated coding in my program, and with my lack of knowledge of VB it tends to get a bit messy. Don't stress too much over this for I can always place the form in the StartUp class and work from there.

    Very Best Rgds,

    Tarablue

    p.s. I didn't mean to misslead jmcilhinney when I first mentioned Class Modules I was just trying to say that I have a lot of Classes in my Solution.

  13. #13
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,705

    Re: (VB 2005) Form Immobiliser

    Quote Originally Posted by Tarablue View Post
    Hi All,

    OK just got back to the computer.

    What I have is this:-

    I start out with a Solution named Project1. Below this I have a set of Classes each named after a product with one name StartUp. In the StartUp class I have Input Forms and some Splash Screens/Forms and the imfamous FormImmobiliser. This StartUp Class references back to all the other Classes so if I try to reference back to the StartUp Class I get the Circular Dependency error.

    Now if I try to access the FormImmobiliser from another class I get the error mentioned in my original thread. I tried the idea proposed by techgnome without success.

    My main aim is to try and limit the amount of duplicated coding in my program, and with my lack of knowledge of VB it tends to get a bit messy. Don't stress too much over this for I can always place the form in the StartUp class and work from there.

    Very Best Rgds,

    Tarablue

    p.s. I didn't mean to misslead jmcilhinney when I first mentioned Class Modules I was just trying to say that I have a lot of Classes in my Solution.
    You wouldn't get any errors specifically from one class referencing another. Are you actually talking about projects rather than classes? Basically, if you end up in this situation then there is a fault in your design. Libraries should not be created arbitrarily, and if you find that you have two libraries that need to reference each other then there is some arbitrariness to the way you have designed your libraries.

  14. #14

    Thread Starter
    Hyperactive Member Tarablue's Avatar
    Join Date
    Feb 2007
    Location
    Somewhere West of GMT
    Posts
    398

    Re: (VB 2005) Form Immobiliser

    Hi jmcilhinney,

    Maybe I'm not quite getting this right but if I place a 2 Classes into a project and go to properties for Class 1 and then reference Class 2 from the References tab and then do likewise with Class 2 to Class 1, then surely I'm producing a circular reference?

    Rgds,
    Tarablue

  15. #15

    Thread Starter
    Hyperactive Member Tarablue's Avatar
    Join Date
    Feb 2007
    Location
    Somewhere West of GMT
    Posts
    398

    Re: (VB 2005) Form Immobiliser

    Hi jmcilhinney

    No, I have just checked, they are VB Classes not projects. Each of the Classes refers to a product and each Class holds data pertaining specifically to that product.

    Rgds,
    Tarablue

  16. #16
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,795

    Re: (VB 2005) Form Immobiliser

    ACK! NOOOOOO! You don't set references to CLASSES! You set references to assemblies (or projects) .... so if you have two classes in the same project, they can refer to each other with no problems. For things in the same project, you don't need to set any references. Can you post a screenshot of your solution explorer window? Might help to envision how you have things set up.


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  17. #17

    Thread Starter
    Hyperactive Member Tarablue's Avatar
    Join Date
    Feb 2007
    Location
    Somewhere West of GMT
    Posts
    398

    Re: (VB 2005) Form Immobiliser

    Hi techgnome,

    Attached is screen capture of part of my Solution. Hope it helps. I went back to the properties area References/Add/Projects and received the Circular Dependencies error.

    I also noted that all the Class Libraries in my Solution are classed as Projects, did't notice that before.

    Best Rgds,
    Tarablue

    p.s. Hang about just trying to gety the image imported
    Last edited by Tarablue; Mar 3rd, 2010 at 12:13 AM.

  18. #18
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,705

    Re: (VB 2005) Form Immobiliser

    A class library is not a class, it's a library containing classes. Classes can exist in pretty much any type of project. A Class Library is just a project template designed to compile to a DLL and contain non-WinForms types.

    If you're getting a circular reference the you have two projects referencing each other, plain and simple. If you feel you need that then your design is flawed and you need to reconsider what type belongs in what project.

  19. #19

    Thread Starter
    Hyperactive Member Tarablue's Avatar
    Join Date
    Feb 2007
    Location
    Somewhere West of GMT
    Posts
    398

    Re: (VB 2005) Form Immobiliser

    Hi jmcilhinney,

    This all stems from a problem I was getting before. I had 1 Solution with every form, product data etc., in one long list, i.e., line by line. This seemed to be working fine until I reached about 60 lines, then problems started to enter my project.

    I was then advised to split it up in this fashion and so far things are woking out. I'm not much of a programmer, "You got that right", I here you say, but so far I can do product selections, show lists of products and display graphs and data pertaining to the product.

    You would head for the nearest Scotch bottle if you could view my code, but it works. So far as this form idea goes I think I'll just place it back in the StartUp area and work from there.

    Bye the bye, how do we import images, I've forgotten?

    Very Best Rgds,
    Tarablue

  20. #20

    Thread Starter
    Hyperactive Member Tarablue's Avatar
    Join Date
    Feb 2007
    Location
    Somewhere West of GMT
    Posts
    398

    Re: (VB 2005) Form Immobiliser

    Hi jmcilhinney,

    OK I found how to import images

    Best Rgds,
    Tarablue

  21. #21

    Thread Starter
    Hyperactive Member Tarablue's Avatar
    Join Date
    Feb 2007
    Location
    Somewhere West of GMT
    Posts
    398

    Re: (VB 2005) Form Immobiliser

    Hi techgnome,

    Screen shot as requested, I hope.

    Best Rgds,
    Tarablue
    Attached Images Attached Images  

  22. #22
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,705

    Re: (VB 2005) Form Immobiliser

    I think you mean that you had one PROJECT. You've almost certainly still only got one SOLUTION. A solution is basically a container for projects. When you create a new project from scratch, VS creates a solution and it puts your new project inside that. You can then add more projects to that solution if you want. Each instance of VS can only open one solution at a time, but each solution can contain as many projects as you like.

    The solution represents the application and each project represents a component of the application. For instance, you might have a Windows Forms Application project that compiles to an EXE, a Class Library project contains all your business logic and compiles to a DLL and another Class Library project that contains all your data access code and also compiles to a DLL. There's a clear hierarchy: the EXE references the business logic DLL and that references the data access DLL. The data access DLL shouldn't even have to know that the business logic DLL exists. Likewise the business logic DLL shouldn't have to know that the application exists. Each DLL should be created such that it can be consumed by any other DLL or EXE that cares to. No DLL should ever be dependent on its consumer. Dependencies flow one way through the hierarchy only. In the above example, you should be able to remove the GUI completely and replace it with a completely new one and the business logic DLL would just keep on working. That's how you need to look at designing your own application. This is one of the problems that occurs when development precedes design.

    EDIT: You can even see from the top line in the Solution Explorer, you have a single solution that contains 17 projects. I can only reiterate, you need to rethink your design first, then change your development strategy based on that new design. You might have to add some new types or consolidate some old ones but you simply cannot have two DLLs, i.e. class libraries, referencing each other.

  23. #23

    Thread Starter
    Hyperactive Member Tarablue's Avatar
    Join Date
    Feb 2007
    Location
    Somewhere West of GMT
    Posts
    398

    Re: (VB 2005) Form Immobiliser

    Hi jmcilhinney,

    H'm, I get your point and will need to consult some more books on the subject. At least if I re-design my project now I would have most of the ground work already done, I just need to transfer the data and form layouts across and tweak the settings.

    Thanks for your time and comments.

    Best Rgds,
    Tarablue

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width