-
June 23rd, 2003, 12:04 AM
#1
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.
-
June 23rd, 2003, 02:07 AM
#2
Maybe you could post the code and let us see it.
Marketing our skills - please participate in the survey and share your insights
-
-
June 23rd, 2003, 02:21 AM
#3
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
-
June 23rd, 2003, 02:45 AM
#4
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.
-
June 23rd, 2003, 02:59 AM
#5
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
-
-
June 23rd, 2003, 03:24 AM
#6
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
-
June 23rd, 2003, 09:13 AM
#7
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?
-
June 23rd, 2003, 09:27 AM
#8
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
-
June 23rd, 2003, 11:27 PM
#9
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.
-
June 24th, 2003, 12:11 AM
#10
Hi, let's see the whole form module..
Busy
-
June 25th, 2003, 12:51 AM
#11
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|