Results 1 to 7 of 7

Thread: [RESOLVED] Trapping of arrays - HELP ME!!!!

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    Resolved [RESOLVED] Trapping of arrays - HELP ME!!!!

    Hi All
    Here is my prob
    I want to trap the array of data - it's condition. Then I want add it to List1.
    However I get an error. >> Subscript out of range <<. What it's wrong?

    my code:
    Code:
    Option Explicit
    
    Private Sub Command1_Click()
    Dim IntCounter     As Integer
    Dim strData()     As String
                    
        For IntCounter = 0 To 4
          If txtDana(IntCounter).Text <> "" Then
             strData(IntCounter) = lblZwierzaki(IntCounter).Caption  ' <<< here I get this error
            List1.AddItem strData(IntCounter)  ' it was: List1.AddItem Sztuki(IntCounter)
          End If                               ' I correct already this now
        Next
         
          
    End Sub
    thanks in advance
    Last edited by Tamgovb; Mar 24th, 2009 at 04:02 PM.
    I know, I know, my English is bad, sorry .....

  2. #2
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: Trapping of arrays - HELP ME!!!!

    whats txtDana() ? Is that declared outside the scope ?
    whats Sztuki() ? Is that also declared outside the scope?
    Where are you getting the error ? You have 3 arrays here.. which line is the error in?

    You need Redim Preserve strdata(IntCounter) before you actually fill it.
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    Re: Trapping of arrays - HELP ME!!!!

    Hi

    thanks for answer.

    TxtDana() – it’s the array of objects (5 textboxes)
    Sztuki() - it was my mistake, already I correct it - should be:
    Code:
                  
               List1.AddItem strData(IntCounter)
    Please look in my code.


    some1uk03 wrote - quote:
    >> You need Redim Preserve strdata(IntCounter) before you actually fill it. <<

    OK, hmmm you would can show me in my code?

    My idea: Near every txtbox is Label with name. Now, I want write it to the List1, all these name from Labeles this txtbox in which some values were. How to make? Trapping of arrays?

    thanks in advance
    Last edited by Tamgovb; Mar 24th, 2009 at 04:25 PM.
    I know, I know, my English is bad, sorry .....

  4. #4
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Trapping of arrays - HELP ME!!!!

    strData() cannot be used without a Redim as mentioned in post#2.
    However, you don't need strData() to add those captions into Listbox.
    Code:
    Option Explicit
    
    Private Sub Command1_Click()
        Dim IntCounter     As Integer
                    
        For IntCounter = 0 To 4
          If txtDana(IntCounter).Text <> "" Then
            List1.AddItem lblZwierzaki(IntCounter).Caption
          End If                               
        Next
          
    End Sub
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    Re: Trapping of arrays - HELP ME!!!!

    Hi

    anhn thank you, sorry, I knew about this. I need some way to trap the array because in my project I have to write in proper column these data in my ListBox (I use Send Message function to create these columns) The division of data on a columns, way to displays this, it all forces such solution (trapping arrays). This code will be as example only my prob.
    Therefore I ask about some an example of code, showing how to trap this array?

    Please help me, thanks in advance
    I know, I know, my English is bad, sorry .....

  6. #6
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: Trapping of arrays - HELP ME!!!!

    Try:

    Code:
    Private Sub Command1_Click()
    Dim IntCounter     As Integer
    Dim strData()     As String
                    
        For IntCounter = 0 To 4
          If txtDana(IntCounter).Text <> "" Then
             Redim Preserve strData(IntCounter)
             strData(IntCounter) = lblZwierzaki(IntCounter).Caption  ' <<< here I get this error
            List1.AddItem strData(IntCounter)  ' it was: List1.AddItem Sztuki(IntCounter)
          End If                               ' I correct already this now
        Next
             
    End Sub
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    Re: Trapping of arrays - HELP ME!!!!

    some1uk03, it fine working!!!!!!!!!!!!!!!!

    Thanks, many thanks

    tamgovb
    I know, I know, my English is bad, sorry .....

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