Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 22nd, 2007, 08:25 AM
Registered User
 
Join Date: May 2007
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?


 
Old May 22nd, 2007, 08:32 AM
Wrox Author
 
Join Date: Oct 2005
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
================================================== =========
 
Old May 22nd, 2007, 08:43 AM
Friend of Wrox
 
Join Date: Sep 2005
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





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.