Results 1 to 15 of 15

Thread: Problem with FileSystemObject

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    120

    Problem with FileSystemObject

    I am using this code to read data from INI file this works almost all the time perfectly but some time it unable to read all the data but return only some part of the file. And if i change tStream.ReadAll to tStream.Read(lenoffile) it works fine. Just wanted to know why readall not working

    my file sometimes contains special chracters


    Code:
    Dim objFile         As FileSystemObject
    Dim strData         As String
    Dim tStream         As TextStream
      
    On Error GoTo ErrHandler
    
       Set objFile = New FileSystemObject
       Set tStream = objFile.OpenTextFile(App.Path & "file.ini", ForReading)
       
       strData = tStream.ReadAll

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Problem with FileSystemObject

    if a file contains ctrl Z ( chr(26) ) it will be seen as end of file marker
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    120

    Re: Problem with FileSystemObject

    so how code works with tStream.Read. how can i fix this with tStream.Readall?

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Problem with FileSystemObject

    Quote Originally Posted by xor83
    my file sometimes contains special chracters
    What kind of special charcters?

    Unicode?

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    120

    Re: Problem with FileSystemObject

    not exactly special characters they look like junk values can't even paste on forum

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Problem with FileSystemObject

    paste into text file then post textfile, even if they are not visible, they will still be there
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7
    Member
    Join Date
    May 2006
    Posts
    32

    Re: Problem with FileSystemObject

    Code:
       Set tStream = objFile.OpenTextFile(App.Path & "\file.ini", ForReading)
    You need to put a \ after App.Path.

  8. #8
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: Problem with FileSystemObject

    Quote Originally Posted by IniX
    Code:
       Set tStream = objFile.OpenTextFile(App.Path & "\file.ini", ForReading)
    You need to put a \ after App.Path.
    I noticed that IniX.

    xor83 why can't you use the normal API calls for reading and writing to an ini file, its going to be a lot simpler?

    GetPrivateProfileString and WritePrivateProfileString.
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    120

    Re: Problem with FileSystemObject

    "App.Path & "\file.ini""

    there is no problem in getting file path... it able to read file and file is not big in size it's just 6KB

  10. #10
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Problem with FileSystemObject

    if you post the file that has the problem someone may be able to tell you what the problem is, as it would appear the fault is in the file
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  11. #11
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: Problem with FileSystemObject

    Quote Originally Posted by xor83
    "App.Path & "\file.ini""

    there is no problem in getting file path... it able to read file and file is not big in size it's just 6KB
    So what problem are you having now?

    Are you using GetPrivateProfileString and WritePrivateProfileString?
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    120

    Re: Problem with FileSystemObject

    I have found that when file have ASCII char 28 and 31 it unable to read the file

    31=unit seperator
    28=File separator

  13. #13
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: Problem with FileSystemObject

    Quote Originally Posted by xor83
    I have found that when file have ASCII char 28 and 31 it unable to read the file
    But are you using GetPrivateProfileString and WritePrivateProfileString? You haven't said yet.
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    120

    Re: Problem with FileSystemObject

    yes i am using WritePrivateProfileString... what is this ?

  15. #15
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: Problem with FileSystemObject

    Quote Originally Posted by xor83
    yes i am using WritePrivateProfileString... what is this ?
    If you don't know what WritePrivateProfileString is then how are you using it?
    Code:
    Public Declare Function WritePrivateProfileString Lib "kernel32" _
    Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, _
    ByVal lpKeyName As Any, ByVal lpString As Any, _
    ByVal lpFileName As String) As Long
    lpApplicationName is the Section name.
    lpKeyName is the Key name.
    lpString is the value being written.
    lpFileName is the ini file name with location.

    e.g.

    Call WritePrivateProfileString("General", "Main Width", CStr(Me.Width), App.Path & "\Your.ini")
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width