I need help with VB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AssFairy
    Confirmed User
    • Jun 2003
    • 674

    #1

    I need help with VB

    I want to fill an array with data but there must be an easier way than this.

    Dim MyArray$(7)
    MyArray$(1) = "Monday"
    MyArray$(2) = "Tuesday"
    MyArray$(3) = "Wednesday"

    What I really want is something like this.

    Dim MyArray$(7)
    Data "Monday","Tuesday","Wednesday" .....

    then use a loop to add the data to the array.


    I could store the data in a text file and read it in like this

    Open "data.txt" For Input As #1
    Do
    x = x + 1
    Input #1, a$
    MyArray$(x) = a$
    Loop Until EOF(1)
    Close

    but I want my data string to be stored within the program.

    I sale lube
  • cluck
    Confirmed User
    • Dec 2002
    • 5248

    #2
    You could store them as comma delimited or whatever then use a function to loop through them and put them in an array I guess.
    icq 279990726
    www.mcdonalds.com <- great money making opportunity

    Comment

    • MrSpeed
      Confirmed User
      • May 2003
      • 158

      #3
      There aren't too many different ways.

      <% Dim mArray(11)
      mArray=Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")
      %>

      Comment

      • gornyhuy
        Chafed.
        • May 2002
        • 18041

        #4
        2 ways come to mind and there are probably better ones:

        1)define a string variable with comma delimeters and then use a string tokenizer

        or

        2)similar to above but use the SPLIT() function which automatically tokenizes a string and returns an array with all the tokens as the array elements.

        have fun!

        icq:159548293

        Comment

        • AssFairy
          Confirmed User
          • Jun 2003
          • 674

          #5
          Originally posted by gornyhuy
          2 ways come to mind and there are probably better ones:

          1)define a string variable with comma delimeters and then use a string tokenizer

          or

          2)similar to above but use the SPLIT() function which automatically tokenizes a string and returns an array with all the tokens as the array elements.

          have fun!
          ??? there is no "Split()" command in VB!

          In old basics you could just use the "Data" and "Read" but VB don't appear to have such a function.

          If you gad a string like .... MyData$="Monday,Tuesday,Wednesday,Thursday"
          how would you put them into an array?
          I sale lube

          Comment

          • gornyhuy
            Chafed.
            • May 2002
            • 18041

            #6
            RTFM.

            http://msdn.microsoft.com/library/de...vafctsplit.asp

            I'm done helping you.

            icq:159548293

            Comment

            • evilregis
              Confirmed User
              • Oct 2003
              • 163

              #7
              Dim Days() as String = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }

              remember VB starts its arrays at 0... so sunday is day(0) not day(1).
              eR
              :: beauty is in the eye of the beer-holder ::

              Comment

              • init
                Confirmed User
                • Oct 2002
                • 973

                #8
                here is a little code i threw up, shows you start with a string then add's data to it. hope this is what you were looking for



                Function Dates()
                Dim strDay As String, iCount As Integer

                strDay = "Monday,Tuesday,Wednesday,Thursday,Friday,Saturday ,Sunday"

                strDates = Split(strDay, ",")

                For iCount = LBound(strDates) To UBound(strDates)


                strDates(iCount) = strDates(iCount) & " Index (" & iCount & ")" & vbNewLine

                MsgBox strDates(iCount)

                Next iCount

                End Function
                icq: 2721653

                Comment

                • gornyhuy
                  Chafed.
                  • May 2002
                  • 18041

                  #9
                  Originally posted by init
                  here is a little code i threw up, shows you start with a string then add's data to it. hope this is what you were looking for



                  Function Dates()
                  Dim strDay As String, iCount As Integer

                  strDay = "Monday,Tuesday,Wednesday,Thursday,Friday,Saturday ,Sunday"

                  strDates = Split(strDay, ",")

                  For iCount = LBound(strDates) To UBound(strDates)


                  strDates(iCount) = strDates(iCount) & " Index (" & iCount & ")" & vbNewLine

                  MsgBox strDates(iCount)

                  Next iCount

                  End Function
                  Nice use of SPLIT...

                  icq:159548293

                  Comment

                  • init
                    Confirmed User
                    • Oct 2002
                    • 973

                    #10
                    Originally posted by gornyhuy


                    Nice use of SPLIT...
                    thanks you :p , easiest peice of code i ever wrote i think
                    icq: 2721653

                    Comment

                    • AssFairy
                      Confirmed User
                      • Jun 2003
                      • 674

                      #11
                      Originally posted by gornyhuy
                      RTFM.

                      http://msdn.microsoft.com/library/de...vafctsplit.asp

                      I'm done helping you.
                      Thanks for the link and taking your time out to help
                      Unfortunately its not supported in my old version of VB, I guess its time to upgrade.
                      I sale lube

                      Comment

                      • AssFairy
                        Confirmed User
                        • Jun 2003
                        • 674

                        #12
                        Originally posted by evilregis
                        Dim Days() as String = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }

                        remember VB starts its arrays at 0... so sunday is day(0) not day(1).
                        Dam.... even this function is not supported in VB5
                        I feel so old and out of date
                        I sale lube

                        Comment

                        Working...