DIGIT-ARC read-only archive · snapshot: July 23, 2026

Passing enum as parameter (vb.net)

2 posts · originally from https://geek.digit.in/community/threads/passing-enum-as-parameter-vb-net.80584/

puneet.darji
puneet.darji Original post #1
Feb 19, 2008 at 12:21 PM
E.g.

public Enum season
winter=0
summer=1
end enum
public Enum month
jan=0
feb=1
end enum

There are two different enums i want to pass in one common function like.


pubic function fillenum(i send above enum as parameter)

end function

At the time of calling function :-

button_click
fillenum(season)
fillenum(month)
end sub


is this posible.

Thnx in adavance

RCuber
RCuber #2
Feb 19, 2008 at 1:40 PM
^^ you cannot directly pass the enum season or month cause its a type. you have to declare a variable and then passthat to the function

something like this, just a rough example.
Code:
Public Enum season
        winter = 0
        summer = 1
    End Enum
    Public Enum month
        jan = 0
        feb = 1
    End Enum

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim se As season
        Dim mon As month
        test(se)
        test(mon)
    End Sub

    Sub test(ByRef ses As season)
        MessageBox.Show(ses.summer.ToString & vbCrLf & ses.winter.ToString)
    End Sub

    Sub test(ByRef mo As month)
        MessageBox.Show(mo.feb.ToString & vbCrLf & mo.jan.ToString)
    End Sub