Results 1 to 5 of 5

Thread: Run Time Error 340

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2000
    Location
    Quantico, VA, USA
    Posts
    41

    Question

    I posted this under 'General VB Topics' also, but I thought one of you guys has probably run into this problem also. Here it is:

    I've got a form that uses an array of controls (commandbuttons) called cmdOptions. Sporadically, the form will not load and it will give me an error of "Control Array Element '0' doesn't exist". The control is created at design time, so this error definitely makes no sense. The only thing I could think of is this: I load the form and then immediately access a user-defined function on it that accesses the control. If the form doesn't load quick enough, the I can see the function getting to the point where it needs the control and it not being there. Basically, I need a way around this little problem.

    -chuck
    To err is human, but to apologize frequently is embarassing.

  2. #2
    Member
    Join Date
    Aug 2000
    Posts
    51
    I think you can say something like

    if cmdbtn(x).visible then <your procedure>

    If it is visible then it is loaded. I've used this before with a data control, but I don't know if this sugestion will be compatable with the prodedure runing on the buttons.

    I assume you call the procedure in the form_load event. You may want to try puting the call in another event. Maybe the from_initialize. (my first sugestion is probably better)

    Let me know if this works.


  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2000
    Location
    Quantico, VA, USA
    Posts
    41
    I call the procedure from another function on another form. See, here's how it works:

    'on frmMain
    Private Sub mnuList_Click()
    Dim mList

    'here is where I load the form by calling the function
    mList = frmOne.BuildList(Id)

    End Sub

    'on frmOne
    Public Function BuildList(Id As String) As Boolean

    Me.Caption = "Build"

    '**************************
    '*HERE'S WHERE IT BLOWS UP*
    '**************************

    cmdOptions(0).Caption = "BUILD"

    '***********************************************
    '* IT TELLS ME THAT cmdOptions(0) DOESN'T EXIST*
    '* SOMETIMES... *
    '***********************************************

    '***********************************************
    '* KEEP IN MIND THAT A LOT MORE HAPPENS HERE. *
    '* THE ONLY THING THAT EVER HAPPENS TO THE *
    '* BUTTON IS THAT IT IS MADE INVISIBLE. *
    '***********************************************

    End Function

    Nothing else happens to that button. It is the first one in the list of things to do, so maybe the button sometimes isn't loaded quick enough?

    -chuck
    To err is human, but to apologize frequently is embarassing.

  4. #4

    Thread Starter
    Member
    Join Date
    Jan 2000
    Location
    Quantico, VA, USA
    Posts
    41

    Arrow

    Thanks to all who replied. I'm not sure, but I think the code problem had something to do with multitasking capabilities of NT. mlewis was right in that the controls should load before any code executes. but i think when the code is actually executed, some strands execute simultaneously (with checks of course to see if these strands affect each other). Here's how I fixed it, in case anyone else has this problem:

    instead of just calling the method of the form to load it, ie. formOne.BuildList, do this-

    'this will start the create a new instance
    dim frmTwo as new formOne
    'allow any events to fire that need to
    doevents
    'finally call method
    frmTwo.BuildList

    the funny thing is that this error didn't start to happen until after a data access routine (the two shouldn't be related in the least). again, thanks to all who responded.

    -chuck
    To err is human, but to apologize frequently is embarassing.

  5. #5
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617

    hmm

    Chuck...

    Just saw this.. but my 2 cents.. Try the changes in
    between ****
    and let me know

    Take care!
    -------------

    'on frmMain
    Private Sub mnuList_Click()
    Dim mList

    'here is where I load the form by calling the function

    **********************************
    dim thisform as new frmOne

    with thisform
    .load
    .BuildList
    end with
    **************************************
    End Sub

    'on frmOne
    Public Function BuildList(Id As String) As Boolean

    Me.Caption = "Build"

    '**************************
    '*HERE'S WHERE IT BLOWS UP*
    '**************************

    cmdOptions(0).Caption = "BUILD"

    '***********************************************
    '* IT TELLS ME THAT cmdOptions(0) DOESN'T EXIST*
    '* SOMETIMES... *
    '***********************************************

    '***********************************************
    '* KEEP IN MIND THAT A LOT MORE HAPPENS HERE. *
    '* THE ONLY THING THAT EVER HAPPENS TO THE *
    '* BUTTON IS THAT IT IS MADE INVISIBLE. *
    '***********************************************

    End Function

    Nothing else happens to that button. It is the first one in the list of things to do, so maybe the button sometimes isn't loaded quick enough?

    -chuck

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