Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting accented symbols in a text box

Status
Not open for further replies.
Oct 5, 1999
105
0
0
GB
I am writing an application that contains (among other things!) names and addresses in text boxes and I would like the user to be able to input accented characters for foreign addresses e.g. Ėûá. I can write a routine to supply the necessary symbol from, say, a menu option, as in Word, but if a user clicks on the menu, how can I tell which text box they were in to insert it?

Also, is there any simple way of testing for alphabetic characters (including accented characters)?


 
Would it work if you would have a drop-down list with all the Ėûá characters for your user to choose from next to the text box?

Have fun.

---- Andy
 
A menu does not take focus away from the ActiveControl ...
 
So, if the current text box is still in focus, how is the best way to get my accented char into it?
I thought I might use SendKeys, but I get an err 70 "Permission Denied".

Alternatively, is there any way to find out which box has focus?
 
Of course! Just remembered I can use Me.ActiveControl

Any better ideas out there?
 
How many special character are we talking about?
If there are not too many, would keyboard shortcuts work?

I have a situation where user wanted to use a bullet in the text box. I set up a command button which sends this character to the text box, set the keyboard shortcut as Alt-B, hide it, and show small message to user: "Alt-B to place a Bullet"

Have fun.

---- Andy
 
Unfortunately, there are over 30 characters, and upper and lower case for each, so too many for shortcuts
 
That's why my first option was a drop-down list with all your special characters.

Have fun.

---- Andy
 
> I can use Me.ActiveControl

Well, quite. That's really what I was getting at.

>Any better ideas out there?

How much better than access to the exact control do you want?
 
You are partly right strongm.
Unfortunately, loading another form to choose a character makes it execute the LostFocus event and then it will execute the GotFocus event after you exit from the menu sub.

It takes a bit of judicious field saving and flag setting/testing and manually calling SetFocus at the right time to get it to work.
I'm not sure how stable my solution is!

Code for menu is:
Code:
Private Sub mnuInsertSymbol_Click()

    If Not TypeOf Me.ActiveControl Is TextBox Then Exit Sub         ' just in case!
    
    gblnInsertActive = True                         ' set flag for control of TextBox events
    Set gtxtInsertTextBox = Me.ActiveControl        ' Save data
    With gtxtInsertTextBox
        glngInsertSelLength = .SelLength
        glngInsertSelStart = .SelStart
        gstrInsertText = .Text
    End With
    frmInsertSymbol.Show vbModal    ' this form will have inserted any chars as required
    gtxtInsertTextBox.SetFocus      ' because system loses it when form loaded
    DoEvents                        ' seems to need this
    gblnInsertActive = False
End Sub

and TextBox events look like:
Code:
Private Sub txtAddress_Change(Index As Integer)
Dim intOldPos As Integer
Dim intNewPos As Integer
Dim strValue As String
Dim strErr As String

    If gblnInsertActive Then Exit Sub

    With txtAddress(Index)
        If mblnCheckChange Then
            sbrStatus.Panels.Item(1).Text = ""
            intOldPos = .SelStart
            intNewPos = intOldPos
            strValue = .Text
            mblnCheckChange = False
            If Len(strValue) > gtypNamesSizes.Address Then
                Beep
                .Text = mstrOldValue
                .SelStart = intOldPos - 1
                sbrStatus.Panels.Item(1).Text = "Max length = " & gtypNamesSizes.Address
            Else
                .Text = strValue
                mstrOldValue = strValue
                .SelStart = intNewPos
            End If
            mblnCheckChange = True
        End If
    End With
End Sub

Private Sub txtAddress_GotFocus(Index As Integer)
Dim blnCheckChange     As Boolean       ' save status

    If gblnInsertActive Then Exit Sub

    mnuInsertSymbol.Enabled = True
    With txtAddress(Index)
        If .Locked Then Exit Sub
        ' select all text
        .SelStart = 0
        .SelLength = 999
        .BackColor = vbYellow
        mstrOldValue = .Text
    End With
End Sub

Private Sub txtAddress_LostFocus(Index As Integer)
    
    If gblnInsertActive Then Exit Sub

    sbrStatus.Panels.Item(1).Text = ""
    With txtAddress(Index)
        .BackColor = vbWindowBackground
    End With
End Sub

 
You didn't say you were loading another form. My commens were based on the fact that you said you were using a menu.
 
But as long as you do what you are doing to capture the ActiveControl before deliberately changing the ActiveControl by loading a new form:

Set gtxtInsertTextBox = Me.ActiveControl

you should be OK. And you shouldn't really need

gtxtInsertTextBox.SetFocus

since VB should handle returning focus appropriately
 
Sorry if I mislead you, but with over 60 characters to insert, menus alone seemed a bit heavy, though still worth considering.

> And you shouldn't really need
> gtxtInsertTextBox.SetFocus

True, but I wanted it to be under my control so I can control SetStart and SelLength, as otherwise VB only executes the SetFocus after my menu routine ends.

Thanks for all your usual good sense.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top