Solved

Run time error 340

Posted on 2001-06-11
11
700 Views
Last Modified: 2010-05-02
I have a  form on which I have several control arrays, labels and shapes. If I click on the enabled control array an instance of another form is displayed.

I can have several instances of this form open at any one time but only ever four visible. The maximum that can be open at any one time is 18.

The form consists of  20 labels, 4 lines, 2 shapes and a text box array consisting of 5 elements (0 to 4).

The programme works fine until a condition is reached when I try to enter data into or process a line of code with reference to, the text box array, I get the following message:-

     Run-time error '340'
     Control array element '0' doesn't exist?

It seems to occur when the twentieth instance of the form is active.  Although this doesn't occur on every occasion and there is never twenty instances open at one time.

When I debug, all other elements (eg 1 to 4) exist but for some reason element '0' does not.  My question is why??????  How can it exist for many instances and then on the 20th  call it says it does not exist.
0
Comment
Question by:abdulvb
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 22

Expert Comment

by:rspahitz
ID: 6179504
Without knowing the index and how it relates to the object, this is difficult to solve.

When you run this in the VB environment, what is the index value: 0, 19, 20, ???

Maybe the index is invalid because it's a variable?

At what point was this particular object created: design-time or run-time?

0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6179508
It appears that the ?0? is an EE interpretation of '0'?

As such, I would propose that whatever index variable you are using to specify the textbox index is either never being set or is being lost along the way.

When this situation occurs, you'll have to track back and find out why the variable is not set correctly.
0
 

Author Comment

by:abdulvb
ID: 6179624
The index value is '0' through to (4) and is set up at design time. There is no variable used to determine the value of the index at run-time.

There are five textboxes on the form and the focus is set on the first member, IE textbox(0) when an instance of the form is created at run-time.

Data is entered into the textbox and the focus moves on to the next member.

When the error occurs and I debug, textbox(1) through to textbox(4) exist but textbox(0) does not.

The error only occurs after several of the instances of the form have been created and data is processed succcessfully.
0
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6179803
how do you create the instances of the form/text box? could you place some code?
0
 

Author Comment

by:abdulvb
ID: 6179873
Yes I can. I will extract relevant sections of the code and post it as a comment tomorrow. Thank you for your responses to date.
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:abdulvb
ID: 6184012

Below is the procedure that opens the forms.

It is a little hard to read in this textbox but if you paste it into Word I am sure it will make more sense.

Local variables are INT1, INT2 & INT3. All other variables are global variables except for the variables BattingIndex & InningsIndex , which are passed to the procedure when it is called.

Sub Display_Template(BattingIndex As Integer, InningsIndex As Integer)
 
Dim INT1 As Integer
Dim INT2 As Integer
Dim INT3 As Integer

INT1=0
INT2=0
INT3 = ScoreSheet(CurrentSheet).lblBatting(0).Left + ScoreSheet(CurrentSheet).lblBatting(0).Width + (((ScoreSheet(CurrentSheet).ScaleHeight - 1565) / 9) * Innings(CurrentSheet) + 300)


For INT1 = FirstBatter(CurrentSheet) - 1 To BattingIndex
    If ScoreSheetMatrix(CurrentSheet, INT1, Innings(CurrentSheet) - 1).Tag = "Display Template" Then
        ScoringTemplate(CurrentSheet, INT1).Top = 700 + INT2 * 900                                                                ' Position for top of template
        ScoringTemplate(CurrentSheet, INT1).Left = INT3 + INT2 * 900                                                             ' Position for left of template
        ScoringTemplate(CurrentSheet, INT1).Caption = ScoreSheet(CurrentSheet).BattingOrder(Str(INT1 * 2 + 1)).Text     ' Label for template
        If Not OpenTemplate(CurrentSheet, INT1) Then
            ScoringTemplate(CurrentSheet, INT1).Tag = Trim(Str(BattingIndex) + Str(InningsIndex))    ' Unique identifier for template
            BatterinBox = BattingIndex + 1                ' Set current Batter at Bat
            LastBatter = BattingIndex                         ' Set previous batter
        End If
        ScoringTemplate(CurrentSheet, INT1).Show                            ' Show template
        OpenTemplate(CurrentSheet, INT1) = True                              ' Set indicator to open
        INT2 = INT2 + 1
    End If
Next INT1

End Sub




The procedure is called by a click on the corresponding label array . A typical section of code that calls the procedure is listed below.



Private Sub lblArrayInnings1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
 
  Dim INT1 As Integer
  Dim INT2 As Integer

 
Select Case Button
    Case 1         ' Left Mouse Click used to set up or display active scoring template
         If CurrentSheet = 0 Then
            If Innings(1) > Innings(0) Then
               Call Display_Template(Index, (Innings(CurrentSheet) - 1))                               ? Open scoring template
            Else
               Call cmdSwitch_Click                                        ? Switch to other sheet
               Call Display_Template((Batting(CurrentSheet) - 1), (Innings(CurrentSheet) - 1))     ? Open scoring template
            End If
        Else
            If Innings(0) = Innings(1) Then
               Call Display_Template(Index, (Innings(CurrentSheet) - 1))                    ? Open scoring template
            Else
               Call cmdSwitch_Click                                        ? Switch to other sheet
               Call Display_Template((Batting(CurrentSheet) - 1), (Innings(CurrentSheet) - 1))     ? Open scoring template
            End If
        End If


End Select


End Sub


0
 

Author Comment

by:abdulvb
ID: 6184021
That is confusing -- the EE interpretation of a single inverted comma seems to end up as a question mark.

0
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6184327
I could not locate where is your form instancing code and/or text box control arrays creation part, if you do it in run-time.
0
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6184331
Also, it is a good idea, to put a prefix to identify variables/object names, like "frm" for form names, "p" or "g" for global variables, etc.

This makes your code more readable.
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 50 total points
ID: 7135919
Hi abdulvb,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will suggest to:

    Refund points and save as a 0-pt PAQ.

EXPERTS: Post a comment if you are certain that an expert deserves credit.  Explain why.
==========
DanRollins -- EE database cleanup volunteer
0
 

Author Comment

by:abdulvb
ID: 7136241
I accept that comment. I have still not solved the problem but will continue to find an answer. If I do I will post the result.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now