Anybody who knows how to change word or character in kanji to katakana or vice-versa.
I'm using 2 textbox to do this, the first textbox is for katakana and the second textbox is for kanji.
What i wanted to do is, whatever i typed in the kanji textbox it will be converted to its corresponding katakana value in the first textbox or vice-versa.

Is this possible in vb.net or do i need to use third party software / dll / activeX to be able to do this, anyone please give me a good idea how to deal with this problem.

Katakana and Kanji are both IME for Japan

Thanks in advance.


Regards,
Millanskie

>Is this possible in vb.net
Of course. It's not like you're doing anything exceptionally complicated, but it will be tedious. Kanji is symbolic and based on concepts/words while katakana is based on syllables. There's really not an algorithm for breaking kanji down into katakana, so you have to take all of the kanji you want to support and provide a mapping to the katakana translation.

I can help little bit there is one function called
strConv(textbox1.text, VbStrConv.Katakana)

May be this can help you.

> so you have to take all of the kanji you want to support and provide a mapping to the katakana translation.

@Narue

Sorry for the trouble but can you please give me a little sample for this problem of mine, I'm just a noob in vb.net and also im not really familiar with kanji and katakana.

@Alekhan

I had tried the function but it did not work the way i wanted, i always gives me the same character that i typed.

>can you please give me a little sample for this problem of mine
It depends on how you set up the dictionary for conversions. I'd probably go with a SQL database and have something like this:

Private Sub buttonConvert_Click ( ByVal sender As Object, ByVal e As EventArgs ) Handles buttonConvert.Click
    Me.Convert ( Me.textBoxKanji.Text )
End Sub

Private Sub Convert ( ByVal kanjiText As String )
    Dim storedProcedure As String = "kanji_to_katakana"
    Dim reader As SqlDataReader

    Try
        Dim connection As New SqlConnection ( Me.ConnectionString )
        Dim command As New SqlCommand ( storedProcedure, connection )

        command.CommandType = CommandType.StoredProcedure
        command.Parameters.Add ( New SqlParameter ( "@KanjiText", kanjiText ) )

        connection.Open()

        reader = cmd.ExecuteReader ( CommandBehavior.CloseConnection )

        Do While reader.Read
            Me.textBoxKatakana.AppendText ( reader.GetString ( 0 ) )
        Loop

        reader.Close()
    Catch ex As Exception
        ' Clean up and handle errors
        If reader IsNot Nothing AndAlso Not reader.IsClosed Then
            reader.Close()
        End If
    End Try
End Sub

The VB.NET code and stored procedure should be easy. The real work will be building the database of mappings. Alternatively you can just use a text file instead of a relational database.

>im not really familiar with kanji and katakana
You don't have to be. You can just get yourself a Kanji dictionary. They typically include translations to the other kana.

@Narue

Thanks for the help, I really appreciate it.

I will try to work it out, the idea/sample that you gave me.

Thank you very much for the time you spent helping me.

@Narue

I have a textbox and i set the IMEmode property to hiragana so that the keyboard will be on hiragana mode everytime i enter that textbox, now what i want to do is to catch the hiragana i typed before it would be converted to kanji when i press the enter.

it will be easier to convert the hiragana to katakana using strConv(textbox1.text, VbStrConv.Katakana)

Note: I only need to convert names in kanji to be in katakana

Oh boy. It is possible to reconvert either way. However, you need to have a special task bar in use with:-
Japanese-Input style- input mode - Conversion mode-ME pad -tools- caps -kana

You must have the japanese IME installed of course. Then it is possible to write in katakana and reconvert

ワタクシ  
                     watakushi
                     わたくし

The first line is in katakana. The second line is in romaji and the third line is in hiragana.

On the task bar you ahouls see Ainput Mode.  Click on this and select katagana if you wrote in hiragana which is highlighted. Hit enter and a box with choices appears.  Select the appropriate mode and the highlighted characters will convert.
Very slow and time consuming unlerss you write a paragrapg at a time in the same mode.  The tricky bit is avoiding having the kanji appear when you don’t want it.
There must be easier ways but I don’t know what they are.Hope this helps you.
I just tested it in a Word doc.      
                     

@Tokyopete

I am not avoiding kanji to appear, i just want to capture the hiragana before it becomes a kanji, because it will easier for me to convert hiragana to katakana rather than converting kanji to katakana.

