Best Method

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brian

    Best Method

    I am looking for a way to store maybe in an array or dictionary... two
    fields....
    first field would be a string... second would be a date...
    for example.. if i called up myinfo(0) it would show "the first Day"
    "1/1/2008" ???
    Brian


  • Cor Ligthert[MVP]

    #2
    Re: Best Method

    Brian,

    What do you want to do store data or put data in a class.

    For two values the latter is in my idea without sense, and for that are 100
    best methods.

    The same is for store this kind of data, there are probably 20 best methods.

    One of those maybe this one.

    Explore isolated storage, which is a data storage mechanism that provides isolation & safety by defining standardized ways of associating code with saved data.


    Cor


    "Brian" <bsgallatin@com munity.nospamsc hreef in bericht
    news:un2etqitIH A.2068@TK2MSFTN GP05.phx.gbl...
    >I am looking for a way to store maybe in an array or dictionary... two
    >fields....
    first field would be a string... second would be a date...
    for example.. if i called up myinfo(0) it would show "the first Day"
    "1/1/2008" ???
    Brian
    >
    >

    Comment

    • rowe_newsgroups

      #3
      Re: Best Method

      On May 14, 9:26 pm, "Brian" <bsgalla...@com munity.nospamwr ote:
      I am looking for a way to store maybe in an array or dictionary... two
      fields....
      first field would be a string... second would be a date...
      for example.. if i called up myinfo(0) it would show "the first Day"
      "1/1/2008" ???
      Brian
      Sounds to me you just need to make a custom class that has two
      properties, label and date:

      //////////////
      Public Class YourClassNameHe re

      Private _Label As String = String.Empty
      Private _TheDate As DateTime = DateTime.Now

      Public Sub New()

      End Sub

      Public Sub New(ByVal label As String, ByVal theDate As DateTime)
      Me.New()

      Me.Label = label
      Me.TheDate = TheDate
      End Sub

      Public Property Label As String
      Get
      Return _Label
      End Get
      Set (ByVal value As String)
      _Label = value
      End Set
      End Property

      Public Property TheDate As DateTime
      Get
      Return _TheDate
      End Get
      Set (ByVal value As DateTime)
      _TheDate = value
      End Set
      End Property

      '// I typed this in the message so this statement might
      '// not be formatted correctly
      Public Overrides Function ToString() As String
      Return String.Format(" {0} {1}", Me.Label, Me.TheDate)
      End Function

      End Class
      //////////////

      Then you could just store these objects in any sort of IEnumerable
      field (array, list, arraylist, etc) and then when you pull them out of
      the array (or whatever) and call the .ToString() method, you will get
      the string like you requested.

      Thanks,

      Seth Rowe [MVP]

      Comment

      • Mayur H Chauhan

        #4
        Re: Best Method

        Simple and best approach for implementing this in .Net Framework 2.0 is to
        create collection of Type Generic and define the Type of the value that you
        will persist. This will solve majority of the problems. Also this is good in
        terms of performance.

        Thanks,
        Mayur H Chauhan
        "rowe_newsgroup s" <rowe_email@yah oo.comwrote in message
        news:fa413615-ff30-49a4-883c-544c48d50cb1@m4 5g2000hsb.googl egroups.com...
        On May 14, 9:26 pm, "Brian" <bsgalla...@com munity.nospamwr ote:
        >I am looking for a way to store maybe in an array or dictionary... two
        >fields....
        >first field would be a string... second would be a date...
        >for example.. if i called up myinfo(0) it would show "the first Day"
        >"1/1/2008" ???
        > Brian
        >
        Sounds to me you just need to make a custom class that has two
        properties, label and date:
        >
        //////////////
        Public Class YourClassNameHe re
        >
        Private _Label As String = String.Empty
        Private _TheDate As DateTime = DateTime.Now
        >
        Public Sub New()
        >
        End Sub
        >
        Public Sub New(ByVal label As String, ByVal theDate As DateTime)
        Me.New()
        >
        Me.Label = label
        Me.TheDate = TheDate
        End Sub
        >
        Public Property Label As String
        Get
        Return _Label
        End Get
        Set (ByVal value As String)
        _Label = value
        End Set
        End Property
        >
        Public Property TheDate As DateTime
        Get
        Return _TheDate
        End Get
        Set (ByVal value As DateTime)
        _TheDate = value
        End Set
        End Property
        >
        '// I typed this in the message so this statement might
        '// not be formatted correctly
        Public Overrides Function ToString() As String
        Return String.Format(" {0} {1}", Me.Label, Me.TheDate)
        End Function
        >
        End Class
        //////////////
        >
        Then you could just store these objects in any sort of IEnumerable
        field (array, list, arraylist, etc) and then when you pull them out of
        the array (or whatever) and call the .ToString() method, you will get
        the string like you requested.
        >
        Thanks,
        >
        Seth Rowe [MVP]

        Comment

        • Cor Ligthert[MVP]

          #5
          Re: Best Method

          Hi Seth,

          Is this not more simple as it has to be in an array.

          Dim myArray() as String = {"The first Day", "1/1/2008"}

          I could not make more from the question of the OP.

          :-)

          Cor

          "rowe_newsgroup s" <rowe_email@yah oo.comschreef in bericht
          news:fa413615-ff30-49a4-883c-544c48d50cb1@m4 5g2000hsb.googl egroups.com...
          On May 14, 9:26 pm, "Brian" <bsgalla...@com munity.nospamwr ote:
          >I am looking for a way to store maybe in an array or dictionary... two
          >fields....
          >first field would be a string... second would be a date...
          >for example.. if i called up myinfo(0) it would show "the first Day"
          >"1/1/2008" ???
          > Brian
          >
          Sounds to me you just need to make a custom class that has two
          properties, label and date:
          >
          //////////////
          Public Class YourClassNameHe re
          >
          Private _Label As String = String.Empty
          Private _TheDate As DateTime = DateTime.Now
          >
          Public Sub New()
          >
          End Sub
          >
          Public Sub New(ByVal label As String, ByVal theDate As DateTime)
          Me.New()
          >
          Me.Label = label
          Me.TheDate = TheDate
          End Sub
          >
          Public Property Label As String
          Get
          Return _Label
          End Get
          Set (ByVal value As String)
          _Label = value
          End Set
          End Property
          >
          Public Property TheDate As DateTime
          Get
          Return _TheDate
          End Get
          Set (ByVal value As DateTime)
          _TheDate = value
          End Set
          End Property
          >
          '// I typed this in the message so this statement might
          '// not be formatted correctly
          Public Overrides Function ToString() As String
          Return String.Format(" {0} {1}", Me.Label, Me.TheDate)
          End Function
          >
          End Class
          //////////////
          >
          Then you could just store these objects in any sort of IEnumerable
          field (array, list, arraylist, etc) and then when you pull them out of
          the array (or whatever) and call the .ToString() method, you will get
          the string like you requested.
          >
          Thanks,
          >
          Seth Rowe [MVP]

          Comment

          • rowe_newsgroups

            #6
            Re: Best Method

            On May 15, 12:00 pm, "Cor Ligthert[MVP]" <notmyfirstn... @planet.nl>
            wrote:
            Hi Seth,
            >
            Is this not more simple as it has to be in an array.
            >
            Dim myArray() as String = {"The first Day", "1/1/2008"}
            >
            I could not make more from the question of the OP.
            >
            :-)
            >
            Cor
            >
            "rowe_newsgroup s" <rowe_em...@yah oo.comschreef in berichtnews:fa4 13615-ff30-49a4-883c-544c48d50cb1@m4 5g2000hsb.googl egroups.com...
            >
            On May 14, 9:26 pm, "Brian" <bsgalla...@com munity.nospamwr ote:
            I am looking for a way to store maybe in an array or dictionary... two
            fields....
            first field would be a string... second would be a date...
            for example.. if i called up myinfo(0) it would show "the first Day"
            "1/1/2008" ???
            Brian
            >
            Sounds to me you just need to make a custom class that has two
            properties, label and date:
            >
            //////////////
            Public Class YourClassNameHe re
            >
            Private _Label As String = String.Empty
            Private _TheDate As DateTime = DateTime.Now
            >
            Public Sub New()
            >
            End Sub
            >
            Public Sub New(ByVal label As String, ByVal theDate As DateTime)
            Me.New()
            >
            Me.Label = label
            Me.TheDate = TheDate
            End Sub
            >
            Public Property Label As String
            Get
            Return _Label
            End Get
            Set (ByVal value As String)
            _Label = value
            End Set
            End Property
            >
            Public Property TheDate As DateTime
            Get
            Return _TheDate
            End Get
            Set (ByVal value As DateTime)
            _TheDate = value
            End Set
            End Property
            >
            '// I typed this in the message so this statement might
            '// not be formatted correctly
            Public Overrides Function ToString() As String
            Return String.Format(" {0} {1}", Me.Label, Me.TheDate)
            End Function
            >
            End Class
            //////////////
            >
            Then you could just store these objects in any sort of IEnumerable
            field (array, list, arraylist, etc) and then when you pull them out of
            the array (or whatever) and call the .ToString() method, you will get
            the string like you requested.
            >
            Thanks,
            >
            Seth Rowe [MVP]
            The twist I saw was that he wanted to display both the label and the
            date together, hence my ToString() override. Though you are correct,
            the question was a bit vague to give an accurate answer.

            Thanks,

            Seth Rowe [MVP]

            Comment

            • Brian

              #7
              Re: Best Method

              ok,, let me try to tell say it different way what I am wanting to do.
              I want to have a collection of dates to add to the monthcalendar.b oldeddates
              but, I would like to list the dates I have bolded in something like a text
              box.... and show that
              1/1/2008 is New Years day... "New Years Day 1/1/2008"
              and I'll have a list of holidays for collection...

              "rowe_newsgroup s" <rowe_email@yah oo.comwrote in message
              news:bafe414b-9814-4405-8999-cfe2bc431fdf@c5 8g2000hsc.googl egroups.com...
              On May 15, 12:00 pm, "Cor Ligthert[MVP]" <notmyfirstn... @planet.nl>
              wrote:
              >Hi Seth,
              >>
              >Is this not more simple as it has to be in an array.
              >>
              >Dim myArray() as String = {"The first Day", "1/1/2008"}
              >>
              >I could not make more from the question of the OP.
              >>
              >:-)
              >>
              >Cor
              >>
              >"rowe_newsgrou ps" <rowe_em...@yah oo.comschreef in
              >berichtnews:fa 413615-ff30-49a4-883c-544c48d50cb1@m4 5g2000hsb.googl egroups.com...
              >>
              On May 14, 9:26 pm, "Brian" <bsgalla...@com munity.nospamwr ote:
              >I am looking for a way to store maybe in an array or dictionary...
              >two
              >fields....
              >first field would be a string... second would be a date...
              >for example.. if i called up myinfo(0) it would show "the first Day"
              >"1/1/2008" ???
              > Brian
              >>
              Sounds to me you just need to make a custom class that has two
              properties, label and date:
              >>
              //////////////
              Public Class YourClassNameHe re
              >>
              Private _Label As String = String.Empty
              Private _TheDate As DateTime = DateTime.Now
              >>
              Public Sub New()
              >>
              End Sub
              >>
              Public Sub New(ByVal label As String, ByVal theDate As DateTime)
              Me.New()
              >>
              Me.Label = label
              Me.TheDate = TheDate
              End Sub
              >>
              Public Property Label As String
              Get
              Return _Label
              End Get
              Set (ByVal value As String)
              _Label = value
              End Set
              End Property
              >>
              Public Property TheDate As DateTime
              Get
              Return _TheDate
              End Get
              Set (ByVal value As DateTime)
              _TheDate = value
              End Set
              End Property
              >>
              '// I typed this in the message so this statement might
              '// not be formatted correctly
              Public Overrides Function ToString() As String
              Return String.Format(" {0} {1}", Me.Label, Me.TheDate)
              End Function
              >>
              End Class
              //////////////
              >>
              Then you could just store these objects in any sort of IEnumerable
              field (array, list, arraylist, etc) and then when you pull them out of
              the array (or whatever) and call the .ToString() method, you will get
              the string like you requested.
              >>
              Thanks,
              >>
              Seth Rowe [MVP]
              >
              The twist I saw was that he wanted to display both the label and the
              date together, hence my ToString() override. Though you are correct,
              the question was a bit vague to give an accurate answer.
              >
              Thanks,
              >
              Seth Rowe [MVP]

              Comment

              • Cor Ligthert[MVP]

                #8
                Re: Best Method

                The shortest way I now with one row

                \\\\
                dim dt as new datatable
                dim dcfirstcolumn as new datacolumn("fir st")
                dim dcsecondcolumn as new datacolumn("sec ond")
                dt.colums.add(d cfirstcolumn)
                dt.colums.add(d csecondcolumn)
                dim dr as new datarow = dt.rows.newrow
                dr(dcfirstcolum n) = "The first Day"
                dr(dcsecondcolu mn) = "1/2/2008"
                dt.rows.add(dr)
                myListBox.DataS ource = dt
                myListBox.Displ ayMember = "first"
                myListbox.Value Member = "second"
                ///

                Typed in this message so watch errors.

                Cor



                "Brian" <bsgallatin@com munity.nospamsc hreef in bericht
                news:uKR4rnvtIH A.4528@TK2MSFTN GP03.phx.gbl...
                ok,, let me try to tell say it different way what I am wanting to do.
                I want to have a collection of dates to add to the
                monthcalendar.b oldeddates
                but, I would like to list the dates I have bolded in something like a text
                box.... and show that
                1/1/2008 is New Years day... "New Years Day 1/1/2008"
                and I'll have a list of holidays for collection...
                >
                "rowe_newsgroup s" <rowe_email@yah oo.comwrote in message
                news:bafe414b-9814-4405-8999-cfe2bc431fdf@c5 8g2000hsc.googl egroups.com...
                >On May 15, 12:00 pm, "Cor Ligthert[MVP]" <notmyfirstn... @planet.nl>
                >wrote:
                >>Hi Seth,
                >>>
                >>Is this not more simple as it has to be in an array.
                >>>
                >>Dim myArray() as String = {"The first Day", "1/1/2008"}
                >>>
                >>I could not make more from the question of the OP.
                >>>
                >>:-)
                >>>
                >>Cor
                >>>
                >>"rowe_newsgro ups" <rowe_em...@yah oo.comschreef in
                >>berichtnews:f a413615-ff30-49a4-883c-544c48d50cb1@m4 5g2000hsb.googl egroups.com...
                >>>
                >On May 14, 9:26 pm, "Brian" <bsgalla...@com munity.nospamwr ote:
                >>I am looking for a way to store maybe in an array or dictionary...
                >>two
                >>fields....
                >>first field would be a string... second would be a date...
                >>for example.. if i called up myinfo(0) it would show "the first Day"
                >>"1/1/2008" ???
                >> Brian
                >>>
                >Sounds to me you just need to make a custom class that has two
                >properties, label and date:
                >>>
                >//////////////
                >Public Class YourClassNameHe re
                >>>
                > Private _Label As String = String.Empty
                > Private _TheDate As DateTime = DateTime.Now
                >>>
                > Public Sub New()
                >>>
                > End Sub
                >>>
                > Public Sub New(ByVal label As String, ByVal theDate As DateTime)
                > Me.New()
                >>>
                > Me.Label = label
                > Me.TheDate = TheDate
                > End Sub
                >>>
                > Public Property Label As String
                > Get
                > Return _Label
                > End Get
                > Set (ByVal value As String)
                > _Label = value
                > End Set
                > End Property
                >>>
                > Public Property TheDate As DateTime
                > Get
                > Return _TheDate
                > End Get
                > Set (ByVal value As DateTime)
                > _TheDate = value
                > End Set
                > End Property
                >>>
                > '// I typed this in the message so this statement might
                > '// not be formatted correctly
                > Public Overrides Function ToString() As String
                > Return String.Format(" {0} {1}", Me.Label, Me.TheDate)
                > End Function
                >>>
                >End Class
                >//////////////
                >>>
                >Then you could just store these objects in any sort of IEnumerable
                >field (array, list, arraylist, etc) and then when you pull them out of
                >the array (or whatever) and call the .ToString() method, you will get
                >the string like you requested.
                >>>
                >Thanks,
                >>>
                >Seth Rowe [MVP]
                >>
                >The twist I saw was that he wanted to display both the label and the
                >date together, hence my ToString() override. Though you are correct,
                >the question was a bit vague to give an accurate answer.
                >>
                >Thanks,
                >>
                >Seth Rowe [MVP]
                >
                >

                Comment

                Working...