473,473 Members | 2,269 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

VB.NET and creating text file

VJ
Hi,

I want to create a text file in the following format:
Name=yyy
Amount=zzz

and so on. The file is key-value pair and each pair appears on next line.

Now part of the data comes from the grid whereas rest I pick up from the
database. And I wrote the following code:

Dim strmExport As System.IO.StreamWriter
strmExport = New System.IO.StreamWriter &
_(objInterfaceINIData.strWorkingDirectory & mstrTempFileInput)

strmExport.AutoFlush = True

strLine = ""
strmExport.WriteLine(strLine)

strLine = "Name=" & """" & strName.Trim & """"
'Note Double quotes to take of any single quote in the name

strmExport.WriteLine(strLine)

strLine = "Amount=" & dblAmount
strmExport.WriteLine(strLine)

And so on.
Now the client says that my output file has tab chars (ascii 9). But in my
code, I am not using tab anywhere.
Now:
a. Does WriteLine add a tab char? But I cannot use Write method since I need
the key-value pair on separate lines. How do I remove tab keys?
b. I opened the file in notepad but did not see tab key. Also tried in Word.
Is there any other way to find if tab key exist in the output file?

Regards,
VJ
Apr 11 '06 #1
2 2076

"VJ" <VJ@discussions.microsoft.com> wrote in message
news:70**********************************@microsof t.com...
Hi,

I want to create a text file in the following format:
Name=yyy
Amount=zzz

and so on. The file is key-value pair and each pair appears on next line.

Now part of the data comes from the grid whereas rest I pick up from the
database. And I wrote the following code:

Dim strmExport As System.IO.StreamWriter
strmExport = New System.IO.StreamWriter &
_(objInterfaceINIData.strWorkingDirectory & mstrTempFileInput)

strmExport.AutoFlush = True

strLine = ""
strmExport.WriteLine(strLine)

strLine = "Name=" & """" & strName.Trim & """"
'Note Double quotes to take of any single quote in the name

strmExport.WriteLine(strLine)

strLine = "Amount=" & dblAmount
strmExport.WriteLine(strLine)

And so on.
Now the client says that my output file has tab chars (ascii 9). But in my
code, I am not using tab anywhere.
Now:
a. Does WriteLine add a tab char? But I cannot use Write method since I
need
the key-value pair on separate lines. How do I remove tab keys?
b. I opened the file in notepad but did not see tab key. Also tried in
Word.
Is there any other way to find if tab key exist in the output file?

Regards,
VJ


I don't know about any of the write methods adding a tab key. That seems
sort of strange.. What about if you used the write method instead of the
writeline method and after eacy pair append on Environment.NewLine
That should do the same as WriteLine would

So ex. your line strLine = "Name=" & """" & strName.Trim & """"
might look like

strLine = "Name=" & """" & strName.Trim & """" & Environment.NewLine
Apr 11 '06 #2
Dom
You may be getting tab characters from the input you are reading...

Writeline doesn't write out tab characters that you wouldn't expect.

It's trivial, but you might also want to put this into a function to
make it easier to test:

function CreateKeyValuePair(key as string, value as string) as String
dim result as String
result += key.trim
result += "="
result += value.trim
end function

Your NUnit test code would look like:
public sub TestCreateKeyValuePair()
assert_equal("Name=xxx", CreateKeyValuePair("Name", "xxx"))
assert_equal("Amount=yyy", CreateKeyValuePair("Amount", "yyy"))
end sub

Your client code would look like:
strmExport.WriteLine(CreateKeyValuePair("Name", "xxx"))
strmExport.WriteLine(CreateKeyValuePair("Amount", "yyy"))

HTH

Dominique

Apr 11 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: va | last post by:
I am trying to create recordset from a text file. The text file contains header and records. The text file is tab delimited. I am using the following statement to create the recordset Call...
4
by: Francois Keyeux | last post by:
hello everyone: i have a web site built using vbasic active server scripting running on iis (it works on either iis 50 and 60, but is designed for iis 50) i know how to create a plain text...
0
by: James Fortune | last post by:
Here is an example of Access creating a single page PDF file. The text in the textbox is scaled to fit horizontally into a grey box 100 pixels wide that is fontsize pixels high. Clicking the...
9
by: Maziar Aflatoun | last post by:
Hi everyone, I like to export some data from the database and allow my users to store this file to their harddrive as a .txt file. Does anyone know how I would go about doing that? (without...
12
by: Mats Lycken | last post by:
Hi, I'm creating a CMS that I would like to be plug-in based with different plugins handling different kinds of content. What I really want is to be able to load/unload plugins on the fly without...
15
by: David Thielen | last post by:
Hi; My ASP.NET app (C# calling J# under .net 2.0) creates a png file in a subdirectory to display as part of the created page. However, the bitmap will not display due to a security violation. ...
2
by: Astra | last post by:
Hi All Creating an rss.xml file dynamically via ASP/ADO/DB, but find errors in the file. Don't think it's an ASP prob to be honest. Think its more to do with the fact that the ampersands are...
4
by: tshad | last post by:
I am trying to set up an Image authorization where you type in the value that is in a picture to log on to our site. I found a program that is supposed to do it, but it doesn't seem to work. ...
5
eragon
by: eragon | last post by:
I wrote this function to create a new file when the user posts in my forums, and its not creating a new file, can you help me? this script is not copyrighted as the last one. function...
2
by: slizorn | last post by:
hi guys, i need to make a tree traversal algorithm that would help me search the tree.. creating a method to search a tree to find the position of node and to return its pointer value basically i...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.