CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Mar 2001
    Posts
    71

    Controll Array - Pls. Help asap. Very erratic problem

    Hi,
    I agree that the problem i am facing is erratic and most of you may find it funny also but the fact is that i am facing this problem and not able to find a solution to this problem.

    Problem Description:
    I have got a controll array of text boxes having say 10 elements.
    All of these elements are created at design time.
    I have coded some lines on the lost focus event of theses text boxes and i m using the same index in the code which i recieve as a parameter to the lost focus method.

    Now the problem is that this problem does not occurs every time.Most of the time it runs fine but some times i get an error message stating that the controll array element does not exists.
    It is very strange because i my self had added this element at design time.Moreover on FormLoad I have populated the very same element of the textbox.

    Details of error message i recieve are as follows:
    Error No. = 340
    Error Description = Controll Array Element 'Element No' doesn't exists.

    So you see this problem is very hasty.
    Actually I have not been able to pin point where the problem is, because this does not occurs every time and occurs randomly on any element of the controll array.

    So if you have ever faced this problem and were able to rectify it then pls. do write in something.

    Regards.

    Vivek Chopra.

  2. #2
    Join Date
    Feb 2002
    Location
    Makati City, Philippines
    Posts
    1,054
    Maybe you could post the code and let us see it.
    Marketing our skills - please participate in the survey and share your insights
    -

  3. #3
    Join Date
    Mar 2001
    Posts
    71
    As required by you i m posting the code also

    Code:
    Private Sub txt_st_LostFocus(Index As Integer)
        txt_st(Index).BackColor = global_module.gvar_NormalColor
        Select Case txt_st(Index).Tag
            Case "MS", "NS"
                    img_help(Index).Visible = False
        End Select
    End Sub
    Error comes on the first line itself where i m trying to change backcolor of the textbox.
    Most of the time it works but some times it gives an error saying
    Controll Array Element 'Element No' doesn't exists.

    Regards

  4. #4
    Join Date
    Mar 2003
    Location
    Orange County, CA
    Posts
    99
    I don't think this helps your problem, but when you have global variables declared in a module, you dont have to use the dot operator (global_module.gvar_NormalColor). Just use it by saying gvar_NormalColor.

  5. #5
    Join Date
    Feb 2002
    Location
    Makati City, Philippines
    Posts
    1,054
    I can't see anything wrong with the code. Do you have something in your code that manipulates the index?

    I also checked on my end and I found out that it is possible to have a control array saomething like:
    Txb(0)
    Txb(2)
    ...where Txb(1) doesn't exist.
    Try to check your controls again.
    Marketing our skills - please participate in the survey and share your insights
    -

  6. #6
    Join Date
    Mar 2001
    Posts
    71
    Hi Thanks for your replies.

    I have been working with vb for last 3years, and as per my understanding also, this piece of code does not have any problem.More Over if you see the code, i am using the index which has been passed to me by vb itself and that is why i define this problem as eratic more over this problem does not occurs every time.

    When ever the problem occurs just close the application , run it again and the second time it will run fine.

    It is so unpridictable.

    for waverdr9:

    I have prefixed the variable name with the module name bacause i have another module which contains another variable with the same name.

    Regards

  7. #7
    Join Date
    Jun 2001
    Location
    Mi
    Posts
    1,249
    Well lets take a different tack ... WHEN does this error occur? When the program 1st starts up? After running for a while? What are you doing with these textboxes? How are you filling them? What about a buffer overflow blowing out the stack?

  8. #8
    Join Date
    Sep 2000
    Location
    FL
    Posts
    1,452
    Code:
    Private Sub txt_st_LostFocus(Index As Integer)
        txt_st(Index).BackColor = global_module.gvar_NormalColor
        Select Case txt_st(Index).Tag
            Case "MS", "NS"
                    img_help(Index).Visible = False
        End Select
    End Sub
    Verify that you have the img_help control for each of your txt_st controls. Also, to help you find the problem, add a

    debug.print Index at the top of your function. This will tell you what the Index of the control is.

    Hope this helps.
    Roger

  9. #9
    Join Date
    Mar 2001
    Posts
    71
    Hi,

    The problem occurs very randomly some times on the first run itself,sometimes on 2nd or 3rd or 4th on any random instance.

    I populate the textboxes on form load using the following syntax:
    txt_st(4).text = "SomeText"
    txt_st(3).text = "SomeText"

    sotoasty : I am facing problem on the first line itself:
    "txt_st(Index).BackColor = global_module.gvar_NormalColor"

    In the debug mode when i check the value of index being passed to me by the vb itself, I figure out it is the same element which the vb is not able to find.

    Regards.

  10. #10
    Join Date
    Jan 2003
    Location
    7,107 Islands
    Posts
    2,487
    Hi, let's see the whole form module..
    Busy

  11. #11
    Join Date
    May 2003
    Location
    Australia
    Posts
    155
    Hi,

    Dont have an answer for you, but got some ideas on what you can try next:

    1) not saying this is neccessarily your problem, but is always a good idea to refer to the controls on your form with Me.txt_st(x), just to avoid potential confusion should you have variables with the same name elsewhere.

    2) Do you have a global/public variable called Index anywhere else in your code??

    3) what is the value and variable type of gvar_NormalColor? Does this get modified. I have seen cases where VB misleadingly reports the wrong error due to the value being assigned to the control array, and not the Index itself.

    4) Are the textboxes visible and enabled? Sometimes you get funny errors like this when the controls are not.

    5) Include in your debug.print statement at beginning of sub the LBound and UBound values for the txt_st() array.

    6) Try using a different name for your control array.

    OK, am clutching at straws now, but might give you some ideas.

    Cheers,
    Tinbum747
    Zen-Programming:

    If a compiler beeps in the IDE forest, and nobody hears it, was there really a bug?

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

Featured