473,383 Members | 1,792 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,383 software developers and data experts.

Using a structure in the same way as a primitive type

I'd like to create a structure such as:

Public Structure MyType
Private m_variable As String

Public Property Variable() As String
Get()
return m_variable
End Get
Set (ByVal Value As String)
If validateVariable(Value) Then
m_variable = Value
Else
Throw New ArgumentException("Variable invalid")
End If
End Set
End Property

Private Function validateVariable(ByVal theVar as String)
'Do validation here
End Function
End Structure

and be able to use it like

Dim mt as MyType
Try
mt = "123abc"
Catch
'Handle exception
End Try

instead of

Dim mt As MyType
Try
mt.Variable = "123abc"
Catch
'Handle exception
End Try

Is this possible, and if so, what changes do I need to make?

Thanks

-- Chris

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>TSAD/yXWZ0qaGm1FxUbJXA==</Id>
Nov 22 '05 #1
4 1312
Chris,
Is this possible, and if so, what changes do I need to make?


Currently no. In the next version (VS 2005) yes, thanks to operator
overloading.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 22 '05 #2
Chris,
Is this possible, and if so, what changes do I need to make?


Currently no. In the next version (VS 2005) yes, thanks to operator
overloading.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 22 '05 #3
Chris,
In addition to the other's comments,

I would define a constructor, then you can do:
mt = New MyType("123abc")
Public Structure MyType
Public Sub New(ByVal value As String)
validateVariable(value)
m_variable = value
End Sub

Hope this helps
Jay
"Chris Bernholt via .NET 247" <an*******@dotnet247.com> wrote in message
news:OK*************@TK2MSFTNGP10.phx.gbl... I'd like to create a structure such as:

Public Structure MyType
Private m_variable As String

Public Property Variable() As String
Get()
return m_variable
End Get
Set (ByVal Value As String)
If validateVariable(Value) Then
m_variable = Value
Else
Throw New ArgumentException("Variable invalid")
End If
End Set
End Property

Private Function validateVariable(ByVal theVar as String)
'Do validation here
End Function
End Structure

and be able to use it like

Dim mt as MyType
Try
mt = "123abc"
Catch
'Handle exception
End Try

instead of

Dim mt As MyType
Try
mt.Variable = "123abc"
Catch
'Handle exception
End Try

Is this possible, and if so, what changes do I need to make?

Thanks

-- Chris

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>TSAD/yXWZ0qaGm1FxUbJXA==</Id>

Nov 22 '05 #4
Chris,
In addition to the other's comments,

I would define a constructor, then you can do:
mt = New MyType("123abc")
Public Structure MyType
Public Sub New(ByVal value As String)
validateVariable(value)
m_variable = value
End Sub

Hope this helps
Jay
"Chris Bernholt via .NET 247" <an*******@dotnet247.com> wrote in message
news:OK*************@TK2MSFTNGP10.phx.gbl... I'd like to create a structure such as:

Public Structure MyType
Private m_variable As String

Public Property Variable() As String
Get()
return m_variable
End Get
Set (ByVal Value As String)
If validateVariable(Value) Then
m_variable = Value
Else
Throw New ArgumentException("Variable invalid")
End If
End Set
End Property

Private Function validateVariable(ByVal theVar as String)
'Do validation here
End Function
End Structure

and be able to use it like

Dim mt as MyType
Try
mt = "123abc"
Catch
'Handle exception
End Try

instead of

Dim mt As MyType
Try
mt.Variable = "123abc"
Catch
'Handle exception
End Try

Is this possible, and if so, what changes do I need to make?

Thanks

-- Chris

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>TSAD/yXWZ0qaGm1FxUbJXA==</Id>

Nov 22 '05 #5

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

Similar topics

1
by: BCC | last post by:
Hi, This is kind of a followup to a previous question... I have a container class that has a load of variables (~100). For example, I have groupings like this: class CContainer {...
4
by: Pram | last post by:
I am curious why did Microsoft write System.DateTime as a structure instead of a class? Maybe for backward compatibilty with any existing old code? FYI, one of the differences between...
4
by: Chris Bernholt via .NET 247 | last post by:
I'd like to create a structure such as: Public Structure MyType Private m_variable As String Public Property Variable() As String Get() return m_variable End Get Set (ByVal Value As String)
3
by: case2005 | last post by:
Can anyone help with the following, I don't know if it's possible, but I'm certain there must be a standard way of dealing with this. I have the following: template<typename FooBar, typename...
15
by: Charles Law | last post by:
I have adapted the following code from the MSDN help for PropertyInfo SetValue. In the original code, the structure MyStructure is defined as a class MyProperty, and it works as expected. There is...
1
by: Jonathan Amend | last post by:
I'm trying to port some C++ code to VB.NET but I have hit a snag. I need to add the pointer of a structure which includes an array to an array and then pass it to an API. Here are the two code...
10
by: Qwert | last post by:
Hello, is it correct that if a type (System.Type) is a value (.IsValueType=True) and not primitive (.IsPrimitive=False), that type is a structure? Thanks.
12
by: Sam Kong | last post by:
Hi, JavaScript hides its memory structure. I know that numbers, booleans, null and undefined are value types (value is directed saved in a variable). I want to know: - How JavaScript...
11
by: JerryWEC | last post by:
I want to be able to create a structure like I did in VB6, that have variables Name As String * 10 Age As String * 3 for the size of the strings. Can I do this some way in VB.net? I'm...
65
by: Arjen | last post by:
Hi, Form a performance perspective, is it wise to use the ref statement as much as possible? Thanks! Arjen
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.