Solved

Create binary file from text file

Posted on 2013-06-21
16
376 Views
Last Modified: 2013-06-24
vb.net8

I have a text file..

Pipe delimited format

material_no|alt_material_no_Green
4TM77|4YM42
5E103|5E104
5E081|5E080
2F141|4ZF10
4KK81|4KK82
2F145|2F132
3UM46|4KK77
5A283|4KK77
3W230|4XM33
3W231|4XM35
4W174|4XM37
4W075|4XM39
4W076|4XM43
6W693|4XM57
6W694|4XM59
6W695|4XM61
5E145|5E077

Is there a way to create a binary file from this text format ?


Thanks
fordraiders
0
Comment
Question by:fordraiders
  • 9
  • 5
16 Comments
 
LVL 9

Expert Comment

by:Misbah
ID: 39267190
generally this can be done through binary serialization .
so one way is to create a COM visible DLL in C# or VB.NET , then call it from Visual Basic
(I am assuming you are not using VB.NET)
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39268675
1)Use IO.File.ReadAllText method to read text file
2) Use GetBytes method to convert text to byte array
3) Use WriteAllBytes to write binary file

File.WriteAllBytes("BinaryFile.bin", Encoding.Ascii.GetBytes(File.ReadAllText("TextFile.txt"))
0
 
LVL 3

Author Comment

by:fordraiders
ID: 39272783
does it matter how big the text file is ?
0
 
LVL 3

Author Comment

by:fordraiders
ID: 39272785
its that one line of code ?
0
 
LVL 3

Author Comment

by:fordraiders
ID: 39272797
declarations for :

File.WriteAllBytes("BinaryFile.bin", Encoding.Ascii.GetBytes(File.ReadAllText("TextFile.txt"))

??
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 39272854
Add

Imports System.IO
Imports System.Text

at the top
0
 
LVL 3

Author Comment

by:fordraiders
ID: 39272946
keeps telling me invalid outside procedure.

references ? maybe

I have tagged  "vb scripting runtime"
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39272957
>keeps telling me invalid outside procedure.

I hoped you would add it behind a button or something.
0
 
LVL 3

Author Comment

by:fordraiders
ID: 39272978
Calling this from a button:


BinaryTransfer()




Imports System.IO
Imports System.Text
Option Explicit

Sub BinaryTransfer()


File.WriteAllBytes ("C:\Program Files\Crs\Keep.bin"), Encoding.Ascii.GetBytes(File.ReadAllText("C:\Program Files\Crs\keep.txt"))



End Sub
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39272999
Can you show the whole code? And what the error is now?
0
 
LVL 3

Author Comment

by:fordraiders
ID: 39273020
vba imports problem

this is the code...

Sub BinaryTransfer()


File.WriteAllBytes ("C:\Program Files\Crs\Keep.bin"), Encoding.Ascii.GetBytes(File.ReadAllText("C:\Program Files\Crs\keep.txt"))



End Sub
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39273046
You added this question in VB.NET zone so the code I have provided is for vb.net.
0
 
LVL 3

Author Comment

by:fordraiders
ID: 39273149
i did not add it the moderator did...


sorry
0
 
LVL 3

Author Comment

by:fordraiders
ID: 39273152
oop sorry...

in my vba mode...


Thnks
0
 
LVL 3

Author Closing Comment

by:fordraiders
ID: 39273155
Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now