Solved

adding items to menu during runtime

Posted on 1998-08-05
7
187 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 200 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

776 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