Addressing Menu Items

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bob Kochem

    Addressing Menu Items

    [I apologize if this is an incredibly newbie question ...]

    I am looking for a way via code to access all the menu itmes on a given
    form. I am looking for something like the Forms or Controls collections, but
    for menu items. Is there such a thing or method? I would prefer to avoid
    using the Win API but will do so if that's the only way available.

    This is for a language-translation (of an existing program) where I wish to
    change (English to Spanish initially) the Descriptions for all the menu
    items.

    Thanks in advance

    Bob K.


  • Kiteman - Canada

    #2
    Re: Addressing Menu Items

    I have a few multilingual programs (9 languages and counting...) and use the
    following technique:

    item.Caption = text

    Under the Tools >>> Menu Editor, just give a name to each menu item.

    You can then change the caption of the item using:

    FileHeader.Capt ion = phrase$(97)
    MenuExit.Captio n = phrase$(101)

    I use an external ANSI text file for each language and just load each line
    into a preset phrase when the language is changed on the fly.

    Hope this gets you going.

    I still have not found a way to support UNICODE characters in the menu
    items, but spanish only requires the ANSI character set so you should be
    fine.

    Regards,
    Tom

    "Bob Kochem" <info@minutem an-systems.com> wrote in message
    news:JKfyf.788$ SD3.741@trndny0 7...[color=blue]
    > [I apologize if this is an incredibly newbie question ...]
    >
    > I am looking for a way via code to access all the menu itmes on a given
    > form. I am looking for something like the Forms or Controls collections,
    > but for menu items. Is there such a thing or method? I would prefer to
    > avoid using the Win API but will do so if that's the only way available.
    >
    > This is for a language-translation (of an existing program) where I wish
    > to change (English to Spanish initially) the Descriptions for all the
    > menu items.
    >
    > Thanks in advance
    > Bob K.[/color]


    Comment

    • Jay Taplin

      #3
      Re: Addressing Menu Items

      You can do this with the controls collection of the form.

      The following code loops through all the controls on the form, checking for
      the type of the control. If it comes back as "Menu", then it is a menu
      control/object. In other words, if the code makes it to the Debug.Print
      line, then you have found a menu item. Good luck!

      Private Sub Command1_Click( )
      Dim ctl As VB.Control

      For Each ctl In Me.Controls
      If StrComp(TypeNam e(ctl), "Menu", vbTextCompare) = 0 Then
      'Found a menu item
      Debug.Print ctl.Name
      End If
      Next

      Set ctl = Nothing
      End Sub

      "Bob Kochem" <info@minutem an-systems.com> wrote in message
      news:JKfyf.788$ SD3.741@trndny0 7...[color=blue]
      > [I apologize if this is an incredibly newbie question ...]
      >
      > I am looking for a way via code to access all the menu itmes on a given
      > form. I am looking for something like the Forms or Controls collections,
      > but for menu items. Is there such a thing or method? I would prefer to
      > avoid using the Win API but will do so if that's the only way available.
      >
      > This is for a language-translation (of an existing program) where I wish
      > to change (English to Spanish initially) the Descriptions for all the
      > menu items.
      >
      > Thanks in advance
      >
      > Bob K.
      >[/color]


      Comment

      • Rick Rothstein [MVP - Visual Basic]

        #4
        Re: Addressing Menu Items

        > Private Sub Command1_Click( )[color=blue]
        > Dim ctl As VB.Control
        >
        > For Each ctl In Me.Controls
        > If StrComp(TypeNam e(ctl), "Menu", vbTextCompare) = 0 Then[/color]

        I would use the following If-Then statement instead of the above...

        If TypeOf ctl Is Menu Then

        Rick



        [color=blue]
        > 'Found a menu item
        > Debug.Print ctl.Name
        > End If
        > Next
        >
        > Set ctl = Nothing
        > End Sub[/color]


        Comment

        • Bob Kochem

          #5
          Re: Addressing Menu Items

          Thanks to all who have replied here.

          I think this gets me off and running.

          I am assuming I can use a similar approach to rename all labels and other
          named items on forms.

          Can anyone point at a good tutorial on making programs support multiple
          languages? I would like to avoid re-inventing the wheel if possible.

          One more thing I am wrestling with is all the message boxes that are posted
          in the program. The program's been around quite a while and now makes use of
          the MsgBox in a couple hundred places. I am thinking of creating a "meta"
          message box function, something like TransMsgBox, doing a global replace of
          "MsgBox" with "TransMsgBo x" and then having the TransMsgBox function do the
          translation (somehow) for every set of arguments passed to it.

          Thanks,

          Bob


          "Kiteman - Canada" <-delete-kiteman@shaw.ca > wrote in message
          news:y_gyf.3434 36$ki.139988@pd 7tw2no...[color=blue]
          >I have a few multilingual programs (9 languages and counting...) and use
          >the following technique:
          >
          > item.Caption = text
          >
          > Under the Tools >>> Menu Editor, just give a name to each menu item.
          >
          > You can then change the caption of the item using:
          >
          > FileHeader.Capt ion = phrase$(97)
          > MenuExit.Captio n = phrase$(101)
          >
          > I use an external ANSI text file for each language and just load each line
          > into a preset phrase when the language is changed on the fly.
          >
          > Hope this gets you going.
          >
          > I still have not found a way to support UNICODE characters in the menu
          > items, but spanish only requires the ANSI character set so you should be
          > fine.
          >
          > Regards,
          > Tom
          >
          > "Bob Kochem" <info@minutem an-systems.com> wrote in message
          > news:JKfyf.788$ SD3.741@trndny0 7...[color=green]
          >> [I apologize if this is an incredibly newbie question ...]
          >>
          >> I am looking for a way via code to access all the menu itmes on a given
          >> form. I am looking for something like the Forms or Controls collections,
          >> but for menu items. Is there such a thing or method? I would prefer to
          >> avoid using the Win API but will do so if that's the only way available.
          >>
          >> This is for a language-translation (of an existing program) where I wish
          >> to change (English to Spanish initially) the Descriptions for all the
          >> menu items.
          >>
          >> Thanks in advance
          >> Bob K.[/color]
          >
          >[/color]


          Comment

          • Jay Taplin

            #6
            Re: Addressing Menu Items

            Point! Thanks for the tip...

            Jay Taplin, MCP


            Comment

            • Kiteman - Canada

              #7
              Re: Addressing Menu Items

              Bob, take a look at my NPW9b or NPW-HA kite making programs at:


              On each form I have built a Label that is large enough to contain the
              translation with the greatest number of characters. The caption for the
              label is set as:

              Label1.Caption = Phrase$(xxx)

              where "xxx" is obtained from the left three characters from the line in the
              external language text file.

              I did try using Resource files (websearch for "Resource files for
              Localization")- it worked to some extent for my purposes, but since my
              translations were being done by volunteers around the world, I couldn't let
              multiple people have access to the resource file - it would bound to get
              botched at some point.

              A big advantage to using my external language file is that anyone can
              perform a translation and plop it into the same folder - as long as it
              follows my file naming convention it is automatically recognized the next
              time the program is run and they can use it immediately. The only time
              that I am required to do anything is if the person needs more room to fit
              the extra characters that their verbose language might require. I have
              found that if I allow room for the German language, that pretty much any
              other language will fit well within that space.

              If you require UNICODE support, you will have to use the objects from the MS
              Forms 2.0 library.

              If you know someone who is willing to translate my language files into
              Spanish, I would appreciate it :-)


              Tom

              "Bob Kochem" <info@minutem an-systems.com>
              wrote in message news:b_iyf.447$ Bn4.75@trndny08 ...
              [color=blue]
              >
              > I think this gets me off and running.
              >
              > I am assuming I can use a similar approach to rename all labels and other
              > named items on forms.
              >
              > Can anyone point at a good tutorial on making programs support multiple
              > languages? I would like to avoid re-inventing the wheel if possible.
              >
              > One more thing I am wrestling with is all the message boxes that are
              > posted in the program. The program's been around quite a while and now
              > makes use of the MsgBox in a couple hundred places. I am thinking of
              > creating a "meta" message box function, something like TransMsgBox, doing
              > a global replace of "MsgBox" with "TransMsgBo x" and then having the
              > TransMsgBox function do the translation (somehow) for every set of
              > arguments passed to it.
              >
              > Thanks,
              >
              > Bob[color=green]
              >> Tom
              >>
              >> "Bob Kochem" <info@minutem an-systems.com> wrote in message
              >> news:JKfyf.788$ SD3.741@trndny0 7...[color=darkred]
              >>> [I apologize if this is an incredibly newbie question ...]
              >>>
              >>> I am looking for a way via code to access all the menu itmes on a given
              >>> form. I am looking for something like the Forms or Controls collections,
              >>> but for menu items. Is there such a thing or method? I would prefer to
              >>> avoid using the Win API but will do so if that's the only way available.
              >>>
              >>> This is for a language-translation (of an existing program) where I wish
              >>> to change (English to Spanish initially) the Descriptions for all the
              >>> menu items.
              >>>
              >>> Thanks in advance
              >>> Bob K.[/color][/color][/color]


              Comment

              Working...