?
Solved

adding items to menu during runtime

Posted on 1998-08-05
7
Medium Priority
?
215 Views
Last Modified: 2010-05-03
i would like to give the user of my program
the ability to edit/change/delete items from
the menubar. these changes would be saved in
an ini file and read from when the program
loads. If its alot easier (on me) the user
could manually edit the ini file. how do i go
about reading multiple items from an ini file
and adding them to the programs menu?...please
be detailed and give example...thanks
0
Comment
Question by:mwam
  • 4
  • 2
7 Comments
 

Expert Comment

by:zabman
ID: 1468081
Well there are several ways to go about this, I'll use the one I think is easiest:

1.  Create the menubar with ALL of the options that you would    
    like to have.

2.  In the MAIN FORM LOAD read the INI file and have the program
    interperate the information to see if the menu controll will
    be visable.  That's it!

  You see, it is virtually impossible to create new controls in Run-Time, however, you can have the controls visible or invisible!  

  If you would like a demo app, e-mail me at zabman@hotmail.com and I will send you a copy.

                           -- Neil Z. :-)

0
 

Author Comment

by:mwam
ID: 1468082
you'll have to be more specific.
i don't know of any VB command "interpret("file.ini")" :)
also, whether its visible or not, is beside the point.
it wont be visible in the menu bar, but when right clicking,
i'll use the PopupMenu command. the menu control is created
in design time, but i need to know how to add items to it,
when the form loads...thanks.

0
 
LVL 1

Accepted Solution

by:
gissing earned 600 total points
ID: 1468083
Use the following declaration...

Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

.to read a buffer from a private profile (a.k.a. an INI file)

Have a menu on your form which has a menu item which is in a control array, Make it index zero. That is, you will have an invisible menu item called something like "mnuItem(0)". When you read the strings in from the INI file (using the above API call), do a Load mnuItem(1) to create a new menu item with index 1. Make it visible, set its caption, and away you go. (for subsequent menu items, you obviously do a Load mnuItem(2), Load mnuItem(3)... etc. etc.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:mwam
ID: 1468084
that's what i was looking for...thanks
0
 

Author Comment

by:mwam
ID: 1468085
how do i go about adding a command for this
new menuitem...during runtime?
0
 
LVL 1

Expert Comment

by:gissing
ID: 1468086
what do you mean "adding a command" ?
0
 

Author Comment

by:mwam
ID: 1468087
i mean, the menu item has to do something, right?
anyway..i figured out a way...i'm using "Line Input #1"
to read a text file to get the menu items (in this case
programs to be run and their paths) .. i'm adding
the paths to an invisible listbox then assigning them this way:

Private Sub mnurun_Click(Index As Integer)
If Index = 0 Then Exit Sub
For i = 0 To appnumber - 1
If Index = i + 1 Then task = Shell(List2.List(i), vbNormalFocus)
Next
End Sub

appnumber being total number of items (apps) and the paths
being the list2.list(i). theres probably a better way
using arrays, but i've never used them and this seems to work.
any suggestions would be appreciated...thanks


0

Featured Post

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.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month17 days, 12 hours left to enroll

830 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