[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

In an MDI form I need to have a running Document number... i.e.  Document 1... Document 2

Posted on 2005-05-11
6
Medium Priority
?
218 Views
Last Modified: 2012-05-05
Hello,

I have a MDI parent form that has a "new" menu item that opens a new child form.

For instance if i keep clicking new it will open up multiple child forms.  

I need each form to have its unique number

Example
Document 1
Document 2
Document 3
Document 4

Here is what i have so far:


Dim frmCurrentChild As New frmChild

        Dim intNum As Integer
        Dim intNewNum As Integer


        frmCurrentChild.Text = "Document " & intNum

        intNum = intNewNum + 1

        frmCurrentChild.MdiParent = Me

        gChildForms.Add(frmCurrentChild)

        frmCurrentChild.Show()

This code keeps giving me a zero for the document number

Any help would be appreciated.

Thanks
Derek
0
Comment
Question by:Durkis007
  • 3
  • 2
6 Comments
 
LVL 7

Expert Comment

by:davidrichardson
ID: 13982272
Do you want it to open the same form multiple times?
0
 

Author Comment

by:Durkis007
ID: 13982293
What it does is open the child form multiple times within the parent form.  Every time i want to open a new child form the document number needs to increase +1

Derek
0
 
LVL 34

Accepted Solution

by:
Sancler earned 1000 total points
ID: 13982696
Derek

I assume all the code you show is within a procedure - sub or function.  Every time a procedure runs it re-initialises all its variables and, when it is finished, it disposes of them.  So

   Dim intNum As Integer
   Dim intNewNum As Integer

always sets them to 0 and

   frmCurrentChild.Text = "Document " & intNum

always produces "Document 0".

You can change this behaviour by declaring a variable with the word Static, rather than Dim.  When you do that the procedure remembers the value between calls to it.  As you want your document numbering to start with 1, rather than 0, I suggest the following

   Static intNum as Integer 'this will start off as 0
   Dim frmCurrentChild As New frmChild
   intNum += 1 'this will increase it by 1 on every call
   frmCurrentChild.Text = "Document " & intNum 'first document will be 1
   frmCurrentChild.MdiParent = Me
   gChildForms.Add(frmCurrentChild)
   frmCurrentChild.Show()

Roger
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Durkis007
ID: 13982751
Awsome!!  Thank you for your help

I forgot about the static variable. would have never thought to use it.

Thanks Again,
Derek
0
 

Author Comment

by:Durkis007
ID: 13988904
I have one more question on that..

here is an example that i uncovered.

When i click new it gives me "document 1"

Now if i close that "document 1"

the next time i open a new document it starts off with "document 2"

is there a way to reset the number back to 1 ?

Thanks Dere

If its too complicated its not a big deal, i am just curious.
0
 
LVL 34

Expert Comment

by:Sancler
ID: 13989569
Derek

Yes, there are various ways you could do it.  One might be to have a public Boolean variable - lets call it Reset - which a child form set to True in its close event.  Then, in the sub as coded before you could add - immediately after the line Dim frmCurrentChild As New frmChild

   If Reset then
      intNum = 0
      Reset = False
   End If

But if it were handled that way you would have the possibility of two Documents with the same name.  Doc1 is opened, Doc2 is opened.  If Doc2 is closed, the next document opened will be Doc1 again, and the original Doc1 is still open.

So, rather than just resetting, you might need to keep track of what numbers are already in use and choose the first one that is not.  That would be possible.  It (obviously) gets a bit more complicated: but not very.  A simple way would be to have a public Boolean array - lets call it InUse().  All elements would be automatically initialised as False.  In the procedure above you would, rather than using a static variable that you increment every time, loop through InUse(), starting at 1, to find the first False, use the element number of that for the Document name, and change that element in InUse() to  True.  Once 1 is in use, the first False it will find is 2 and the next Document number will be 2, and so on.  In a form's close event you set the relevant element number in InUse() back to False.  Then, once Doc1 is closed, its number will be available again next time you create a new child form.  

If you want to go that far, and have trouble coding it, post again here.  I'll be happy to try and help again for the original points - for which, by the way, thanks.

Roger
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month19 days, 15 hours left to enroll

873 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