Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 22nd, 2007, 08:25 AM
Registered User
 
Join Date: May 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Edit .Dat file


We have a .dat file that contains tabs & spaces as delimiters. We need to edit this file to replace a particular field in a record. One way I thought is to import the file to excel and edit code using VBA. Though I succeeded editing the column with new value, I'm stuck with exporting the excel back to .dat file with preserving the format. Is there a way to edit .dat file directly?


Reply With Quote
  #2 (permalink)  
Old May 22nd, 2007, 08:32 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

You can read a .dat file like you would any other TextFile.

Dim sr as StreamReader
Dim sFile as String
sr = File.OpenText("file.dat")
sFile = sr.ReadToEnd()
sr.Close()

hth.


================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
Reply With Quote
  #3 (permalink)  
Old May 22nd, 2007, 08:43 AM
Friend of Wrox
Points: 3,060, Level: 23
Points: 3,060, Level: 23 Points: 3,060, Level: 23 Points: 3,060, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: , , .
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Use the following to save in txt format (dat)

Sub Save_File()

Application.DisplayAlerts = False

ActiveWorkbook.SaveAs Filename:="c:\test\testfile.dat", FileFormat:=xlTextMSDOS

Application.DisplayAlerts = True

End Sub


http://www.vbadud.blogspot.com
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Importing dat file Earl Hickey Visual Basic 2005 Basics 4 May 25th, 2007 12:11 PM
Help. How to save and retrieve text from .dat file dextergaisie Pro VB 6 1 May 15th, 2007 11:45 AM
Read a .dat file into a struct type cuccu C# 2005 0 December 22nd, 2006 06:21 AM
Connecting to dat file from access or VB shaiss Access VBA 0 December 31st, 2005 02:21 PM
How to open Binary .dat file? bekim VB.NET 2002/2003 Basics 2 June 16th, 2004 09:56 AM



All times are GMT -4. The time now is 11:00 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.