|
-
Jan 17th, 2000, 08:00 PM
#1
Thread Starter
Junior Member
Hi everyone,
My Requirement is as explained below.
In a MDI Form I'm having a Menu Control Array named mnu_Masters. If I click a Menu Control Array Item , the corresponding
Form should be showed. If I have a large number of Array Items, the Code will increase b'cos , I ' ve to put Select Case
Statement for all Menu Items as shown below.
Private Sub mnu_Masters_Click(Index As Integer)
Dim pStr_Caption As String
pStr_Caption = mnu_Masters(Index).Caption
Select Case LCase(pStr_Caption)
Case "mill master"
frm_MasterMill.Show
Case "mode of trans master"
frm_ModeofTrans.Show
End Select
End Sub
I 've stored the Menu Captions in a Menu Control Array and their correponding Form Names in a Table. Is it possible to show a form using the name stored in Table so that I don't have to put Case Statement for all Menu Items? Thanks for any help.
Regards
Sujatha
-
Jan 17th, 2000, 11:41 PM
#2
Member
You can use a collection to store all of the forms in your app and set their 'Key' value to the form name. You can then load and show the form as indicated by its 'Key'.
Here's an example using a std. exe project. Add Forms 1, 2, & 3 to the project. Add a menu and menu subitems 'Form2' & 'Form3'. Paste this code into the form and run it.
Option Explicit
Private col_Forms As Collection
Private Sub Form_Load()
Set col_Forms = New Collection
'Add form references and set their 'Key'
col_Forms.Add Form2, "Form2"
col_Forms.Add Form3, "Form3"
End Sub
Private Sub mnuFormItem_Click(Index As Integer)
Dim frm As Form
Set frm = col_Forms.Item(mnuFormItem(Index).Caption)
frm.Show
End Sub
[This message has been edited by mcleran (edited 01-18-2000).]
[This message has been edited by mcleran (edited 01-18-2000).]
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
|