How do I open file for input

  • Thread starter Thread starter Kurt
  • Start date Start date
K

Kurt

In VB4, VB6 I have code that works very well coded as;

Drive = App.Path & "\User_Files\profile.bda"
Open Drive For Input As #1
Input #1, dat4, Abackup, TimeHide, WhatRunmin, autorun, cleanwhen
Close #1

Can someone please assist me in doing this using VB.NET
I need to open a file with multiple fields separated by commas and I’ve spent many hours trying to figure this out using VB.NET and so far have not.Thank you in advance for your help.
 
==================================================================================

I thought I had it resolved, but it's not working like I hoped and I've checked out a lot of links on this subject but still have not found a way to read / write CSV files using VBexpress 2005.
I'm thinking this program sucks. Why they didn't make it easy to do what a program like this should do is bad business.
When I write the data back to the file it just read from, it leaves some strings characters at the beginning of the line.
 
It leaves some STRANGE characters at the beginning of the line. is what I was trying to say.
 
Can someone assist me in getting this program to read and write CVS files without leaving the strange characters in the front of the line when it writes the data back to the HD. Thank you in advance for your help.
 
-------------------------------------------------------------------------------

Hi Peter, Thanks for your reply.
I’ve tried different things and nothing seems to work as well as what I’ve got here below, this is just a trial and error test program to get the expected end results of reading / writing to csv files. Here’s the codeat this point.

FileNumber = FreeFile()
FileOpen(FileNumber, My.Application.Info.DirectoryPath & "\User_Files\profile.bda", OpenMode.Input)
t = 1
Do Until EOF(1)
Input(FileNumber, filecheck)
If t = 1 Then dat4 = filecheck
If t = 2 Then Abackup = filecheck
If t = 3 Then TimeHide = filecheck
t = t + 1
Loop
FileClose(FileNumber)
t = 0
Dim csvFile As String = My.Application.Info.DirectoryPath & "\User_Files\profile.bda"
Dim outFile As IO.StreamWriter = My.Computer.FileSystem.OpenTextFileWriter(csvFile, False)

outFile.WriteLine(dat4 & "," & Abackup & "," & TimeHide)
outFile.Close()
Console.WriteLine(My.Computer.FileSystem.ReadAllText(csvFile))

And here’s the end results;

3,1,1

I was expecting to see 3,1,1 but as you can see there are these strainge charictors added to the front of the line.
 
---------------------------------------------------------------------------------
I'm having trouble trying this because I don't know what type "Encoding" should be declared as"
 
For what it's worth, I have tested the technique in your code, and verified it does exactly what I expect: i.e. the ReadAllText() method correctly interprets the BOM and the subsequent call to Console.WriteLine() shows only the data you expected. I suspect that you are leaving out an important piece of information.

----------------------------------------------------------------------------------
The only thing I can see that I forgot to mention is I have in a module declarations page
Public dat4 As Object
Public Abackup As Integer
Public TimeHide As Integer

and with that I am still getting the same thing "unexpected results". I'm getting so burned out on trying this but because of this I am at a stand still. uuugggggghhhh. Thanks for trying with me.
 
I think the most likely explanation is that you do not in fact see the extra characters looking at the output of Console.WriteLine(), but instead are seeing them in some other context (e.g. loading the file in a text editorthat doesn't understand the UTF-8 BOM).
 
Back
Top