PDA

View Full Version : [SOLVED] Controledit bug?



TrippyTom
08-16-2007, 01:02 PM
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).

TrippyTom
08-16-2007, 01:04 PM
um... hehe, wrong image! (don't know how to remove it)

Try this pic instead.

TrippyTom
08-16-2007, 02:38 PM
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.

John Wilson
08-17-2007, 12:20 AM
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

TrippyTom
08-17-2007, 09:03 AM
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)

TrippyTom
08-17-2007, 09:04 AM
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

TrippyTom
08-17-2007, 09:06 AM
bleh, it might be just easier if i attached the file. so here you go. :)

Tommy
08-17-2007, 12:21 PM
Hi TrippyTom, :hi:

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. :banghead:
If you change it to a combobox it works if you select an item from the list. Even then you have to SELECT :bat2: an item you can't scroll down and then select the button. I don't think this is what you are looking for though.

TrippyTom
08-17-2007, 12:28 PM
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.

Tommy
08-17-2007, 12:56 PM
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.

John Wilson
08-17-2007, 11:37 PM
I think this is correct. I misunderstood before and I was using a form where you can set an on change event.