?
Solved

Reading arabic text from file system object

Posted on 2003-02-24
7
Medium Priority
?
768 Views
Last Modified: 2007-12-19
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
Comment
Question by:cmachovina
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 

Expert Comment

by:dokc
ID: 8010284
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
 

Author Comment

by:cmachovina
ID: 8010882
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
 

Expert Comment

by:dokc
ID: 8011300
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
Industry Leaders: 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!

 

Author Comment

by:cmachovina
ID: 8011748
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
 

Accepted Solution

by:
dokc earned 200 total points
ID: 8012251
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
 

Author Comment

by:cmachovina
ID: 8017107
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
 

Expert Comment

by:dokc
ID: 8018422
:-)
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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month8 days, 8 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question