Home All Groups Group Topic Archive Search About
Author
11 Apr 2005 4:21 PM
Adrian
Hi
    sorry for such a simple question!

I want to be able to create a structure or is call a class in VB.net? eg
test1

I want it to have a number of elements that I refer to as test1.username,
test1.password...

But I cant think how to do this.

thanks

Author
11 Apr 2005 4:42 PM
Crouchie1998
Public Structure UserInfo
   Public Usename As String
   Public Password As String
End Structure

Dim strInfo As UserInfo

   strInfo.Username = "Crouchie1998"
   strInfo.Password = "My Password

I hope this helps

Crouchie1998
BA (HONS) MCP MCSE
Author
11 Apr 2005 4:49 PM
Frank Eller
Hi Adrian,

> Hi
>    sorry for such a simple question!
>
> I want to be able to create a structure or is call a class in VB.net?
> eg test1
>
> I want it to have a number of elements that I refer to as
> test1.username, test1.password...
>
> But I cant think how to do this.

Ugh - Well, first of all I recommend you read a book about object oriented
programming ... welll, at least a book aboutt VB.NET. First I must make some
things clear here:

- a struct is not a class - a class is a reference type, a struct is a value
type. They behave different.
- What you need to do is to create a class, put some fields in it and then
create properties for the fields.
- The fields of a class are never accessed from outside the class

What you would need is this:

Public Class Test

  Private _userName As String = String.Empty
  Private _passWord As String = String.Empty

  Public Property UserName() As String
    Get
      Return Me._userName
    End Get
    Set(ByVal Value As String)
      Me._userName = Value
    End Set
  End Property

  Public Property Password() As String
    Get
      Return Me._passWord
    End Get
    Set(ByVal Value As String)
      Me._passWord = Value
    End Set
  End Property

End Class

After that, to access the Properties, you need to create an object of the
class, for example in a Buttons Click-Event:

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

  Dim testObject As New Test
  testObject.UserName = ...

End Sub

That shoud do the trick :-)).

Regards,

Frank Eller
www.frankeller.de