|
-
Mar 8th, 2010, 08:03 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] menu item msgbox
I have problem,
How to click _title> _click Item(1,2,3,4,5...),
msgbox "item1,2,3,4,5..."
any idea please!
Code:
Begin VB.Menu MF
Caption = "title"
Begin VB.Menu MenuItem
Caption = "Dumm"
Index = 0
Visible = 0 'False
End
Begin VB.Menu MenuExit
Caption = "exit"
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub Form_Load()
Dim I As Integer
For I = 1 To 10
Load MenuItem(I)
MenuItem(I).Caption = "Item " & I
MenuItem(I).Visible = True
Next
End Sub
-
Mar 8th, 2010, 08:07 AM
#2
Re: menu item msgbox
I don't understand what you mean?
When you say "how to click item" are you asking how to programmatically execute the code in the menu click event?
Or, are you trying to dynamically create new menu items?
-
Mar 8th, 2010, 08:33 AM
#3
Re: menu item msgbox
 Originally Posted by rpool
How to click _title> _click Item(1,2,3,4,5...),
msgbox "item1,2,3,4,5..."
Not sure what you are asking, is this even close?....
Code:
Private Sub Command1_Click()
' click menu item 5
Call MenuItem_Click(5)
End Sub
Private Sub MenuItem_Click(Index As Integer)
' show menu caption for the index that was clicked
MsgBox MenuItem(Index).Caption
End Sub
-
Mar 8th, 2010, 08:47 AM
#4
Thread Starter
Hyperactive Member
Re: menu item msgbox
your right. would you tell me what case I need ?
-
Mar 8th, 2010, 08:55 AM
#5
Re: menu item msgbox
 Originally Posted by rpool
