Results 1 to 9 of 9

Thread: [2008] Class Project - Need help with making one

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2006
    Location
    UK / East Sussex
    Posts
    1,054

    [2008] Class Project - Need help with making one

    Hi,

    I am all new to the Class project and this is my first one.

    I have a few bits of code that I am always using in projects and I never get them right first time so I thought it would make sense to make a bunch of dlls containing them for easy use and when I have finished them I will make them available for free through my website however having a bit of a problem getting them to work.

    I am not to sure where and how to put things so they can be used by the program using the DLL.

    Firstly how do I declare varbiles to be accessed and modified by a program

    I tried just at the begging of the class doing:

    Public variblename as String()

    i also tried putting them in a module and declaring them public but when in the module my program doesn't see them and when they are in the class it sees them but says it can't access them.


    Secondly how do I declare the sub so that the program can launch it? I tried a Public Sub and a Public Function.


    Thanks,
    Max
    M.Carpenter

    Server Admin for Wurm Online
    Wurm Online - A very unique and original MMO from Code Club AB
    https://www.youtube.com/watch?v=YQlYar2uHWAWurm Trailor


  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: [2008] Class Project - Need help with making one

    In general, what you described all sounds workable. You need to access everything through the library name, though. Thus if you create a class library called MyLib, then you create instances of the forms with:

    NewForm = New MyLib.MyForm

    At that point, everything should behave as it would normally. If you still can't see public members, then something else is going on.
    My usual boring signature: Nothing

  3. #3
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2008] Class Project - Need help with making one

    you need to set a reference to your class library project from your main exe project. Even if they are in the same solution, they can't see eachother via code unless you set a reference.

    If they are both part of the same solution, you need to go to add reference for your exe, and then there should be a "projects" tab where you can just select the class library project and it will reference it from your exe. If they are not part of the same solution, then you likely would need to do the same thing, but go to the browse tab instead of the projects tab, and find the compiled class library dll. I recommed putting them in the same solution for easy debugging though.

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2006
    Location
    UK / East Sussex
    Posts
    1,054

    Re: [2008] Class Project - Need help with making one

    Ok, well I added a reference and used Imports But I have just added a declaration for it like Shaggy said and it's no longer got an error. Is this correct:

    Code:
    Imports EmailHandling
    Imports EmailHandling.EasyEmailer
    Imports EmailHandling.EasyEmailer.Sender
    
    Public Class Form1
    
        Dim EmailHand As New EmailHandling.EasyEmailer.Sender
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
    
            EmailHand.ToAddress = "[email protected]"
    
            EmailHand.Send()
    
    
        End Sub
    End Class
    Thats the windows form project that is talking to my dll I know naming is bad but its only an exmaple.

    And here is a bit from my class project:

    Code:
    Imports System.Net.Mail
    
    Namespace EasyEmailer
    
        Public Class Sender
    
            Public ToAddress As String ' Put the To Address Here
    
    
            Public Sub Send()
    
    'code to send the email here
    
            End Sub
    
    
        End Class
    
    End Namespace

    Thanks,
    M.Carpenter

    Server Admin for Wurm Online
    Wurm Online - A very unique and original MMO from Code Club AB
    https://www.youtube.com/watch?v=YQlYar2uHWAWurm Trailor


  5. #5
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2008] Class Project - Need help with making one

    looks like you are doing it correctly.

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2006
    Location
    UK / East Sussex
    Posts
    1,054

    Re: [2008] Class Project - Need help with making one

    Thanks for your help then. Will mark it as resolved.

    So hopefully by then end of the year my developer section of my site should be up and running and I should have a small collection of DLLS :-) Will post a copy of the link on my sig when it is.
    M.Carpenter

    Server Admin for Wurm Online
    Wurm Online - A very unique and original MMO from Code Club AB
    https://www.youtube.com/watch?v=YQlYar2uHWAWurm Trailor


  7. #7
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: [2008] Class Project - Need help with making one

    I don't think you need all those Imports statements since you are fully decorating the variable declaration. I never use Imports, because I prefer to fully decorate declarations, but if you use the Imports statements, then this should be sufficient:

    Dim EmailHand As New Sender
    My usual boring signature: Nothing

  8. #8
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2008] Class Project - Need help with making one

    Quote Originally Posted by Shaggy Hiker
    I don't think you need all those Imports statements since you are fully decorating the variable declaration. I never use Imports, because I prefer to fully decorate declarations, but if you use the Imports statements, then this should be sufficient:

    Dim EmailHand As New Sender
    so do you actually remove all the project level imports too??

  9. #9
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: [2008] Class Project - Need help with making one

    No, I leave them, but I do generally fully decorate the names, even if I don't need to. With intellisense, and being a fast typist, there is little cost to doing so, and I find it easier to remember what I was doing when I come back to the code later.
    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
  •  



Click Here to Expand Forum to Full Width