|
-
Mar 19th, 2008, 04:50 AM
#1
Thread Starter
Lively Member
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
-
Mar 19th, 2008, 05:40 AM
#2
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
-
Mar 19th, 2008, 06:04 AM
#3
Thread Starter
Lively Member
Re: Problem with FileSystemObject
so how code works with tStream.Read. how can i fix this with tStream.Readall?
-
Mar 19th, 2008, 06:08 AM
#4
Re: Problem with FileSystemObject
 Originally Posted by xor83
my file sometimes contains special chracters
What kind of special charcters?
Unicode?
-
Mar 19th, 2008, 06:34 AM
#5
Thread Starter
Lively Member
Re: Problem with FileSystemObject
not exactly special characters they look like junk values can't even paste on forum
-
Mar 19th, 2008, 06:42 AM
#6
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
-
Mar 19th, 2008, 06:44 AM
#7
Member
Re: Problem with FileSystemObject
Code:
Set tStream = objFile.OpenTextFile(App.Path & "\file.ini", ForReading)
You need to put a \ after App.Path.
-
Mar 19th, 2008, 07:27 AM
#8
Re: Problem with FileSystemObject
 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.
-
Mar 25th, 2008, 04:43 AM
#9
Thread Starter
Lively Member
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
-
Mar 25th, 2008, 04:52 AM
#10
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
-
Mar 25th, 2008, 07:38 AM
#11
Re: Problem with FileSystemObject
 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.
-
Mar 27th, 2008, 01:59 AM
#12
Thread Starter
Lively Member
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
-
Mar 27th, 2008, 02:40 PM
#13
Re: Problem with FileSystemObject
 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.
-
Mar 28th, 2008, 04:23 AM
#14
Thread Starter
Lively Member
Re: Problem with FileSystemObject
yes i am using WritePrivateProfileString... what is this ?
-
Mar 28th, 2008, 07:36 AM
#15
Re: Problem with FileSystemObject
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|