Results 1 to 15 of 15

Thread: [RESOLVED] Getting list of ALL forms in a project (including Unloaded forms)

  1. #1

    Thread Starter
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Resolved [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:
    1. Dim f As Form
    2. For Each f In Project1.AllForms 'list of ALL forms
    3.     cboStartupForm.AddItem f.Name
    4. Next

    (They couldn't resolve it in CodeGuru. I have exactly same question. I hope someone can show me the correct path.
    )

    (related thread)

    .
    Last edited by iPrank; Jun 19th, 2008 at 01:51 AM. Reason: TemplateProject/Framework <> Tomato/Tomatoe
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    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?

    Some people call this approach "database driven gui" and it is very common thing than you can find in practically every industry.

  3. #3

    Thread Starter
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    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?
    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.
    Last edited by iPrank; Jun 18th, 2008 at 09:45 PM.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  4. #4
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    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?
    You asre working on some project so it is a "project", right?

  5. #5

    Thread Starter
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    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.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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:
    1. Open App.Path & "\project1.vbp" For Input As 1
    2.   myarr = Split(Input(LOF(1), #1), vbNewLine)
    3.   Close 1
    4.   For i = 0 To UBound(myarr)
    5.     If Left(myarr(i), 5) = "Form=" Then Debug.Print Mid(myarr(i), 6)
    6.    
    7.   Next
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7

    Thread Starter
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    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.
    Last edited by iPrank; Jun 19th, 2008 at 07:28 AM.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  8. #8
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  9. #9

    Thread Starter
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    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).
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  10. #10

    Thread Starter
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    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...]
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  11. #11
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    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.

  12. #12

    Thread Starter
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    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.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  13. #13

  14. #14

    Thread Starter
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    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:
    1. Option Explicit
    2.  
    3. Private Sub UserControl_Initialize()
    4.     UpdateFormList ' works if the form is saved before adding the usercontrol
    5. End Sub
    6.  
    7. Private Sub UserControl_Terminate()
    8.     UpdateFormList 'works both time - wheather the form is saved or not
    9. End Sub
    10.  
    11. Private Sub UpdateFormList()
    12.     Dim F1 As Integer, F2 As Integer
    13.     Dim i As Long
    14.  
    15.     If Dir$(App.Path & "\" & App.EXEName & ".vbp") <> "" Then
    16.         F1 = FreeFile
    17.         Open App.Path & "\" & App.EXEName & ".vbp" For Input As F1
    18.         F2 = FreeFile
    19.         Open App.Path & "\FormList.txt" For Output As F2
    20.         Dim myarr() As String
    21.         myarr = Split(Input(LOF(F1), #F1), vbNewLine)
    22.         Close F1
    23.  
    24.         For i = 0 To UBound(myarr)
    25.  
    26.             If Left(myarr(i), 5) = "Form=" Then
    27.                 Write #F2, Mid(myarr(i), 6)
    28.             End If
    29.  
    30.         Next
    31.  
    32.         Close F2
    33.     End If
    34.  
    35. End Sub
    You could also check if you are running in IDE.
    Last edited by iPrank; Jun 19th, 2008 at 11:43 AM.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  15. #15
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    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...



    However, as long as it works for you...

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