Consulting

Results 1 to 11 of 11

Thread: Controledit bug?

  1. #1
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location

    Controledit bug?

    Hi peeps,

    I made an add-in that is a simple toolbar that has a controledit text box, and 2 icons (attached pic). The problem is, the user has to press ENTER after typing in a value in the textbox for it to "stick". Is there a way to make it remember the input value without pressing enter (after the textbox loses focus, it loses the text too).
    Office 2010, Windows 7
    goal: to learn the most efficient way

  2. #2
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    um... hehe, wrong image! (don't know how to remove it)

    Try this pic instead.
    Office 2010, Windows 7
    goal: to learn the most efficient way

  3. #3
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    I wanted to clarify something:

    ENTER and TAB both work to "solidify" the text. But if you type a value and just press a button, it remembers the previous setting.
    Office 2010, Windows 7
    goal: to learn the most efficient way

  4. #4
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    Hi Tom

    It doesn't do this for me (but of course I'm not using your code!) Post up your code or email it to me

    john AT technologytrish.co.uk
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  5. #5
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    ok, well here's the routine that creates the toolbar:
    Public Sub AddToolBar()
    On Error Resume Next
    Dim I As Integer
    Dim J As Integer
    Dim sToolBar As String
    On Error Resume Next
    sToolBar = Application.CommandBars(YOUR_TOOLBAR_NAME).Name
    If Err.Number <> 0 Then
        Application.CommandBars.Add YOUR_TOOLBAR_NAME, , , True
        ReadSettingIni Application.CommandBars(YOUR_TOOLBAR_NAME) '<- this line
    End If
    Application.CommandBars(YOUR_TOOLBAR_NAME).Visible = True
    I = Application.CommandBars(YOUR_TOOLBAR_NAME).Controls.Count
    For J = I To 1 Step -1
        Application.CommandBars(YOUR_TOOLBAR_NAME).Controls(J).Delete
    Next
    On Error GoTo 0
    If MyButton Is Nothing Then
        Set MyButton = Application.CommandBars(YOUR_TOOLBAR_NAME).Controls.Add(1)
    End If
    With MyButton
        .Caption = "Resize: "
        .Style = msoButtonCaption 'caption only
        .Tag = "height"
        .Width = 50
        .Visible = True
    End With
    If MyButton1 Is Nothing Then
        Set MyButton1 = Application.CommandBars(YOUR_TOOLBAR_NAME).Controls.Add(2) 'ControlEdit (textbox)
    End If
    With MyButton1
        .Width = 50
        .Visible = True
    End With
    If MyButton2 Is Nothing Then
        Set MyButton2 = Application.CommandBars(YOUR_TOOLBAR_NAME).Controls.Add(1)
    End If
    With MyButton2
        .FaceId = 541 'height icon
        .Style = msoButtonIcon 'icon only
        .Tag = "Height"
        .OnAction = "myControlRoutine"
        .TooltipText = "Height"
        .Width = 10
        .Visible = True
    End With
    If MyButton3 Is Nothing Then
        Set MyButton3 = Application.CommandBars(YOUR_TOOLBAR_NAME).Controls.Add(1)
    End If
    With MyButton3
        .Caption = "Width"
        .FaceId = 542 'width icon
        .Style = msoButtonIcon 'icon only
        .Tag = "Width"
        .OnAction = "myControlRoutine"
        .TooltipText = "Width"
        .Width = 10
       .Visible = True
    End With
    End Sub
    and this is the routine that's activated when a button is pressed:

    Sub myControlRoutine()
    Dim mySlide As Long
    Dim shp As Shape
    Dim newWidth As Single
    Dim newHeight As Single
    Dim newShp As ShapeRange
    Dim num As Long
    Dim I As Long
    Dim strVal As Variant
    Dim ctrlEdit As CommandBarControl
    Set ctrlEdit = CommandBars(YOUR_TOOLBAR_NAME).FindControl(Type:=msoControlEdit)
    If Not ctrlEdit Is Nothing Then
        If ctrlEdit.Text <> "" Then
            myVal = ctrlEdit.Text
            strVal = myVal
            If IsNumeric(strVal) Then
                'different action depending on which button was clicked
                Select Case CommandBars.ActionControl.Tag
                    Case "Height"
                        Call changeHeight
                    Case "Width"
                        Call changeWidth
                End Select
                'MsgBox "Do " & CommandBars.ActionControl.Caption & " with value: " & myVal
            Else
                MsgBox "Values must be numeric."
                ctrlEdit.Text = ""
            End If
        Else
            MsgBox "Please enter a value to resize with."
        End If
    End If
    End Sub
    and these are the routines the buttons do:
    Sub changeHeight()
    Dim colTemp As New Collection
    Dim shp As Shape
    Dim I As Long
    With ActiveWindow.Selection
        If .Type = ppSelectionShapes Then
            'add all selected shapes to new collection
            For Each shp In .ShapeRange
                colTemp.Add shp
            Next shp
        End If
    End With
    'resize shapes
    For I = 1 To colTemp.Count
        With ActiveWindow.Selection.ShapeRange
            .LockAspectRatio = msoTrue
            .Height = myVal * 72
        End With
    Next
    End Sub
    
    Sub changeWidth()
    Dim colTemp As New Collection
    Dim shp As Shape
    Dim I As Long
    With ActiveWindow.Selection
        If .Type = ppSelectionShapes Then
            'add all selected shapes to new collection
            For Each shp In .ShapeRange
                colTemp.Add shp
            Next shp
        End If
    End With
    'resize shapes
    For I = 1 To colTemp.Count
        With ActiveWindow.Selection.ShapeRange
            .LockAspectRatio = msoTrue
            .Width = myVal * 72
        End With
    Next
    End Sub
    I presume I don't need to post any other code that's needed for the addin (auto-open, auto-close, etc)
    Last edited by Aussiebear; 04-24-2023 at 01:46 AM. Reason: Adjusted the code tags
    Office 2010, Windows 7
    goal: to learn the most efficient way

  6. #6
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    oh, here's the public variables I setup too:
    Option Explicit
    Public Const YOUR_TOOLBAR_NAME As String = "Quick Resize"
    Public MyButton As CommandBarButton
    Public MyButton1 As CommandBarControl
    Public MyButton2 As CommandBarButton
    Public MyButton3 As CommandBarButton
    Public myVal As Variant
    Last edited by Aussiebear; 04-24-2023 at 01:47 AM. Reason: Adjusted the code tags
    Office 2010, Windows 7
    goal: to learn the most efficient way

  7. #7
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    bleh, it might be just easier if i attached the file. so here you go.
    Office 2010, Windows 7
    goal: to learn the most efficient way

  8. #8
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    Hi TrippyTom,

    From what I am seeing the change event will not fire until the enter key or tab key is pressed and the focus is lost from the control. If you pick a command button before pressing the tab or enter key the control does not set the text property.
    If you change it to a combobox it works if you select an item from the list. Even then you have to SELECT an item you can't scroll down and then select the button. I don't think this is what you are looking for though.

  9. #9
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    Correct.... in my clarification post above, I said it only works if the user presses ENTER or TABs out of the field before using the buttons.

    I was wondering if this is the default behavior of a control edit text box, or if there's a workaround that I can use.

    It's just a minor annoyance, but if I can make it more user-friendly, I would like to.
    Office 2010, Windows 7
    goal: to learn the most efficient way

  10. #10
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    Quote Originally Posted by TrippyTom
    I was wondering if this is the default behavior of a control edit text box, or if there's a workaround that I can use.
    This seems to be the default from what I have gathered. As far as a workaround not one that I have found. The text property is not set until a key is pressed, the change event doesn't even get triggered until an item is selected from a list or tab/enter key is pressed.

  11. #11
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    I think this is correct. I misunderstood before and I was using a form where you can set an on change event.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •