sonia sardana -13 Posting Whiz

I m reading the doc file in binary mode,Junk Characters are returning,Now i want to convert these junk characters(BYTE ARRAY) to string....But mine code is not converting...

Private Sub Form_Load()
RaedOtherFile "D:\THIS IS S A TEST SCREENING.doc"
End Sub

Private sub RaedOtherFile(sFileName As String) 
        Dim bytData() As Byte
      Dim strdata as string

       ReDim bytData(1 To FileLen(sFileName)) As Byte
      Open sFileName For Binary Access Read As #1
      Get #1, , bytData()
      Close #1
      strdata =ByteArrayToString(bytData())
        End Sub

Public Function ByteArrayToString(bytArray() As Byte) As String
    Dim sAns As String
    Dim iPos As String
    
    sAns = StrConv(bytArray, vbUnicode)
    iPos = InStr(sAns, Chr(0))
    If iPos > 0 Then sAns = Left(sAns, iPos - 1)
    
    ByteArrayToString = sAns
 
 End Function
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.