locked
Class Library RRS feed

  • Question

  • I created a class library named classlibrary1 and added reference to program TEST that calls the function
     When I run program to call function in class library I receive following error  'decimaltostring' is not declared
    '===========================================================================================================
    ' Classlibrary1
    ' Class Library

     Public Class Class1
        Function decimaltostring(ByVal x_decimal As Decimal, ByRef x_string As String)
            x_string = x_decimal.ToString
            Return x_string
        End Function
    End Class

    '===========================================================================================================
    '
    ' program TEST

    Imports ClassLibrary1
    Public Class mnu_main


        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

            Dim my_decimal As Decimal = 4456.43
            Dim my_string As String = ""
            decimaltostring(my_decimal, my_string)

        End Sub
    End Class
    '===========================================================================================================

    I have never done a class library before can someone help me with this basic module


    Charlie Soroka

    Sunday, June 3, 2012 3:56 PM

Answers

  • Hi Charlie,

    it works- You have to make a reference of classLibrary1 in projekt test. (Assembly ClassLibrary1.dll) here sreenshot:

    My project test here is named ConsoleApplication1

    Here is the project solution:

    and the code:

    Imports ClassLibrary1
    Module Module1
        Sub Main()
            Dim my_decimal As Decimal = 4456.43
            Dim my_string As String = ""
            Dim c1 As New Class1
            'OK
            c1.decimaltostring(my_decimal, my_string)
            'OK
            Class1.decimaltostring2(my_decimal, my_string)
        End Sub
    End Module

    and class1:

    Public Class Class1
        Public Function decimaltostring(ByVal x_decimal As Decimal, ByRef x_string As String)
            x_string = x_decimal.ToString
            Return x_string
        End Function
        Public Shared Function decimaltostring2(ByVal x_decimal As Decimal, ByRef x_string As String)
            x_string = x_decimal.ToString
            Return x_string
        End Function
    End Class

    Please notice:

    When You make changes in class1 You have to compile the whole solution. Otherwise this changes wil not be visible in the main project.

    I hope this helps

    regards Ellen


    Ich benutze/ I'm using VB2008 & VB2010


    • Edited by Ellen Ramcke Monday, June 4, 2012 6:19 AM
    • Marked as answer by sorokateam Monday, June 4, 2012 11:56 PM
    Monday, June 4, 2012 6:15 AM
  • Hello sorokateam,

    I also tried the 2nd way by adding  Public SHARED to function and then added the class1 to the function call and received the following message: Could not load file or assembly 'ClassLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.

    Charlie Soroka

    som moths ago i wrote this sample , hope this help , http://code.msdn.microsoft.com/Creazione-di-una-libreria-ec412ff4

    This and only one example, but the written procedure and what matters.

    Regards.


    • Marked as answer by sorokateam Monday, June 4, 2012 11:58 PM
    Monday, June 4, 2012 8:04 PM
  • Hi Charlie,

    Public  Function decimaltostring(ByVal x_decimal As Decimal, ByRef x_string As String)

    I've forgotten make in class test this changes:

    Dim c1 as New class1

    c1.decimaltostring(my_decimal, my_string)

    ..... or

    Public shared  Function decimaltostring(ByVal x_decimal As Decimal, ByRef x_string As String)

    and in test:

    class1.decimaltostring(my_decimal, my_string)

    regards Ellen


    Ich benutze/ I'm using VB2008 & VB2010



    Sunday, June 3, 2012 6:28 PM
  • Thanks for reply Ellen:

    I added dim c1 as new class1 and added the c1 to function call.  Program test will compile with no errors.

    When I run program I receive following error: An error occurred creating the form. See Exception.InnerException for details.  The error is: Could not load file or assembly 'ClassLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.


    Charlie Soroka

    • Marked as answer by sorokateam Monday, June 4, 2012 11:57 PM
    Sunday, June 3, 2012 9:16 PM
  • I also tried the 2nd way by adding  Public SHARED to function and then added the class1 to the function call and received the following message: Could not load file or assembly 'ClassLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.

    Charlie Soroka

    • Marked as answer by sorokateam Monday, June 4, 2012 11:56 PM
    Sunday, June 3, 2012 9:29 PM
  • Hi Ellen:  I could not get to work so I deleted the test application and created again and was able to get it to work as per your code.  Thank you for your help.


    Charlie Soroka

    • Marked as answer by sorokateam Monday, June 4, 2012 11:56 PM
    Monday, June 4, 2012 11:56 PM

