Public Structure

  • Thread starter Thread starter zulander
  • Start date Start date
Z

zulander

Hi i have a Public Structure:

Public Structure MeterAccountName
Dim Meter As String
Dim Account_No As String
Dim xName As String
End Structure

is their a way to clear a structure without having to do the
fallowing:

MeterAccountName.Meter =""
MeterAccountName.Account =""
MeterAccountName.xName =""


Thank you
 
Perhaps you can create a method to do that or assign a new variable

ob = new MeterAccountName
 
no, that will mean that the object doesn't point to any area in the memory
an you will not be able to use this object until you assign it a New
MeterAccountName

view my other posting
 
Actually both are working in VB 2005, but I'm not a big fan of using Nothing
as this is really not the same semantic than for objects. I prefer New but
I'm not yet totally convinced as this is not really something "new".

The third option which I tried would be to create a shared readonly "Empty"
property that returns an empty structure. This way you would just write :

MyStruct=MeterAccountName.Empty

(I thought also about a clear method but i could be easy to add a field and
forgot to reset it).
 
Actually, setting it to Nothing will work in this case (much to my
surprise!) since it's a structure and not a class. You will only get away
with it in VB though. Trying the same thing in C# will give you a compiler
error ("Cannot convert null to '...' because it is a value type")

I would still recommend a separate method for it (like Clear or something).

/claes
 
Claes Bergefall said:
surprise!) since it's a structure and not a class. You will only get away
with it in VB though. Trying the same thing in C# will give you a compiler
error ("Cannot convert null to '...' because it is a value type")

In fact, this method works in C#, too, but only in the initial definition of
the variable. You do not have to explicitely assign null to it, though:

MyStruct msInst;
msInst.myField = value;
 
Back
Top