Results 1 to 6 of 6

Thread: [RESOLVED] place text into textbox array from menu

  1. #1

    Thread Starter
    Addicted Member scottlafoy's Avatar
    Join Date
    Feb 2009
    Location
    Calgary Alberta, Canada
    Posts
    148

    Resolved [RESOLVED] place text into textbox array from menu

    Hi, I have a textbox array called lanastart, I also have a right click menu that brings up times from 9:00am to 10:00pm. My question is how do I get that time into the textbox that I right clicked on and selected the time from. I think my biggest problem is that the text box is in an array 0 to 27.
    this is the code for the right click menu (Thanks to MartinLiss)
    Code:
    Private Sub lanastart_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbRightButton Then
            lanastart(Index).Enabled = False
            lanastart(Index).Enabled = True
            PopupMenu timemenu
            lanastart(Index).Text = timemnu
        End If
    End Sub
    Thank you
    C:\DOS
    C:\DOS\RUN
    RUN\DOS\RUN

  2. #2
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    Re: place text into textbox array from menu

    Why dont you use a combobox for this purpose? Thats seems like ideal, and easy to do.

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

    Re: place text into textbox array from menu

    If I understand you correctly....
    Code:
    Private Sub lanastart_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbRightButton Then
            lanastart(Index).Enabled = False
            lanastart(Index).Enabled = True
            timemenu.Tag = Index
            PopupMenu timemenu
            timemenu.Tag = ""
        End If
    End Sub
    ' then in your submenus click events (the submenus on timemenu)
    ' I have no idea what your submenu names are, so I will guess mnuHours
    Private Sub mnuHours_Click(Index As Integer)
         If timemenu.Tag <> "" Then
             lanastart(Val(timemenu.Tag)).Text = mnuHours(Index).Caption
         End If
    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}

  4. #4

    Thread Starter
    Addicted Member scottlafoy's Avatar
    Join Date
    Feb 2009
    Location
    Calgary Alberta, Canada
    Posts
    148

    Re: place text into textbox array from menu

    Thanks for the thought Jim Davis, I had originaly started this project with comboboxes but soon decided the textboxes looked better, I have over 352 textboxes on one page in 12 different arrays.

    Thank you LaVolpe, this works well. Is there a way I can alter it to include another array without adding another menu?

    like
    from this
    Code:
    If timemenu.Tag <> "" Then
             lanastart(Val(timemenu.Tag)).Text = tenCaption
         End If
    to this
    Code:
    If timemenu.Tag <> "" Then
             **the place that was right clicked**(Val(timemenu.Tag)).Text = ten.Caption
         End If
    Thank you for your time,
    C:\DOS
    C:\DOS\RUN
    RUN\DOS\RUN

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

    Re: place text into textbox array from menu

    Think I get it. You have other textbox arrays besides lanastart? Then maybe...
    Code:
    Private Sub lanastart_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbRightButton Then
            lanastart(Index).Enabled = False
            lanastart(Index).Enabled = True
            timemenu.Tag = "lanastart" & vbTab &  Index ' << changed
            PopupMenu timemenu
            timemenu.Tag = ""
        End If
    End Sub
    
    ' then to apply the caption, using the same menus
    If timemenu.Tag <> "" Then
         Dim tabPos As Integer, ctrlName As String, ctrlIndex As Integer
         tabPos = InStr(timemenu.Tag, vbTab)
         If tabPos Then
              ctrlName = Left$(timemenu.Tag, tabPos-1)
              ctrlIndex = Mid$(timemenu.Tag, tabPos+1)
              Me.Controls(ctrlName)(ctrlIndex).Text = tenCaption
         End If
    End If
    Edited: After some thought, this is a bit simpler and less code overall
    Code:
    ' in your declarations section add this
    Dim TextBoxForMenus As VB.TextBox
    
    Private Sub lanastart_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Button = vbRightButton Then
            lanastart(Index).Enabled = False
            lanastart(Index).Enabled = True
            Set TextBoxForMenus = lanastart(Index)
            PopupMenu timemenu
            Set TextBoxForMenus = Nothing
        End If
    End Sub
    
    ' then to apply the caption, using the same menus
    If Not TextBoxForMenus Is Nothing Then TextBoxForMenus.Text = tenCaption
    Last edited by LaVolpe; Feb 27th, 2009 at 07:34 PM.
    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}

  6. #6

    Thread Starter
    Addicted Member scottlafoy's Avatar
    Join Date
    Feb 2009
    Location
    Calgary Alberta, Canada
    Posts
    148

    Re: place text into textbox array from menu

    Thank you LaVolpe, that is exactly what I was trying to do.
    C:\DOS
    C:\DOS\RUN
    RUN\DOS\RUN

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