All replies

  • Hi Charlie,

    Public  Function decimaltostring(ByVal x_decimal As Decimal, ByRef x_string As String)

    I've forgotten make in class test this changes:

    Dim c1 as New class1

    c1.decimaltostring(my_decimal, my_string)

    ..... or

    Public shared  Function decimaltostring(ByVal x_decimal As Decimal, ByRef x_string As String)

    and in test:

    class1.decimaltostring(my_decimal, my_string)

    regards Ellen


    Ich benutze/ I'm using VB2008 & VB2010



    Sunday, June 3, 2012 6:28 PM
  • Thanks for reply Ellen:

    I added dim c1 as new class1 and added the c1 to function call.  Program test will compile with no errors.

    When I run program I receive following error: An error occurred creating the form. See Exception.InnerException for details.  The error is: Could not load file or assembly 'ClassLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.


    Charlie Soroka

    • Marked as answer by sorokateam Monday, June 4, 2012 11:57 PM
    Sunday, June 3, 2012 9:16 PM
  • I also tried the 2nd way by adding  Public SHARED to function and then added the class1 to the function call and received the following message: Could not load file or assembly 'ClassLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.

    Charlie Soroka

    • Marked as answer by sorokateam Monday, June 4, 2012 11:56 PM
    Sunday, June 3, 2012 9:29 PM
  • Hi Charlie,

    it works- You have to make a reference of classLibrary1 in projekt test. (Assembly ClassLibrary1.dll) here sreenshot:

    My project test here is named ConsoleApplication1

    Here is the project solution:

    and the code:

    Imports ClassLibrary1
    Module Module1
        Sub Main()
            Dim my_decimal As Decimal = 4456.43
            Dim my_string As String = ""
            Dim c1 As New Class1
            'OK
            c1.decimaltostring(my_decimal, my_string)
            'OK
            Class1.decimaltostring2(my_decimal, my_string)
        End Sub
    End Module

    and class1:

    Public Class Class1
        Public Function decimaltostring(ByVal x_decimal As Decimal, ByRef x_string As String)
            x_string = x_decimal.ToString
            Return x_string
        End Function
        Public Shared Function decimaltostring2(ByVal x_decimal As Decimal, ByRef x_string As String)
            x_string = x_decimal.ToString
            Return x_string
        End Function
    End Class

    Please notice:

    When You make changes in class1 You have to compile the whole solution. Otherwise this changes wil not be visible in the main project.

    I hope this helps

    regards Ellen


    Ich benutze/ I'm using VB2008 & VB2010


    • Edited by Ellen Ramcke Monday, June 4, 2012 6:19 AM
    • Marked as answer by sorokateam Monday, June 4, 2012 11:56 PM
    Monday, June 4, 2012 6:15 AM
  • Hello sorokateam,

    I also tried the 2nd way by adding  Public SHARED to function and then added the class1 to the function call and received the following message: Could not load file or assembly 'ClassLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.

    Charlie Soroka

    som moths ago i wrote this sample , hope this help , http://code.msdn.microsoft.com/Creazione-di-una-libreria-ec412ff4

    This and only one example, but the written procedure and what matters.

    Regards.


    • Marked as answer by sorokateam Monday, June 4, 2012 11:58 PM
    Monday, June 4, 2012 8:04 PM
  • Hi Ellen:  I could not get to work so I deleted the test application and created again and was able to get it to work as per your code.  Thank you for your help.


    Charlie Soroka

    • Marked as answer by sorokateam Monday, June 4, 2012 11:56 PM
    Monday, June 4, 2012 11:56 PM