PDA

View Full Version : International Phonetic Alphabet Macro



momiage
12-21-2005, 05:58 PM
I was looking for some insight for a project I am working on. I use the International Phonetic Alphabet(IPA) to do phonetic transcription for some of my classes. The work is tedious (insert, symbol, choose the character...) and I wanted to automate it. This is what I want to do.

1. Create a userform that has the list of symbols as seperate buttons. When the user clicks on these buttons it will place the appropriate symbol in the text box. When the user is finished entering in the symbols, they can hit another button to insert it where the cursor is currently set.
2. The macro will also have to check to make sure that the arial unicode MS font is installed.

Problems I am having so far:

I can't get the symbols (IPA characters) to appear as the text on the buttons in the userform.
I am not entirely sure how to send the textbox information to the word document. Document.write?

Many thanks in advance for any help that anyone can give. I have done a good amount of macro writing for excel, but this will be the first for word.

Momiage

Killian
12-23-2005, 05:53 AM
Hi there Momiage, and welcome to VBAX :hi:

It sounds like an interesting project. I have a couple of things for you to try out - hopefully they will help you along.

First, here's the function I currently use to check for fonts, with a calling macroSub Macro1()

If CheckForFont("Arial") Then
MsgBox "Arial found"
Else
MsgBox "Arial not found"
End If

End Sub

'############################################
'function to test if a named font is available
Function CheckForFont(strFontName) As Boolean

'create a StdFont to assign the font names to
Dim myfont As New StdFont
'if strFontName is not an installed font, the assignment fails
myfont.Name = strFontName
'check if the assignment has failed
If myfont.Name <> strFontName Then
CheckForFont = False
Else
CheckForFont = True
End If
End Function
'############################################Next, getting the buttons to show the character: I assume you have a list of the Unicode decimal values of the characters you want to use... (if not, I googled and found this (http://www.phon.ucl.ac.uk/home/sampa/index.html))
Because you are looking to return a Unicode character, you will need to use ChrW() - note: this is unlikely to work on Mac.
So, as an example:
To show a reverse epsilon. The decimal unicode value is 604, so on a button named CommandButton1CommandButton1.Caption = ChrW(604)

Finally, getting it into Word:
The cursor position is defined in Word using the Selection object. It returns a range, so you can set it's text property to equal the text from the userform textboxSelection.Text = TextBox1.Text

momiage
12-24-2005, 06:10 AM
Killian-

Thanks for your reply. A quick question before I try testing all of this this weekend. When the user clicks a button to insert a character, would I also use the ChrW function to insert the character in to the text box?

Many Thanks,

Momiage

Killian
12-24-2005, 07:20 PM
... When the user clicks a button to insert a character, would I also use the ChrW function to insert the character in to the text box?

Yes, you would.
Or you can use the button caption, since it's already there, i.e.
TextBox.Text = TextBox1.Text & CommandButton1.Caption

momiage
01-02-2006, 07:39 AM
Back again with an update.

I got the characters to appear on the button captions. (good)
I can send the textbox text to the document (good)

But I have run in to a new problem. After I send the text to the document, I get just a highlighted bar in the document. I have to close the userform for it to appear.

Any suggestion on how to work around this?

fumei
01-02-2006, 09:03 AM
But I have run in to a new problem. After I send the text to the document, I get just a highlighted bar in the document. I have to close the userform for it to appear.
Could you please describe what you actually want to have happen? Why is your userform NOT closed? Are you doing multiple entries? If so, how are you moving the location for the insertion?

momiage
01-02-2006, 09:49 AM
The user activates the macro, which brings up the user form.
Then they can click the buttons to assemble the phonetic characters in the text box.
Next they click the button to send it to the word document
After that the cursor should be moved one to the right
And the textbox text should be cleared.
The userform should stay open to allow for mulitple entries, and can be closed by the user at anytime.

I hope this helps clarify :)

Killian
01-02-2006, 10:40 AM
So there are a couple of things to add to the click event of the button after the characters have been sent to the Word doc:
To move the cursor to the end of the selection, you can useSelection.MoveRight Unit:=wdCharacter, Count:=1
Then to clear the textbox:txtChars.Text = ""(where txtChars is the name of the textbox)

In terms of managing the user interface, there are a couple of options:
It sounds like this is something you want frequently available but a userform does tend to get in the way. I would suggest setting the form's ShowModal property to False (only available in versions 2000+), loading it at document/template open and having a toolbar button (with associated shortcut key) that Shows/Hides it.

Another option that seems suitable would be to have all the functionality built into a toolbar that can be shown/docked as required.

Norie
01-02-2006, 11:26 AM
1. Create a userform that has the list of symbols as seperate buttons. When the user clicks on these buttons it will place the appropriate symbol in the text box. When the user is finished entering in the symbols, they can hit another button to insert it where the cursor is currently set.


Rather than having buttons why not use a listbox or combobox?

momiage
01-02-2006, 01:48 PM
Killian,

I had the exact same code typed in this morning and it didn't work. Now it does...I am not asking questions...it works and thats all I care about.

The initial test phase is complete, and I thank you all for your input. I am off to work on the complete version to see what I can do.

One thought for everyone to ponder...I want to be able to streamline my code, and I am really horrible at writing functions. I believe that I can capture the button input and then call a function in order to process it in to the text box. By the time I am finished I may have 50 or more buttons for consonants, vowels, and diacritic marks, and would like to write one function instead of repeating code over and over again.

You have helped me a great deal, and I cannot thank you enough for your time and your guidance.

Momiage

momiage
01-02-2006, 01:50 PM
Rather than having buttons why not use a listbox or combobox?

In my opinion it would work better if the user can see the characters on seperate buttons. The people who will be using this will be new to IPA, and being there once myself, I prefer having it all in front of me.

Norie
01-02-2006, 02:14 PM
But surely with buttons you would require code for each button?

With a listbox you could display every value, let the user select one, press a command button and add the value to a textbox.

As I don't know to much about IPA I couldn't quite say if this approach would work but it's what I would do rather than having a whole load of buttons.

Killian
01-03-2006, 05:00 AM
There is a technique for dealing with this situation (where the same code needs to be run for a large number of form controls). Basically, it is achieved by creating a class that has your control type declared "Public WithEvents" - you then include the event code required.
Then on the form initialize code, each of the controls is set as a new instance of that class and added to a collection. Now, you have a collection of controls on the form that follow the event procedures defined in the class.

I've attached an example with some IPA info I googled for which may or may not be correct - I wouldn't know - but hopefully it illustrates the point. I've made a mousemove event to show info for each button and a mouseup to add the char to the textbox.

I don't want to keep banging on about doing this in a toolbar, but another advantage of this would be that the same routine can be called for each button, using the CommandBars.ActionControl property to determine which button/character to use.

Norie
01-03-2006, 11:50 AM
Killian

Nice code.:)

I'm a bit of a novice with using Class modules and was wondering why you use the MouseUp event rather than Click for the command buttons.

MOS MASTER
01-03-2006, 04:56 PM
Hi K, :hi:

This looks very nice! Very solid coding! :clap:

A late best wishes to you buddy, and Norie and Momiage too.

fumei
01-03-2006, 10:06 PM
My compliments as well! Nice.

Killian
01-04-2006, 03:11 AM
Thnx guys, and a happy new year to you all :beerchug:

re: use of the MouseUp event vs. Click...
no reason other than habit. For some reason, in some IDE/language I can't recall, I've dealt with lots of mouse events seperately and it's stuck. In this case its not neccesary and Click would be better - MouseUp is handy when you need the button values and the fact that it happens before Click can sometimes be useful.