Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I need to change my code because I have some problem with it, and I need a replacement for the FileOpen function.
Do you know what could I use insted of FileOpen function ?
I thinked to writeline function but I don't know how to use it, because I need to import some option into the output (I'm making a builder app based).
Here is the actual code I need to replace :

VB
Dim myfile, opt() as string
FileOpen(1, Application.ExecutablePath, OpenMode.Binary, OpenAccess.Read, OpenShare.Shared)

        myfile = Space(LOF(1))

        FileGet(1, myfile)
        FileClose(1)
        Label1.Text = opt(1)
        Label2.Text = opt(2)
        Label3.Text = opt(3)


How you can see I receive in the output file the options (opt) I checked before in my builder, but I need another way to do this.
Could writeline - filestream function do same work?

Hope you can help me.
Posted
Updated 3-Jul-14 11:18am
v2
Comments
[no name] 3-Jul-14 17:30pm    
Well that depends. Are you writing this in VB or VB.NET? Why is this code not working for you? "some problem" means absolutely nothing to anyone but you. Does "some problem" mean that you are not using FileGet correctly and opt contains nothing?
Member 8078971 3-Jul-14 17:54pm    
I'm coding in VB.NET anyway I don't meant my code doesn't work, it work correctly and it is perfect, but for others reasons I need to change it, I can't release my program with this function.
So I'm trying to search an alternative, possibly easy like FileOpen is.

1 solution

It depends on what and how you want to read/write to/from this file. In most cases, these alternatives are much: better binary/text readers/writers. Please see:
http://msdn.microsoft.com/en-us/library/system.io.streamreader%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.io.streamwriter%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.io.binaryreader%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.io.binarywriter.aspx[^].

Besides, I'm not sure if you really need to deal with file IO directly. In many cases, using serialization is much better. For the ideas:
http://en.wikipedia.org/wiki/Serialization[^],
using data contracts: http://msdn.microsoft.com/en-us/library/ms733127%28v=vs.110%29.aspx[^].

Good luck,
—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900