Link to home
Start Free TrialLog in
Avatar of gorexy
gorexy

asked on

translation question


HI,
  I want to perform a small translation program.  
The program can read the input file in this format:

1.Wo an a i ei ...
2....

and the output will become
1.ab ei i i eI (for example)
2....

That means each unit will be translated into a new string.
The following is what I did so far.

However, I don't know how to separate each unit by space and so I can compare each unit.  

My code now got a problem.  When the input is a and then ai , the code can just replace ai into ai (e.g.) instead of Ai (e.g.) since a -> a.

''''''''''code begin'''''
Private Sub Command1_Click()
Load Form1
Form1.Show
End Sub

Private Sub Command2_Click()
Load Form1
Output = True
Form1.Show
End Sub

Private Sub Command3_Click()
Dim pathandname As String
Dim filesize As String
Dim path As String
Dim mystring As String

If Text1.Text = "" Then
MsgBox "You must first select a file!"
Exit Sub
End If

'If Right(Form1.File1.path, 1) <> "\" Then
'path = Form1.File1.path + "\"
'Else
'path = Form1.File1.path
'End If

'If Text1.Text = Form1.File1.FileName Then
'pathandname = path + Form1.File1.FileName
'Else
'pathandname = Text1.Text
'End If

filenum = FreeFile
Open Text1.Text For Input As filenum
filenum2 = FreeFile
Open Text2.Text For Output As filenum2

Do While Not EOF(filenum)
Line Input #filenum, mystring
Text1.Font.Name = "Ipa-samd uclphonl"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
mystring = ReplaceInString(mystring, "b", "p") '1
mystring = ReplaceInString(mystring, "p", "pH") '2
mystring = ReplaceInString(mystring, "m", "m") '3
mystring = ReplaceInString(mystring, "f", "f") '4
mystring = ReplaceInString(mystring, "d", "t") '5
mystring = ReplaceInString(mystring, "t", "tH") '6
mystring = ReplaceInString(mystring, "n", "n") '7
mystring = ReplaceInString(mystring, "l", "l") '8
mystring = ReplaceInString(mystring, "z", "ts") '9
mystring = ReplaceInString(mystring, "c", "tsH") '10
mystring = ReplaceInString(mystring, "s", "s") '11
mystring = ReplaceInString(mystring, "j", "tC") '12
mystring = ReplaceInString(mystring, "q", "tCH") '13
mystring = ReplaceInString(mystring, "x", "C") '14
mystring = ReplaceInString(mystring, "g", "k") '15
mystring = ReplaceInString(mystring, "k", "kH") '16
mystring = ReplaceInString(mystring, "h", "x") '17
mystring = ReplaceInString(mystring, "zh", "chr$(0167)") '18
mystring = ReplaceInString(mystring, "ch", "chr$(0167)") '19
mystring = ReplaceInString(mystring, "sh", "chr$(0167)") '20
mystring = ReplaceInString(mystring, "r", "r") '21
mystring = ReplaceInString(mystring, "ng", Chr(Asc("n") - 32)) '22
mystring = ReplaceInString(mystring, "a", Chr(Asc("a") - 32)) '23
mystring = ReplaceInString(mystring, "o", "o") '24
mystring = ReplaceInString(mystring, "e", "e") '25
mystring = ReplaceInString(mystring, "i", "i") '26
mystring = ReplaceInString(mystring, "u", "u") '27
mystring = ReplaceInString(mystring, "ul", "y") '28
mystring = ReplaceInString(mystring, "er", "y") '29
mystring = ReplaceInString(mystring, "ai", Chr(Asc("a") - 32) + i + "super") '30
mystring = ReplaceInString(mystring, "ei", Chr(Asc("e") - 32) + i + "super") '31
mystring = ReplaceInString(mystring, "ao", Chr(Asc("a") - 32) + u + "super") '32
mystring = ReplaceInString(mystring, "ai", Chr(Asc("o") - 32) + u + "super") '33
mystring = ReplaceInString(mystring, "an", "<")   '34
mystring = ReplaceInString(mystring, "en", "F<") '35
mystring = ReplaceInString(mystring, "ang", Chr(Asc("a") - 32) + Chr$(212))   '36

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Print #filenum2, mystring
Loop

Close filenum
Close filenum2

End Sub

Function ReplaceInString(orgstring As String, orgchar As String, newchar As String) As String
Dim interarr As Variant
Dim i As Integer

ReplaceInString = ""
interarr = Split(orgstring, orgchar)
For i = 0 To UBound(interarr)
  If i <> 0 Then ReplaceInString = ReplaceInString & newchar
  ReplaceInString = ReplaceInString & interarr(i)
 
Next i
End Function

''''''code end'''''

Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Hi gorexy,

Please check the "Checking Algorithm" in your code to ensure no problem within.

And you can replace the "ReplaceInString" function with "Replace" function if you're using VB6

regards.
Avatar of gorexy
gorexy

ASKER

sorry can you make clear?
My code above has no prolem to run.

and why I need to replace the replaceinstring into replace?

Yes I am using VB6 with SP5
Hi,

> why I need to replace the replaceinstring into replace?
Just a suggestion, bcos you don't need a Sub to comparing the string.

Replace function in VB:

Description

Returns a string in which a specified substring has been replaced with another substring a specified number of times.

Syntax

Replace(expression, find, replacewith[, start[, count[, compare]]])

Avatar of gorexy

ASKER

sorry can you make clear?
My code above has no prolem to run.

and why I need to replace the replaceinstring into replace?

Yes I am using VB6 with SP5
Avatar of gorexy

ASKER

oic...but I am not familiar with the replace function,
Can you show me how can I plug the replace function into my code?
ASKER CERTIFIED SOLUTION
Avatar of rspahitz
rspahitz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi gorexy,

Anyway,

> Can you show me how can I plug the replace function into my code?

Example:

mystring = Replace(mystring, "en", "F<") '35

But

According to your situation, use the Replace function may not be the first choice, make sure your checking algorithm is correct so that no characters is overlapping..

And rsphahitz 's Example which shows the "Select Case" statement is more reasonable.

regards
Hi gorexy,

Anyway,

> Can you show me how can I plug the replace function into my code?

Example:

mystring = Replace(mystring, "en", "F<") '35

But

According to your situation, use the Replace function may not be the first choice, make sure your checking algorithm is correct so that no characters is overlapping..

And rsphahitz 's Example which shows the "Select Case" statement is more reasonable.

regards
Hi gorexy,

Anyway,

> Can you show me how can I plug the replace function into my code?

Example:

mystring = Replace(mystring, "en", "F<") '35

But

According to your situation, use the Replace function may not be the first choice, make sure your checking algorithm is correct so that no characters is overlapping..

And rsphahitz 's Example which shows the "Select Case" statement is more reasonable.

regards
<sorry for multiple postings..>
Avatar of gorexy

ASKER

yup excellent , exactly what I need.
Thanks
(and I learn something new to me too)
Glad to help again!