473,327 Members | 1,930 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,327 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 1310
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.