|
-
Nov 21st, 2000, 06:42 AM
#1
Thread Starter
New Member
I want to write info to .dat files but i can't write more then 1 line while i want to write something like this:
Lokaal 251
10.42.251.1
10.42.251.2
10.42.251.3
10.42.251.4
And i want to read it line by line (just like .ini)
how do i do this ???
-
Nov 21st, 2000, 06:59 AM
#2
I will be told otherwise here (I'm sure there's a proper way someone will point out) but I like to cheat.
1) Set the .dat files attributes to normal :
Code:
SetAttr "C:\file.dat", VBNormal
2) Rename the file to .ini
Code:
NAME "C:\file.dat" as "C:\file.ini"
3) Carry out the ammendment as normal
4) Change it back after.
This will work, watch the number of other posts to critisise this & show you a proper way though, come on where are they ?
-
Nov 21st, 2000, 08:25 AM
#3
Read the file:
Code:
'Read File
Dim iFileNummer As Integer
Dim sTemp As String
iFileNummer = FreeFile
Open "C:\Lokaal" For Input As #iFileNummer
Do Until EOF(iFileNummer)
Line Input #iFileNummer, sTemp
MsgBox sTemp 'Do some stuff with the contents of the line
Loop
Close #iFileNummer
'End read file
Write to the file
Code:
'Write File
Dim iFileNummer As Integer
Dim sTemp As String
iFileNummer = FreeFile
'Output erases the current contents of the file
'Use append if you want to add contents instead of creating a new file
Open "C:\Lokaal" For Output As #iFileNummer
Print #iFileNummer, "Line 1"
Print #iFileNummer, "Line 2"
Print #iFileNummer, "Line 3"
Print #iFileNummer, "Line 4"
Close #iFileNummer
-
Nov 21st, 2000, 08:33 AM
#4
Addicted Member
well the easier way is to use the filesystemobject with the text stream object. it would look like this
Code:
dim fsoSystem as New FileSystemObject
dim tsmFile as TextStream
dim strText as String
set tsmFile = fsoSystem.OpenTextFile("c:\testfile.dat", ForAppending)
strText = tsmFile.ReadLine
tsmFile.WriteLine(strText)
there are other methods the textstream object has like,
readall,skipline,write and others.
it makes writing and reading files very easy and clean.
you don't need to worry about changing the filename and forgetting to change it back or changing the file attributes
what alex shows you isn't cheating, its sloppy code that just has potential to cause yourself problems in the future
no offense alex...
just use the feature vb gives you.. that why it one of the most widely used programming languages....
and if your wondering what to reference to get the filesystemobject and the textstream object.
go into your refrences dialog and add
Microsoft Scripting Runtime (scrrun.dll)
[Edited by ender_pete on 11-21-2000 at 08:37 AM]
 ender_pete 
C#,VS.NET Ent Arch, vb6 ee sp5,html,vbscript,jscript,
xml,dhtml,delphi,c++,vc++,java,cgi,php, python, ada(so ancient) ,adasage(also ancient) and others i can't remember.....
-
Nov 21st, 2000, 08:37 AM
#5
None taken, I have made a note of that for me to use in future too.
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
|