none
How to declare a class variable in VB.NET RRS feed

  • Question

  • I try to convert my VBA code to VB.NET. miscreflocation05152019 is class module.

    How to change 'Public As New miscreflocation05152019' (VBA) in VB.NET

    VBA

    Public refloc As New miscreflocation05152019

    Thanks,

    Jay

    Wednesday, August 14, 2019 2:27 AM

Answers

  • Hi,

    see the following MSDN link:

    https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/objects-and-classes/

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by JayWangTPE Thursday, August 15, 2019 1:50 AM
    Wednesday, August 14, 2019 2:40 AM
    Moderator
  • Right click on a project in solution explorer, select add, select class, give it a name. Now add code eg.

    Public Class miscreflocation05152019
        Public Function GetUserName() As String
            Return Environment.UserName
        End Function
    End Class
    

    Call it in a button click

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim ops As New miscreflocation05152019
        MessageBox.Show(ops.GetUserName())
    End Sub

    Or instead of a class add a code module.

    Public Module miscreflocation05152019
        Public Function GetUserName() As String
            Return Environment.UserName
        End Function
    End Module
    

    Call it

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        MessageBox.Show(miscreflocation05152019.GetUserName())
    End Sub
    A code module is the same as in VBA and in C# a static class.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by JayWangTPE Thursday, August 15, 2019 1:50 AM
    Wednesday, August 14, 2019 10:59 AM
    Moderator

All replies

  • Hi,

    see the following MSDN link:

    https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/objects-and-classes/

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by JayWangTPE Thursday, August 15, 2019 1:50 AM
    Wednesday, August 14, 2019 2:40 AM
    Moderator
  • Right click on a project in solution explorer, select add, select class, give it a name. Now add code eg.

    Public Class miscreflocation05152019
        Public Function GetUserName() As String
            Return Environment.UserName
        End Function
    End Class
    

    Call it in a button click

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim ops As New miscreflocation05152019
        MessageBox.Show(ops.GetUserName())
    End Sub

    Or instead of a class add a code module.

    Public Module miscreflocation05152019
        Public Function GetUserName() As String
            Return Environment.UserName
        End Function
    End Module
    

    Call it

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        MessageBox.Show(miscreflocation05152019.GetUserName())
    End Sub
    A code module is the same as in VBA and in C# a static class.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by JayWangTPE Thursday, August 15, 2019 1:50 AM
    Wednesday, August 14, 2019 10:59 AM
    Moderator
  • It fix my problem.

    Thanks very much!

    Thursday, August 15, 2019 1:50 AM