VERSION 5.00
Object = "{0D452EE1-E08F-101A-852E-02608C4D0BB4}#2.0#0"; "FM20.DLL"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form frmInpage 
   Caption         =   "Form1"
   ClientHeight    =   3195
   ClientLeft      =   165
   ClientTop       =   735
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   10830
   ScaleWidth      =   15240
   StartUpPosition =   3  'Windows Default
   Begin MSComDlg.CommonDialog oDlg 
      Left            =   480
      Top             =   5640
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin MSForms.TextBox txtDoc 
      Height          =   4935
      Left            =   1080
      TabIndex        =   0
      Top             =   480
      Width           =   6735
      VariousPropertyBits=   -1400879077
      Size            =   "11880;8705"
      FontName        =   "Naqsh"
      FontHeight      =   360
      FontCharSet     =   0
      FontPitchAndFamily=   2
      ParagraphAlign  =   2
   End
   Begin VB.Menu mnuFile 
      Caption         =   "&File"
      Begin VB.Menu mnuNew 
         Caption         =   "&New..."
      End
      Begin VB.Menu mnuSave 
         Caption         =   "&Save..."
      End
      Begin VB.Menu mnuExit 
         Caption         =   "E&xit"
      End
   End
End
Attribute VB_Name = "frmInpage"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Form_Load()
Dim obj As New CInpage
Dim sText As String


End Sub


Private Sub mnuNew_Click()

Dim sText As String
Dim sFileType As String
Dim oInpage As New CInpage

oDlg.Filter = "Unicode Text(*.txt)|*.txt"
oDlg.FilterIndex = 0
oDlg.ShowOpen

If Trim(oDlg.FileName) = "" Then Exit Sub 'Or oDlg.CancelError = True Then Exit Sub

sFileType = LCase(Mid(oDlg.FileName, Len(oDlg.FileName) - 3))

If sFileType <> ".txt" Then 'And sFileType <> ".utx" Then
    MsgBox "Cannot Open the file of this format"
    Exit Sub
End If


Open oDlg.FileName For Binary As #1
'Do Until EOF(1)
'    Line Input #1, sTextLine
'    sText = sText & sTextLine
'Loop
sText = Input(LOF(1), 1)
Close #1



If sFileType = ".txt" Then
    txtDoc.Text = oInpage.ConvertUnicode(sText)
End If


End Sub

Private Sub mnuSave_Click()
Dim iIndex As Integer
Dim iLength As Integer
Dim sHTMLtext As String
Dim iChar As Integer
Dim sUnicodeText As String

oDlg.Filter = "HTML File (*.htm)|*.htm; Text File(*.txt)|*.txt"
oDlg.FilterIndex = 0
oDlg.DefaultExt = ".htm"
oDlg.ShowSave

iLength = Len(txtDoc.Text)
sUnicodeText = txtDoc.Text

If Mid(oDlg.FileName, Len(oDlg.FileName) - 3) = ".txt" Then
        Open oDlg.FileName For Output As #1
        Print #1, sUnicodeText
        Close #1
ElseIf Mid(oDlg.FileName, Len(oDlg.FileName) - 3) = ".htm" Then
         sHTMLtext = sHTMLtext & "<html>" & vbNewLine
         sHTMLtext = sHTMLtext & "<head>" & vbNewLine
         sHTMLtext = sHTMLtext & "<meta http-equiv=Content-Type content=text/html; charset=utf-8>" & vbNewLine
         sHTMLtext = sHTMLtext & "</head>" & vbNewLine
         sHTMLtext = sHTMLtext & "<body dir=rtl lang=ur>" & vbNewLine
         sHTMLtext = sHTMLtext & "<font face=" & Chr(34) & "Arabic TypeSetting" & Chr(34) & "size=" & Chr(34) & "12" & Chr(34) & ">"
            
         For iIndex = 1 To iLength
            iChar = AscW(Mid(sUnicodeText, iIndex, 1))
            If iChar = 10 Or iChar = 13 Then
                sHTMLtext = sHTMLtext & "<BR>"
                iIndex = iIndex + 1
            Else
                 If iChar > 255 Then
                    sHTMLtext = sHTMLtext & "&#" & iChar & ";"
                Else
                    sHTMLtext = sHTMLtext & Chr(iChar)
                End If
            End If
          Next
          
          sHTMLtext = sHTMLtext & "</font>" & vbNewLine
          sHTMLtext = sHTMLtext & "</body>" & vbNewLine
          sHTMLtext = sHTMLtext & "</html>" & vbNewLine
           
           Open oDlg.FileName For Output As #1
           Print #1, sHTMLtext
           Close #1
        
End If
End Sub
