Results 1 to 4 of 4

Thread: Arrays?

  1. #1

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Arrays?

    I don't want to sound like a dumbass, but is there a way to use arrays in Visual Basic, such as you can in Perl?

    I want to be able to have a list of error messages and call them by like Error(10) or whatever. Is there something similiar to this? If so, can someone tell me how to declare it and use it?

    Thanks in advance.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  2. #2
    Fanatic Member
    Join Date
    May 2001
    Posts
    837
    yep

    VB Code:
    1. Dim E(1 to 10) As String
    2.  
    3. E(1) = "Very Bad Error"
    4. E(2) = "Even Worse Error"
    5. E(3) = "Blue Screen of Death!"
    6.  
    7. MsgBox E(3)
    The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.

  3. #3
    New Member
    Join Date
    Jul 2001
    Location
    Pittsburgh, PA
    Posts
    3

    arrays with variables

    hey, is it possible to declare an array with one dimension being a variable? Life say I want to save memory so i open a file as #0 and then

    Dim i as integer

    do while not EOF(0)
    i = i + 1
    loop

    Can I use i in declaring an array? As in

    Dim arrfoo(0 to 0, 0 to i) as string

    Thanks for your help

    Steve Gazzo
    "Hack for fun, program for profit."

  4. #4
    Fanatic Member
    Join Date
    May 2001
    Posts
    837
    i don't think VB lets you dim an array with a variable the first time, what you have to do is declare it dynamically

    VB Code:
    1. Dim E() As String
    2.  
    3. i = 5
    4.  
    5. ReDim E(1 to i, 1 to i) As String

    also keep in mind (this is a problem i ran into a while back) that when declaring arrays dynamically using preserve, you can only change the last dimension

    so...
    ReDim E(1 to i, 1 to i) As Integer
    is legal

    but after that...
    ReDim Preserve(1 to i, 1 to i + 1) As Integer
    is not, so you can only do
    ReDim Preserve(1 to i, 1 to i + 1) As Integer
    The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width