Results 1 to 7 of 7

Thread: Array of Form refs.

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658

    Question Array of Form references

    I need to implement a back button for my project. I have roughly 40 forms.

    At the minute every time a Form loads it is logged into an array of forms. When i hit the back button i delete the current form from the array and go to the one previous to it. This all works rather marvellously.

    The question which i am getting to is about the array. The array has 20 elements. 1-20. So as i log screens it eventually gets filled up. So when the array is full i want to remove the first element. Shift elements (2 - 20) to elements (1 -19) respectivley and log the new screen in position 20.

    Now i can do this with a loop,
    Code:
    For iCtr = 1 To 19
      Set previousScreens(iCtr) = previousScreens(iCtr + 1)
    Next iCtr
    but obviously this takes a bit of time. Not much but a bit. So what i want to know is this. Is there an easier / quicker method to shift all the elements of the array by one?

    Thanks in advance.
    Iain, thats with an i by the way!

  2. #2
    Member
    Join Date
    Jan 1999
    Location
    Longmont,CO
    Posts
    53

    Thumbs up

    I can't think of an easier way to manage your array. I can, however, think of an easier way to do what you want. Why couldn't you use VB's intrinsic Forms collection to add and remove your forms? It's gonna be there whether you want it or not so you may as well use it. Also, it can handle adding and removing forms from whatever position in the collection you like.

    Dan McLeran

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658

    Unhappy VB Forms collection

    I can't use VB's Forms collection because there is only ever two forms open at once. One of them being a form with a treeView on it (nabigation bar). When you change forms the new form is loaded and the old one is unloaded.

    I need to do this because the infromation on each form is almost always part of the information on another form. So when the user changes something on a form a lot of forms have to be re-initialsed.

    Now i could have coded the loading of the information into the form_activate event, but because on some forms i am having to load 10 comboBoxes with 250 items i decided against it. Because every time the form loses focus then regains it, the form_activate event is fired. You can imagine how slow that would be.

    Any one else with an idea?
    Iain, thats with an i by the way!

  4. #4
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    Can't you create a sort of double linked list with object refs?

    Just a thought...

    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    Paul282,

    Could you please elaborate on that a little. I can't see how this will help matters.
    Iain, thats with an i by the way!

  6. #6
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    Well, do you know how linked lists work? you can expand them, shrink them and change the order of them just by changing the references of the surrounding list items.

    Well, VB doesn't have pointers so this needs to be instanced as class objects because you can create references to other objects effectively creating a linked list.

    you could do this with forms.
    you only have to keep as many forms in the list as you like because destroying all references to an object causes the object to be destroyed so you can choose to remove a form from memory altogether if you like by removing the references.

    I have a project from my VB Algorithms book with an example of a linked list of label controls being added and destroyed... shall I send it too you?

    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658

    Thumbs up Cheers

    If you could send me that example that would be great.

    Cheers for your help.
    Iain, thats with an i by the way!

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