|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
A simple questionHi
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 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 Hi Adrian,
> Hi Ugh - Well, first of all I recommend you read a book about object oriented > 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. 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
Creating events in VB.net
read app.config File pointer to be positioned at the last occurance of a keyword How to back up an object... MDIChild form controls: how to pass information between them? MDI ignoring Handles for Ctl+F6 Unexpected behaviour of MyClass (please ignore 1st post) Why use Dim outside of sub? Schedule task in VB.NET Can't set focus to controls on TabPage |
|||||||||||||||||||||||