[RESOLVED] Getting list of ALL forms in a project (including Unloaded forms)
I'm trying to build a 3-tier template-project. In this template-project each user will be able to customize their environment. The admin specifies the default UI and the users can customize it.
Problem is, whenever we add a new form in this project, we'll need to change our UI customizer code.
For example, a user may have the option to set 'Starup Form' by a SetStartupForm() method. When we add a new form in our project, we'll need to add the form's name in that method.
Q. Is there any way to get name of ALL forms (loaded or unloaded) in a project ? I'm looking for something like:
VB Code:
Dim f As Form
For Each f In Project1.AllForms 'list of ALL forms
cboStartupForm.AddItem f.Name
Next
(They couldn't resolve it in CodeGuru. I have exactly same question. I hope someone can show me the correct path. :)
)
(related thread)
.
Re: Getting list of ALL forms in a project (including Unloaded forms)
- Setup database for all the configurations you need
- Always start with default settings
- Let user decide however he/she wants to see the environment
- Save user settings to db per user
- I don't know why do you even need some admin to maintain user environment? :confused:
Some people call this approach "database driven gui" and it is very common thing than you can find in practically every industry.
Re: Getting list of ALL forms in a project (including Unloaded forms)
Quote:
Originally Posted by RhinoBull
- Setup database for all the configurations you need
.......
- Always start with default settings
- Let user decide however he/she wants to see the environment
- Save user settings to db per user
Some people call this approach "database driven gui" and it is very common thing than you can find in practically every industry.
I know. But in that case I'll need to save form's name in the db.
This is a FRAMEWORK, not a project. Other developers (including me) will work on this project simultaniously.
UI customization is our least concern. So, I thought of writing a code that will handle the UI, no developer will need to add his/her form's name/Max-Min size etc to the db.
I want them to just call SetUI(userId) at their form's Form_Load and forget everything about UI customization. No need to add their form's name anywhere.
Quote:
Originally Posted by RhinoBull
- I don't know why do you even need some admin to maintain user environment? :confused:
We have a customizable menu that gets populated from DB. The admin will set access to these menus depending on users role. User role is editable/addable (gm?). So an admin will need to set new level of authorisation for a new role.
For other things, like startup form or other little things, we actually don't need them to be customized by the admin. But thought it may help a new user (very little computer savvy) if an admin already customizes his/her UI depending on the user-role.
Re: Getting list of ALL forms in a project (including Unloaded forms)
Quote:
Originally Posted by iPrank
This is a FRAMEWORK, not a project...
What's type of "framework" and what does it mean? :confused:
You asre working on some project so it is a "project", right?
Re: Getting list of ALL forms in a project (including Unloaded forms)
Oh yes. It is a VB project. Please excuse my poor english. The correct word is 'Template project'.
Other programmers will work on this template project and will add other functionalities.
Re: Getting list of ALL forms in a project (including Unloaded forms)
this will do what you ask, in the IDE, with a little tweaking
vb Code:
Open App.Path & "\project1.vbp" For Input As 1
myarr = Split(Input(LOF(1), #1), vbNewLine)
Close 1
For i = 0 To UBound(myarr)
If Left(myarr(i), 5) = "Form=" Then Debug.Print Mid(myarr(i), 6)
Next
Re: Getting list of ALL forms in a project (including Unloaded forms)
Thanks! But how can I do this runtime ? Oviously the project file will not be there in my client's app.path.
One way I can see to apply your idea is by creating an addin that will add the names of the froms in a module as String, and during runtime, I can load the names from that string.
Another way I can think of is by creating a usercontrol. The programmer should add this usercontrol to his/her form, and the user control will check if it is design-mode and run your code.
Not exactly what I was looking for...but atleast you've shown me a way. :thumb:
Re: Getting list of ALL forms in a project (including Unloaded forms)
sorry, thought you wanted it during development stage, just before compiling you could write to a res file to be compiled within the exe
Re: Getting list of ALL forms in a project (including Unloaded forms)
Oh yes. I need it during development phase. But I don't want other developers to run any code.
Sorry, I was stupid. Your idea is perfect. (I've edited previous post before seeing your reply) I just need to make a usercontrol that will run your code (and all my UI customization code will run from this usercontrol).
Re: Getting list of ALL forms in a project (including Unloaded forms)
Also I'll need to update the res file in Terminate event (just in case someone removes a form from a project).
[I'm not resolving this thread just yet. Just in case...]
Re: Getting list of ALL forms in a project (including Unloaded forms)
But compiling list of forms into resource is basically the same as maintaining that list in the database which is what I suggested in my first reply.
However you do it someone still has to maitain the list - nothing is done for you magically. :confused:
Re: Getting list of ALL forms in a project (including Unloaded forms)
But with westconn1's idea there is no need to manually maintain the list in the db. The CustomizeUI usercontrol (which users must add in their form) will autometically maintain the list.
Re: Getting list of ALL forms in a project (including Unloaded forms)
Resource file will have to be manually edited as well. I'm not aware of any "automated" resource update, are you? :confused:
Re: Getting list of ALL forms in a project (including Unloaded forms)
There is no need to use a resource file. You could save the formlist in a separate file or add to a db.
In a usercontrol
vb Code:
Option Explicit
Private Sub UserControl_Initialize()
UpdateFormList ' works if the form is saved before adding the usercontrol
End Sub
Private Sub UserControl_Terminate()
UpdateFormList 'works both time - wheather the form is saved or not
End Sub
Private Sub UpdateFormList()
Dim F1 As Integer, F2 As Integer
Dim i As Long
If Dir$(App.Path & "\" & App.EXEName & ".vbp") <> "" Then
F1 = FreeFile
Open App.Path & "\" & App.EXEName & ".vbp" For Input As F1
F2 = FreeFile
Open App.Path & "\FormList.txt" For Output As F2
Dim myarr() As String
myarr = Split(Input(LOF(F1), #F1), vbNewLine)
Close F1
For i = 0 To UBound(myarr)
If Left(myarr(i), 5) = "Form=" Then
Write #F2, Mid(myarr(i), 6)
End If
Next
Close F2
End If
End Sub
You could also check if you are running in IDE.
Re: Getting list of ALL forms in a project (including Unloaded forms)
Quote:
Originally Posted by westconn1
sorry, thought you wanted it during development stage, just before compiling you could write to a res file to be compiled within the exe
Quote:
Originally Posted by iPrank
There is no need to use a resource file...
Right... :confused:
However, as long as it works for you...