473,396 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

A simple question

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
Nov 21 '05 #1
2 895
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
Nov 21 '05 #2
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

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: abcd | last post by:
I am trying to set up client machine and investigatging which .net components are missing to run aspx page. I have a simple aspx page which just has "hello world" printed.... When I request...
4
by: dba_222 | last post by:
Dear Experts, Ok, I hate to ask such a seemingly dumb question, but I've already spent far too much time on this. More that I would care to admit. In Sql server, how do I simply change a...
14
by: Giancarlo Berenz | last post by:
Hi: Recently i write this code: class Simple { private: int value; public: int GiveMeARandom(void);
30
by: galiorenye | last post by:
Hi, Given this code: A** ppA = new A*; A *pA = NULL; for(int i = 0; i < 10; ++i) { pA = ppA; //do something with pA
17
by: Chris M. Thomasson | last post by:
I use the following technique in all of my C++ projects; here is the example code with error checking omitted for brevity: _________________________________________________________________ /*...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.