The problem is can't get the hiragana on the textbox, i don't know what event should i use just to capture the hiragana while the user is still typing.

I already use some possible events of textbox but nothing i used had been able to work

Okay. Fully understood, BUT to write foreign names in hiragana and then convert is never done. It is pointless. You simply switch to katakana and then write the foreign name using the katakana box, enter and then continue in hiragana. All foreign names and words are written only in katakana anyway. Kanji is never used for foreign words, only Katana. This being written so far using US English. The Japanese written underneath was done using the IME.

わたくしわにほんじんです。わたくしのともたちわ イギリスジン です。 かれのなまえわ ピーター です。
Iam a Japanese person. Myfriend is English. His name is Peter.

I used the Japanese IME to write the above and then switched back to US English to continue this message to you. The way shown above is the correct way to do the conversion. Batch type conversions won't work as there are too ma instructions required.
As I live in Japan and frequently use Kanji, hiragana and katana when writing as does my Japanese wife I might be correct in what I have written.
Back to you to get sorted out.

Hey guys thanks for the help, I already solved my problem, but i have to use a third party software named "InputMan" by GrapeCIty, it do exactly what i want.

Here is the sample code that i used

Imports GrapeCity.Win.Editors 
・・・ 
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
    ' ResultStringイベントが発生するように設定します。 
    GcIme1.SetCausesImeEvent(GcTextBox1, True) 
End Sub 

Private Sub GcIme1_ResultString(ByVal sender As Object, ByVal e As GrapeCity.Win.Editors.ResultStringEventArgs) Handles GcIme1.ResultString 
    ' ふりがなをラベルコントロールに表示します。 
    If e.SourceControl Is GcTextBox1 Then 
        Label1.Text += e.ReadString 
    End If 
End Sub

>can you please give me a little sample for this problem of mine
It depends on how you set up the dictionary for conversions. I'd probably go with a SQL database and have something like this:

Private Sub buttonConvert_Click ( ByVal sender As Object, ByVal e As EventArgs ) Handles buttonConvert.Click
    Me.Convert ( Me.textBoxKanji.Text )
End Sub

Private Sub Convert ( ByVal kanjiText As String )
    Dim storedProcedure As String = "kanji_to_katakana"
    Dim reader As SqlDataReader

    Try
        Dim connection As New SqlConnection ( Me.ConnectionString )
        Dim command As New SqlCommand ( storedProcedure, connection )

        command.CommandType = CommandType.StoredProcedure
        command.Parameters.Add ( New SqlParameter ( "@KanjiText", kanjiText ) )

        connection.Open()

        reader = cmd.ExecuteReader ( CommandBehavior.CloseConnection )

        Do While reader.Read
            Me.textBoxKatakana.AppendText ( reader.GetString ( 0 ) )
        Loop

        reader.Close()
    Catch ex As Exception
        ' Clean up and handle errors
        If reader IsNot Nothing AndAlso Not reader.IsClosed Then
            reader.Close()
        End If
    End Try
End Sub

The VB.NET code and stored procedure should be easy. The real work will be building the database of mappings. Alternatively you can just use a text file instead of a relational database.

>im not really familiar with kanji and katakana
You don't have to be. You can just get yourself a Kanji dictionary. They typically include translations to the other kana.

hai to all
pls help me too to over come the same problem of converting a text in kanji to katakana
actually my project is to be done in vb6 ...
the above written code is used only wen i create a procedure...
but i need a coding eg which directly converts without goin in to DB...
pls help me ...
thank you all in advance

Hey guys thanks for the help, I already solved my problem, but i have to use a third party software named "InputMan" by GrapeCIty, it do exactly what i want.

Here is the sample code that i used

Imports GrapeCity.Win.Editors 
・・・ 
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
    ' ResultStringイベントが発生するように設定します。 
    GcIme1.SetCausesImeEvent(GcTextBox1, True) 
End Sub 

Private Sub GcIme1_ResultString(ByVal sender As Object, ByVal e As GrapeCity.Win.Editors.ResultStringEventArgs) Handles GcIme1.ResultString 
    ' ふりがなをラベルコントロールに表示します。 
    If e.SourceControl Is GcTextBox1 Then 
        Label1.Text += e.ReadString 
    End If 
End Sub

Please teach me how to use InputMan. I need to have this program. Thank you in advance.

This question has already been answered. Start a new discussion instead.