Public Structure

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • zulander@gmail.com

    #1

    Public Structure

    Hi i have a Public Structure:

    Public Structure MeterAccountNam e
    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:

    MeterAccountNam e.Meter =""
    MeterAccountNam e.Account =""
    MeterAccountNam e.xName =""


    Thank you

  • zulander@gmail.com

    #2
    Re: Public Structure

    Will this do :
    MeterAccountNam e=nothing

    zulander@gmail. com wrote:
    Hi i have a Public Structure:
    >
    Public Structure MeterAccountNam e
    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:
    >
    MeterAccountNam e.Meter =""
    MeterAccountNam e.Account =""
    MeterAccountNam e.xName =""
    >
    >
    Thank you

    Comment

    • Samuel Shulman

      #3
      Re: Public Structure

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

      ob = new MeterAccountNam e



      <zulander@gmail .comwrote in message
      news:1153136263 .423559.42950@s 13g2000cwa.goog legroups.com...
      Hi i have a Public Structure:
      >
      Public Structure MeterAccountNam e
      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:
      >
      MeterAccountNam e.Meter =""
      MeterAccountNam e.Account =""
      MeterAccountNam e.xName =""
      >
      >
      Thank you
      >

      Comment

      • Samuel Shulman

        #4
        Re: Public Structure

        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
        MeterAccountNam e

        view my other posting




        <zulander@gmail .comwrote in message
        news:1153138185 .209492.140580@ b28g2000cwb.goo glegroups.com.. .
        Will this do :
        MeterAccountNam e=nothing
        >
        zulander@gmail. com wrote:
        >Hi i have a Public Structure:
        >>
        > Public Structure MeterAccountNam e
        > 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:
        >>
        >MeterAccountNa me.Meter =""
        >MeterAccountNa me.Account =""
        >MeterAccountNa me.xName =""
        >>
        >>
        >Thank you
        >

        Comment

        • Patrice

          #5
          Re: Public Structure

          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=MeterA ccountName.Empt y

          (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.shulman @ntlworld.coma écrit dans le message de
          news: efU93zZqGHA.348 4@TK2MSFTNGP04. phx.gbl...
          Perhaps you can create a method to do that or assign a new variable
          >
          ob = new MeterAccountNam e
          >
          >
          >
          <zulander@gmail .comwrote in message
          news:1153136263 .423559.42950@s 13g2000cwa.goog legroups.com...
          >Hi i have a Public Structure:
          >>
          > Public Structure MeterAccountNam e
          > 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:
          >>
          >MeterAccountNa me.Meter =""
          >MeterAccountNa me.Account =""
          >MeterAccountNa me.xName =""
          >>
          >>
          >Thank you
          >>
          >
          >

          Comment

          • Claes Bergefall

            #6
            Re: Public Structure

            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

            "Samuel Shulman" <samuel.shulman @ntlworld.comwr ote in message
            news:udjp82ZqGH A.4032@TK2MSFTN GP03.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
            MeterAccountNam e
            >
            view my other posting
            >
            >
            >
            >
            <zulander@gmail .comwrote in message
            news:1153138185 .209492.140580@ b28g2000cwb.goo glegroups.com.. .
            >Will this do :
            >MeterAccountNa me=nothing
            >>
            >zulander@gmail. com wrote:
            >>Hi i have a Public Structure:
            >>>
            >> Public Structure MeterAccountNam e
            >> 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:
            >>>
            >>MeterAccountN ame.Meter =""
            >>MeterAccountN ame.Account =""
            >>MeterAccountN ame.xName =""
            >>>
            >>>
            >>Thank you
            >>
            >
            >

            Comment

            • Stanimir Stoyanov

              #7
              Re: Public Structure

              "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.st oyanoff.info

              Comment

              Working...