Home All Groups Group Topic Archive Search About
Author
17 Jul 2006 11:37 AM
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

Author
17 Jul 2006 12:09 PM
zulander
Will this do :
MeterAccountName=nothing

zulan***@gmail.com wrote:
Show quoteHide quote
> 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
Author
17 Jul 2006 12:37 PM
Samuel Shulman
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




<zulan***@gmail.com> wrote in message
Show quoteHide quote
news:1153138185.209492.140580@b28g2000cwb.googlegroups.com...
> Will this do :
> MeterAccountName=nothing
>
> zulan***@gmail.com wrote:
>> 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
>
Author
17 Jul 2006 2:31 PM
Claes Bergefall
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

Show quoteHide quote
"Samuel Shulman" <samuel.shul***@ntlworld.com> wrote in message
news:udjp82ZqGHA.4032@TK2MSFTNGP03.phx.gbl...
> 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
>
>
>
>
> <zulan***@gmail.com> wrote in message
> news:1153138185.209492.140580@b28g2000cwb.googlegroups.com...
>> Will this do :
>> MeterAccountName=nothing
>>
>> zulan***@gmail.com wrote:
>>> 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
>>
>
>
Author
18 Jul 2006 8:41 PM
Stanimir Stoyanov
"Claes Bergefall" wrote:
> 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;
--
Best regards,

Stanimir Stoyanov
admin@nospam.stoyanoff.info
Author
17 Jul 2006 12:31 PM
Samuel Shulman
Perhaps you can create a method to do that or assign a new variable

ob = new MeterAccountName



<zulan***@gmail.com> wrote in message
Show quoteHide quote
news:1153136263.423559.42950@s13g2000cwa.googlegroups.com...
> 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
>
Author
17 Jul 2006 1:48 PM
Patrice
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).

--
Patrice

"Samuel Shulman" <samuel.shul***@ntlworld.com> a écrit dans le message de
news: efU93zZqGHA.3***@TK2MSFTNGP04.phx.gbl...
Show quoteHide quote
> Perhaps you can create a method to do that or assign a new variable
>
> ob = new MeterAccountName
>
>
>
> <zulan***@gmail.com> wrote in message
> news:1153136263.423559.42950@s13g2000cwa.googlegroups.com...
>> 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
>>
>
>