run time error '340' - Control array element '29' doesn't exsit-VBForums
Results 1 to 21 of 21

Thread: run time error '340' - Control array element '29' doesn't exsit

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2009
    Posts
    112

    run time error '340' - Control array element '29' doesn't exsit

    Hi All!

    I got this error:
    run time error '340' - Control array element '29' doesn't exsit

    When I press the Debug button,
    I'm in this bold line:

    For i = 1 To 28
    ETSI_Selector(i).Value = 0
    ETSI_Selector(i).Visible = False
    ETSI_No(i).Visible = False
    ETSI_Test(i).Visible = False
    Next i

    What can I do?

    10X!!!
    Y

  2. #2
    VBaholic & Loving It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    GetWindowRect()
    Posts
    12,228

    Re: run time error '340' - Control array element '29' doesn't exsit

    How can 29 be in play? Your loop only goes from 1 to 28.
    Insomnia is just a byproduct of, "It can't be done"

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {GDI+ Classes/Samples} {Unicode Open/Save Dialog} {Icon Organizer/Extractor}
    {VBA Control Arrays} {XP/Vista Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: run time error '340' - Control array element '29' doesn't exsit

    Either create control array element 29 or make your loop from 0 to 28

    If there is a third choice, it escapes me.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Sep 2009
    Posts
    112

    Re: run time error '340' - Control array element '29' doesn't exsit

    My loop is from 1 to 28!

    How the error can be by 29?

  5. #5
    VBaholic & Loving It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    GetWindowRect()
    Posts
    12,228

    Re: run time error '340' - Control array element '29' doesn't exsit

    Quote Originally Posted by li9erYol View Post
    My loop is from 1 to 28!

    How the error can be by 29?
    That's what I asked.
    Run it again, when you get the error, hover of the variable i and what is its value? Is it 29?

    If so, is i declared at the top of your form? If so, it may have been changed due to a call to one of your other events, i.e., ETSI_Selector(i) click event for example. In this case, DIM i in the same routine that your for:next loop is running in
    Insomnia is just a byproduct of, "It can't be done"

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {GDI+ Classes/Samples} {Unicode Open/Save Dialog} {Icon Organizer/Extractor}
    {VBA Control Arrays} {XP/Vista Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  6. #6
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,135

    Re: run time error '340' - Control array element '29' doesn't exsit

    It's never a good idea to hardcode counters if you can use some dynamic input: in case of control array you have Lbound/Ubound:
    Code:
        For i = ETSI_Selector.LBound To ETSI_Selector.UBound
            '...
        Next i
    You'd still need some basic error handler to trap non-existant members (control could've been unloaded).

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Sep 2009
    Posts
    112

    Re: run time error '340' - Control array element '29' doesn't exsit

    i decllration:

    Option Explicit

    Dim i As Integer

    Private Sub Form_Load()

    i = 0

    ' Clear & Disable ETSI Objects (Selectors, ETSI No. & Test Name)
    ETSI_Selector(0).Visible = False
    ETSI_No(0).Visible = False
    ETSI_Test(0).Visible = False

    For i = 1 To 39
    Load ETSI_Selector(i)
    Load ETSI_No(i)
    Load ETSI_Test(i)
    Next


    Private Sub ClearSelectedTests()

    For i = 1 To 39
    ETSI_Selector(i).Value = 0

    ETSI_Selector(i).Visible = False
    ETSI_No(i).Visible = False
    ETSI_Test(i).Visible = False
    Next i

  8. #8
    VBaholic & Loving It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    GetWindowRect()
    Posts
    12,228

    Re: run time error '340' - Control array element '29' doesn't exsit

    That should answer your question and verifies my assumptions in previous reply. The variable i is being changed outside of your loop. As I suggested, DIM it in your routines that you use it in, or better yet, DIM a different variable and use that. Do not allow your for:next loops to use the shared i variable and your problem will go away.

    Edited: Rhinobull's suggestion is a good one to implement.
    Last edited by LaVolpe; Apr 13th, 2010 at 09:02 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {GDI+ Classes/Samples} {Unicode Open/Save Dialog} {Icon Organizer/Extractor}
    {VBA Control Arrays} {XP/Vista Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Sep 2009
    Posts
    112

    Re: run time error '340' - Control array element '29' doesn't exsit

    In the Private Sub ClearSelectedTests():

    I remark the 3 lines, as you can see below,
    and it works!

    What is wrong here? the line "ETSI_Selector(i).Value = 0" is working in this For loop

    For i = 1 To 39
    ETSI_Selector(i).Value = 0

    'ETSI_Selector(i).Visible = False
    'ETSI_No(i).Visible = False
    'ETSI_Test(i).Visible = False
    Next i

  10. #10
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Candon City, Ilocos Sur, Phils.
    Posts
    10,810

    Re: run time error '340' - Control array element '29' doesn't exsit

    If that works then this should also work.
    Code:
    For i = 1 To 39
    	ETSI_Selector(i).Value = 0
    	ETSI_Selector(i).Visible = Falsese
    Next i
    Can you try it?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Sep 2009
    Posts
    112

    Re: run time error '340' - Control array element '29' doesn't exsit

    It works but only if i is 1 to 2.

    I tried another thing:

    I remark the first line only:

    For i = 1 To 39
    'ETSI_Selector(i).Value = 0
    ETSI_Selector(i).Visible = False
    ETSI_No(i).Visible = False
    ETSI_Test(i).Visible = False
    Next i

    It works!!!

    I don't undrestand why...?

  12. #12
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Candon City, Ilocos Sur, Phils.
    Posts
    10,810

    Re: run time error '340' - Control array element '29' doesn't exsit

    What happened when you tried the code I provided?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Sep 2009
    Posts
    112

    Re: run time error '340' - Control array element '29' doesn't exsit

    It didn't work!

    I tried another thing and its works! I don't understand the differents:

    For i = 1 To 39
    ETSI_Selector(i).Value = 0

    'ETSI_Selector(i).Visible = False
    'ETSI_No(i).Visible = False
    'ETSI_Test(i).Visible = False
    Next i

    ETSI_Selector(1).Visible = False
    ETSI_Selector(2).Visible = False
    .
    .
    .
    ETSI_Selector(28).Visible = False

    ETSI_No(1).Visible = False
    ETSI_No(2).Visible = False
    ETSI_No(3).Visible = False
    .
    .
    .
    ETSI_No(28).Visible = False

    ETSI_Test(1).Visible = False
    ETSI_Test(2).Visible = False
    ETSI_Test(3).Visible = False
    .
    .
    .
    ETSI_Test(28).Visible = False

  14. #14
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Candon City, Ilocos Sur, Phils.
    Posts
    10,810

    Re: run time error '340' - Control array element '29' doesn't exsit

    If you can upload your project with the faulty form then we may be able to check what's going on.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  15. #15
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,428

    Re: run time error '340' - Control array element '29' doesn't exsit

    li9erYol, can you confirm that you have removed the declaration of i from the top and placed it in the routines with the loop? (see posts #5 & #8)
    Code:
    Option Explicit
    
    Dim i as Integer '<-- bad, will potentially cause problems in loops 
    
    Private Sub ClearSelectedTests()
      Dim i as Integer '<-- good, no issues with scope
    
      For i = 1 To 39
        ETSI_Selector(i).Value = 0
        ETSI_Selector(i).Visible = False
        ETSI_No(i).Visible = False
        ETSI_Test(i).Visible = False
      Next i 
    End Sub
    It is also advisable for follow RhinoBull's advice and use LBound() and UBound() to determine the array bounds.
    Last edited by Milk; Apr 14th, 2010 at 03:26 AM. Reason: more
    W o t . S i g

  16. #16

    Thread Starter
    Lively Member
    Join Date
    Sep 2009
    Posts
    112

    Re: run time error '340' - Control array element '29' doesn't exsit

    I'm using the Option Explicit to another variables,

    Can I do what you write?

    Can you please explain me why:

    * Dim i as Integer is bad, will potentially cause problems in loops ?

    * Dim i as Integer and no issues with scope?

    Thanks again!!!
    Y
    Last edited by li9erYol; Apr 14th, 2010 at 03:46 AM.

  17. #17
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,573

    Re: run time error '340' - Control array element '29' doesn't exsit

    Quote Originally Posted by li9erYol View Post
    I'm using the Option Explicit to another variables,

    Can I do what you write?

    Can you please explain me why:

    * Dim i as Integer is bad, will potentially cause problems in loops ?

    * Dim i as Integer and no issues with scope?

    Thanks again!!!
    Y
    The answer is this:
    Quote Originally Posted by LaVolpe View Post
    That should answer your question and verifies my assumptions in previous reply. The variable i is being changed outside of your loop. As I suggested, DIM it in your routines that you use it in, or better yet, DIM a different variable and use that. Do not allow your for:next loops to use the shared i variable and your problem will go away.

    Edited: Rhinobull's suggestion is a good one to implement.

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India

    Skills: PHP, MySQL, jQuery, VB.Net, VB6, Photoshop...

  18. #18
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: run time error '340' - Control array element '29' doesn't exsit

    Me speak simple English.
    Code:
    Option Explicit
    
    ' MUST BE REMOVED
    Dim i as Integer
    ' Because: it will be SHARED with ALL procedures
    ' When changed in one place, changed everywhere
    
    Private Sub ClearSelectedTests()
      ' Instead: add it in each procedure
      Dim i as Integer
      ' Because: no longer shared with other procedures!
    
      For i = 1 To 39
        ETSI_Selector(i).Value = 0
        ETSI_Selector(i).Visible = False
        ETSI_No(i).Visible = False
        ETSI_Test(i).Visible = False
      Next i 
    End Sub
    Last edited by Merri; Apr 14th, 2010 at 01:08 PM. Reason: 1) Fixing Milk's typos 2) Putting it back like it was

  19. #19
    VBaholic & Loving It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    GetWindowRect()
    Posts
    12,228

    Re: run time error '340' - Control array element '29' doesn't exsit

    Merri, suggest you change from: 1 to 39, to: 1 to 28
    Insomnia is just a byproduct of, "It can't be done"

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {GDI+ Classes/Samples} {Unicode Open/Save Dialog} {Icon Organizer/Extractor}
    {VBA Control Arrays} {XP/Vista Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  20. #20
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: run time error '340' - Control array element '29' doesn't exsit

    Milk typo. He fix too.

    Edit!

    Or not a typo at all, 39 is in Y's own code.

  21. #21
    VBaholic & Loving It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    GetWindowRect()
    Posts
    12,228

    Re: run time error '340' - Control array element '29' doesn't exsit

    Quote Originally Posted by Merri View Post
    Milk typo. He fix too.

    Edit!

    Or not a typo at all, 39 is in Y's own code.
    Ah, you are correct sir, I see 2 different values in 2 different posts -- good eye.
    Which indicates that RhinoBull's suggestion in post #6 is worth implementing.
    Insomnia is just a byproduct of, "It can't be done"

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {GDI+ Classes/Samples} {Unicode Open/Save Dialog} {Icon Organizer/Extractor}
    {VBA Control Arrays} {XP/Vista Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.