How to add a file reference to VB project

Posted on 2008-11-18
Last Modified: 2012-05-05

I have a VB project that contains about 20 vb files.  Each file handles a particular function like importing a file, or changing an asset location etc, etc.

I'm adding another file to perform a function that closely relates an existing file/function.  How do I make reference to this file so I can use a particular routine in that file?

Considering the picture below, I would expect a dropdown somewhere that would provide a way to reference project files.

How would I do this if the file name I need to reference is called AssetChangeDept.vb ??

Question by:John500
    LVL 21

    Expert Comment

    In solutions Explorer pane,

    right click and Add Reference...
    Most likely go to Browse and get the .exe or dll...but .vb file isn't compiled, so that's not going to work...if you want to use the vb file, then you could

    In solutions Explorer pane,

    right click and add existing Item...

    Author Comment

    Sorry if I wasn't clear on the project configuration.  The twenty files I spoke of are part of the existing project.  Thus, the file I'm adding will be file 21 and let's say the file I want to barrow from is file 5.

    Since this file 21 handles a completely separate task I don't want to add the code to file 5.  I just want to make reference to the routine in file 5.

    See what I mean?
    LVL 21

    Expert Comment

    I think i understand what you want...will you need runtime values from file example file 5?  Meaning will it be running live data and when you access it, the success of file 21 is dependent upon that data?  or will you be passing the values to file 5 from file 21?  if so, could you just create an instance of form 5 within form 21 (OOP) to use its methods?
    LVL 11

    Accepted Solution

    Can you use inheritance?

    If you use this the new class(file) will have all the functionality of the original file...
    Public Class ClassA 
        Inherits ClassB 
        Public Sub FunctionExtension() 
        End Sub 
    End Class 

    Open in new window

    LVL 11

    Expert Comment

    I may have misunderstood ...
    This file - AssetChangeDept.vb  - Does it contain a namespace?
    If so you need to :

    Imports AssetChangeDeptNameSpace.FileNameClassName

    Does this make sense or ???

    Author Comment

    I won't be needing any runtime values.  I just need to access the methods or functions from file - AssetChangeDept.vb

    File AssetChangeDept.vb definitely contains a class called 'AssetChangeDept'

    This class has a particular function I want to use - Private Sub MoveAsset()

    The constructor for the class looks like this:

    Public Sub New(ByVal f1 As AssetTrack)
            Call InitializeComponent()
            form1 = f1
    End Sub

    I guess I need to declare an instance of the class in my new file.  However, I don't need or want the Form that comes with this class.  I guess I have two choices at this point:

    1)  Create an overloaded constructor that doesn't take a Form  (how would that look? )
    2)  Be redundant and forget this class - just barrow all the code in the new file.

    If I did create a new constructor, how would I do it?  The call to InitializeComponent() basically initializes all the buttons and objects of a Form I'm not even using:

    Public Sub New()
    End Sub

    Then what in my new file?


    LVL 21

    Assisted Solution

    well if that's the case, what you can do is create a helper class and pull out this functionality and place it in a regular class...and create an instance of the helper class to take care of this method...then you can delete if from the .vb also and create an instance of helper class in there as well to access the method...

    Author Closing Comment

    I ended up going an entirely different route which relied more on the database stored procedures than the VB code.  Take a look at this question if you folks get a chance:

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    760 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

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now