• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 830
  • Last Modified:

Reading arabic text from file system object

I am trying to grab all the arabic text from a MSWord document.  I'm using the readall fxn from the FileSystemObject.  The moment I bring it over into VB and place it in a text box, I receive just one "?" character in the text box.  I tried using the
strconv("string",vbunicode) fxn but didn't seem to work.  Any help would be appreciated.  Here is the code that I'm using:

    Dim strText As String
    Dim fso As New FileSystemObject
   
    'Create File System Object
    Set fs = CreateObject("Scripting.FileSystemObject")
       
    'About to read file
    Set ts = fs.OpenTextFile(strFileName, ForReading,   TristateTrue)
    strText = StrConv(ts.ReadAll, vbUnicode)
    txtTest.Text = strText
   
    'MsgBox (strText)

    ts.Close

using VB 6.0
MS Word 2000
Windows 2000
0
cmachovina
Asked:
cmachovina
  • 4
  • 3
1 Solution
 
dokcCommented:
You should not use word document because it has a special format, but if you have text saved as Unicode text file, you can show this text properly in textbox. For this you need:
one Unicode text file in the same directory where your VB Project is called "test.txt" with some arabic characters.
one TextBox (but you need to change font to arial or some other Unicode font and set script property to Arabic)

Option Explicit

Private Sub Form_Load()
    Dim strText As String
    Dim fso, fs As Object
    Const ForReading = 1, ForWriting = 2, ForAppending = 3

    'Create File System Object
    Set fso = CreateObject("Scripting.FileSystemObject")
           
    ' third parameter is for file creation,
    ' forth is TristateTrue for Unicode
    Set fs = fso.OpenTextFile("test.txt", ForReading, False, -1)
    strText = fs.ReadAll
 
    Text1.Text = strText

    fs.Close
End Sub

I did not try with Arabic but with Central European and Cyrillic works fine.

Kind regards.
0
 
cmachovinaAuthor Commented:
I tried what you said.  Put all text in a *.txt file and converted it to arial font.  Not sure what you mean by setting the script property to Arabic...of the text box?  If so, how...no "script" property.

When I made the changes, it no longer puts one single "?" character in the text box.  It replaced all characters with "?" character which is a good thing. It is recognizing all characters in text file, just not the correct ones.  As you can see, I tried using the strconv(string,vbunicode) fxn but that only placed about 10 junk characters in the text box.  Thanks for the help.

Private Sub Command2_Click()

    'Create File System Object
    Set fs = CreateObject("Scripting.FileSystemObject")
   
    'About to read file
    Set ts = fs.OpenTextFile(strFileName, ForReading, False, -1)
    strText = ts.ReadAll
    'strText = StrConv(strText, vbUnicode)
    txtTest.Text = strText
   
    'MsgBox (strText)

    ts.Close

End Sub
0
 
dokcCommented:
You do not need to convert to Unicode because VB internally works with Unicode strings. When you read from file string will be automatically converted to Unicode.
And now proper letters:
When you add TextBox in Form, default font is MS Sans Serif. Go to properties for TextBox and change font to Arial for example. When you open Font dialog box you will see font type in the down right part of dialog box. That is Western by default. Just change this to Arabic (this is a reason why you have garbage instead of proper letters)
You should also change TextBox property RightToLeft to true, I think.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
cmachovinaAuthor Commented:
Still having the same problem.  All characters have been replaced with "?".  I tried changing the regional setting to arabic as well and that didn't work...not quite sure what is going on.  I tried using a document in english just to make sure it was reading it and it didn't have a problem.  Any idea's would be appreciated.  TIA
0
 
dokcCommented:
Then try using Microsoft Forms 2.0 instead. For this you need to have MS Office installed on your computer and on any computer where your program will run.
0
 
cmachovinaAuthor Commented:
Using MS Forms 2.0 worked...woo hoo!!  It is interesting though...when I look at the value of the variable before it places the text in the text box it displays all "?" marks.  It then places the variable in the MS Forms 2.0 text box and displays arabic text.  Thanks for the help.  Owe you a beer.
0
 
dokcCommented:
:-)
After job is finished, there is nothing better then good beer.
One more remark:
this control is not redistributable and you need to check legal terms at:
http://support.microsoft.com/default.aspx?scid=kb%3ben-us%3b224305

Kind regards.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now