Dear Visitore of this Question I m New to VB.net
i have declared a structure in vb.net and i want to give values to its members how could i can do that
help me plz

Structure Employee
dim inta as integer
dim strs as string
end structure

how to intialise the values to inta and strs

Re: How to declare structure and its data members in vb.net 80 80

There are a few methods for Structures, but there is more support for Classes. The easiest is to just assign the elements one at a time.

Dim empTest As Employee

empTest.inta = 1
empTest.strs = "Bill White"

To create an initializer, you need to create a Sub New and pass the initialization to it. You also have to declare the variable using the New keyword.

Structure Employee
    Public inta As Integer
    Public strs As String

    Public Sub New(intNew as Integer, strNew As String)
        inta = intNew
        strs = strNew
    End Sub
End Structure

Dim empTest As Employee = New Employee(1, "Bill White")

If you are wanting this kind of construction, it might be time to start considering Classes instead.

Re: How to declare structure and its data members in vb.net 80 80

That line could be instead:

Dim empTest As New Employee(1, "Bill White")
Re: How to declare structure and its data members in vb.net 80 80

it is so simple create an instance ot the structure and give the values to the instance
dim emp as employee
emp.inta=10
emp.strs="John"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.