your right. would you tell me what case I need ?
Which one...????
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Mar 8th, 2010, 10:02 AM
#6
Thread Starter
Hyperactive Member
Re: menu item msgbox
Thanks, I use myArr() To Do menu items, but said:
Object already loaded (Error 360)
What wrong please!
Code:
Option Explicit
Private Sub Form_Load()
Dim myArr() As String
ReDim myArr(0 To 3, 0 To 1)
myArr(0, 0) = "click a"
myArr(0, 1) = "msgbox a"
myArr(1, 0) = "click b"
myArr(1, 1) = "msgbox b"
myArr(2, 0) = "click c"
myArr(2, 1) = "msgbox c"
myArr(3, 0) = "click d"
myArr(3, 1) = "msgbox d"
Dim crt As Integer
Dim cy As Integer
For crt = LBound(myArr, 1) To UBound(myArr, 1)
For cy = LBound(myArr, 2) To UBound(myArr, 2)
Load MenuItem(crt)
MenuItem(crt).Caption = "Item " & myArr(crt, cy) 'show string Click a, click b, click c...
MenuItem(crt).Visible = True
Next cy
Next crt
End Sub
Private Sub MenuItem_Click(Index As Integer)
' show menu caption for the index that was clicked
MsgBox MenuItem(Index).Caption 'result msgbox a,msgbox b, msgbox c..
End Sub
-
Mar 8th, 2010, 10:03 AM
#7
Re: menu item msgbox
What line of code caused the error?
-
Mar 8th, 2010, 10:25 AM
#8
Thread Starter
Hyperactive Member
Re: menu item msgbox
I try fix:
But new problem little bug:
File>
Click A
Click B
Click C
Click D
Click A <<rpt?
Exit
Code:
Private Sub Form_Load()
Dim cx As Integer
For cx = LBound(mydata, 1) To UBound(mydata, 1)
Load MenuItem((cx) + 1) ''HERE, used +1, not "0"
MenuItem(cx).Caption = mydata(cx, 0)
MenuItem(cx).Visible = True
Next cx
End Sub
Private Sub MenuItem_Click(Index As Integer)
Dim mx As Integer
For mx = LBound(mydata, 1) To UBound(mydata, 1)
If CStr(MenuItem(Index).Caption) = CStr(mydata(mx, 0)) Then
MsgBox mydata(mx, 0) & ">" & mydata(mx, 1)
End If
Next mx
End Sub
Private Function mydata()
Dim myArr() As String
ReDim myArr(0 To 3, 0 To 1)
myArr(0, 0) = "click a"
myArr(0, 1) = "msgbox a"
myArr(1, 0) = "click b"
myArr(1, 1) = "msgbox b"
myArr(2, 0) = "click c"
myArr(2, 1) = "msgbox c"
myArr(3, 0) = "click d"
myArr(3, 1) = "msgbox d"
mydata = myArr
Erase myArr
End Function
-
Mar 8th, 2010, 10:31 AM
#9
Re: menu item msgbox
You need to tell us what happens.
-
Mar 8th, 2010, 10:36 AM
#10
Thread Starter
Hyperactive Member
Re: menu item msgbox
Sorry, I try sound:
Run Ctrl+F5,
that menu named "file"
click file
I can see menu items
Click A
Click B
Click C
Click D
Click A <<rpt?
Exit
(Q1) what only rpt "Click A"
(Q2) I Not undetstand why need Load MenuItem((cx) + 1) ''HERE, used +1, not "0"
Is my bug?
(Q3) Is look fine?
thanks!
-
Mar 8th, 2010, 10:53 AM
#11
Re: menu item msgbox
In your code (post #6), remove this line:
Then try it....
If that doesn't solved your problem, consider uploading your project.... 
Edit:
I thought you have already created the Menus and you want to simply include the captions... That's why I posted the above solution...
Last edited by akhileshbc; Mar 8th, 2010 at 11:13 AM.
Reason: misunderstanding... :D
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Mar 8th, 2010, 10:58 AM
#12
Thread Starter
Hyperactive Member
Re: menu item msgbox
please help me to check!
Code:
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 6285
ClientLeft = 165
ClientTop = 735
ClientWidth = 8700
LinkTopic = "Form1"
ScaleHeight = 6285
ScaleWidth = 8700
StartUpPosition = 3 'def
Begin VB.Menu MenuF
Caption = "File"
Begin VB.Menu MenuItem
Caption = "Dummy"
Index = 0
Visible = 0 'False
End
Begin VB.Menu MenuExit
Caption = "Exit"
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Form_Load()
Dim cx As Integer
For cx = LBound(mydata, 1) To UBound(mydata, 1)
Load MenuItem((cx) + 1)
MenuItem(cx).Caption = mydata(cx, 0)
MenuItem(cx).Visible = True
Next cx
End Sub
Private Sub MenuItem_Click(Index As Integer)
Dim mx As Integer
For mx = LBound(mydata, 1) To UBound(mydata, 1)
If CStr(MenuItem(Index).Caption) = CStr(mydata(mx, 0)) Then
MsgBox mydata(mx, 0) & ">" & mydata(mx, 1)
End If
Next mx
End Sub
Private Function mydata()
Dim myArr() As String
ReDim myArr(0 To 3, 0 To 1)
myArr(0, 0) = "click a"
myArr(0, 1) = "msgbox a"
myArr(1, 0) = "click b"
myArr(1, 1) = "msgbox b"
myArr(2, 0) = "click c"
myArr(2, 1) = "msgbox c"
myArr(3, 0) = "click d"
myArr(3, 1) = "msgbox d"
mydata = myArr
Erase myArr
End Function
-
Mar 8th, 2010, 11:10 AM
#13
Re: menu item msgbox
Here's the complete code: ...
Code:
Option Explicit
Dim myArr() As String
Private Sub Form_Load()
ReDim myArr(0 To 3, 0 To 1)
myArr(0, 0) = "click a"
myArr(0, 1) = "msgbox a"
myArr(1, 0) = "click b"
myArr(1, 1) = "msgbox b"
myArr(2, 0) = "click c"
myArr(2, 1) = "msgbox c"
myArr(3, 0) = "click d"
myArr(3, 1) = "msgbox d"
Dim cx As Integer
For cx = LBound(myArr, 1) To UBound(myArr, 1)
If cx <> 0 Then Load MenuItem((cx)) '~~~> See this
MenuItem(cx).Caption = myArr(cx, 0)
MenuItem(cx).Visible = True
Next cx
End Sub
Private Sub MenuItem_Click(Index As Integer)
Dim mx As Integer
For mx = LBound(myArr, 1) To UBound(myArr, 1)
If CStr(MenuItem(Index).Caption) = CStr(myArr(mx, 0)) Then
MsgBox myArr(mx, 0) & ">" & myArr(mx, 1)
End If
Next mx
End Sub
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Mar 8th, 2010, 11:17 AM
#14
Thread Starter
Hyperactive Member
Re: menu item msgbox
too magic, thanks a lot.
here, changed something,
Form1, is main
Form2
Form3
Form4
Form5 when _click
but :
I try to "click a", can't start Form2.Show
I try to "click b", can't start Form3.Show
...
any idea please!
Code:
Option Explicit
Dim myArr() As String
Private Sub Form_Load()
ReDim myArr(0 To 3, 0 To 1)
myArr(0, 0) = "click a"
myArr(0, 1) = "Form2"
myArr(1, 0) = "click b"
myArr(1, 1) = "Form3"
myArr(2, 0) = "click c"
myArr(2, 1) = "Form4"
myArr(3, 0) = "click d"
myArr(3, 1) = "msgbox d"
Dim cx As Integer
For cx = LBound(myArr, 1) To UBound(myArr, 1)
If cx <> 0 Then Load MenuItem((cx)) '~~~> See this
MenuItem(cx).Caption = myArr(cx, 0)
MenuItem(cx).Visible = True
Next cx
End Sub
Private Sub MenuItem_Click(Index As Integer)
Dim mx As Integer
For mx = LBound(myArr, 1) To UBound(myArr, 1)
If CStr(MenuItem(Index).Caption) = CStr(myArr(mx, 0)) Then
MsgBox myArr(mx, 0) & ">" & myArr(mx, 1)
myArr(mx, 1).Show
End If
Next mx
End Sub
-
Mar 8th, 2010, 07:33 PM
#15
Re: menu item msgbox
myArray(mx,1) is simply a string, not a form. You have to create an existing form with that string's name, then show it.
Code:
Private Sub MenuItem_Click(Index As Integer)
Dim f As Form
Set f = Forms.Load(myArr(Index, 1))
f.Show
End Sub
-
Mar 8th, 2010, 11:14 PM
#16
Thread Starter
Hyperactive Member
Re: menu item msgbox
thanks, last, how to draw MFT_SEPARATOR ? please!
MFT_SEPARATOR
myArr(0, 0) = "click a"
myArr(0, 1) = "msgbox a"
myArr(1, 0) = "MFT_SEPARATOR"
myArr(1, 1) = "MFT_SEPARATOR"
myArr(2, 0) = "click c"
myArr(2, 1) = "msgbox c"
menu items:
click a
----------------------''MFT_SEPARATOR
click c
EDIT: I found , just only = "-" , can work! but why "-" ...?
Last edited by rpool; Mar 9th, 2010 at 12:51 AM.
-
Mar 9th, 2010, 01:46 AM
#17
Re: menu item msgbox
 Originally Posted by rpool
EDIT: I found , just only = "-" , can work! but why "-" ...?
That is what they (MS) decided to use. 
Open the menu editor and press "F1" key for help, (if you have MSDN/Help installed)
help says... If you want to create a separator bar in your menu, type a single hyphen (-) in the Caption box.
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
|