Results 1 to 8 of 8

Thread: [RESOLVED] Arrays, Simple right?.. erm :/

  1. #1

    Thread Starter
    Addicted Member Dayjo's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    130

    Resolved [RESOLVED] Arrays, Simple right?.. erm :/

    Hello folks,
    I'm having trouble with an array that's a user-defined type.

    Basically I have a user defined type:
    VB Code:
    1. Private Type proxy
    2.     theip As String
    3.     theport As String
    4. End Type
    Then I declare an array as a "proxy";
    VB Code:
    1. Dim proxies() As proxy
    But then I have a loop, that reads a number of lines from a file, say like 6. (the number is not set so I'm not sure of the best way to declare the array size), and then the properties are set like so:
    VB Code:
    1. Open txtListFile For Input As #1
    2. Do Until EOF(1)
    3. DoEvents
    4.     Line Input #1, theproxy
    5.     pos = InStrRev(theproxy, ":")
    6.     theip = Mid(theproxy, 1, pos - 1)
    7.     theport = Mid(theproxy, pos + 1, 6)
    8.  
    9.     proxies(proxyCount).theip = theip
    10.     proxies(proxyCount).theport = theport
    11.    
    12.     proxyCount = proxyCount + 1
    13. Loop
    14. Close #1
    But for some reason, even though "theport" and "theip" are set correctly, when assigning the values to the array property, it just doesnt assign. (They end up being blank) I'm probably doing something really stupid here, but I just cant see why it wont work :/.

  2. #2
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: Arrays, Simple right?.. erm :/

    You are creating a Dynamic array but you are not assigning it any index or what number of elements will the array contain?
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  3. #3

    Thread Starter
    Addicted Member Dayjo's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    130

    Re: Arrays, Simple right?.. erm :/

    Quote Originally Posted by Dayjo
    (the number is not set so I'm not sure of the best way to declare the array size),
    As I said, I'm not sure what's the best way of declaring the array size because it's not always going to be the same.

  4. #4
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: Arrays, Simple right?.. erm :/

    Quote Originally Posted by Dayjo
    As I said, I'm not sure what's the best way of declaring the array size because it's not always going to be the same.
    Then you will have to use Redim Preserve everytime you want to increase the number of elements in the array
    VB Code:
    1. Dim proxies() As proxy
    2. 'some statements
    3. 'initialize array with 10 elements
    4. ReDim proxies(10) As proxy
    5. 'add the data to the array
    6. 'and if you want to add more elements use
    7. 'this will preserver the data and increase the number of elements in the array
    8. ReDim Preserve proxies(15) As proxy
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  5. #5

    Thread Starter
    Addicted Member Dayjo's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    130

    Re: Arrays, Simple right?.. erm :/

    Ok yeah I've done that, but still when I try and assign the value to the array:
    proxies(proxyCount).theip = theip
    It just doesnt assign it, even though "theip" is a value.
    proxies(proxyCount).theip just returns ""

  6. #6
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: Arrays, Simple right?.. erm :/

    Quote Originally Posted by Dayjo
    Ok yeah I've done that, but still when I try and assign the value to the array:
    proxies(proxyCount).theip = theip
    It just doesnt assign it, even though "theip" is a value.
    proxies(proxyCount).theip just returns ""
    Post the code that you have written till now alonwith the changes that you made.
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  7. #7

    Thread Starter
    Addicted Member Dayjo's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    130

    Re: Arrays, Simple right?.. erm :/

    I deleted all the code and started again, it seems to be working now using the "Preserve" method.

    Cheers.

  8. #8
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: Arrays, Simple right?.. erm :/

    Quote Originally Posted by Dayjo
    I deleted all the code and started again, it seems to be working now using the "Preserve" method.

    Cheers.
    Glad it helped..
    Please Mark your thread resolved.
    Use [code] source code here[/code] tags when you post source code.

    My Articles

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