Results 1 to 17 of 17

Thread: [RESOLVED] menu item msgbox

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2009
    Posts
    492

    Resolved [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

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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?

  3. #3
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: menu item msgbox

    Quote Originally Posted by rpool View Post
    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

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2009
    Posts
    492

    Re: menu item msgbox

    your right. would you tell me what case I need ?

  5. #5
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: menu item msgbox

    Quote Originally Posted by rpool View Post
    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,...

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2009
    Posts
    492

    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

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: menu item msgbox

    What line of code caused the error?

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2009
    Posts
    492

    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

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: menu item msgbox

    You need to tell us what happens.

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2009
    Posts
    492

    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!

  11. #11
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: menu item msgbox

    In your code (post #6), remove this line:
    Code:
    Load MenuItem(crt)
    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,...

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2009
    Posts
    492

    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

  13. #13
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

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

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2009
    Posts
    492

    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

  15. #15
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2009
    Posts
    492

    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.

  17. #17
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: menu item msgbox

    Quote Originally Posted by rpool View Post
    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
  •  



Click Here to Expand Forum to Full Width