0

Visual Basic (2013) is refusing to work properly, so I have no way of testing my code, and as you can probably tell i have no clue. I am trying to take information from a csv file and use VB to write a certain part of data in the csv to a separate text file. This is my code so far:

Imports System.IO

Public Class Form1
    Dim inFile As StreamReader = Nothing
    Dim outFile As StreamWriter = Nothing
    Dim sFilename As String = "C:\etc"
    Dim inputText As String
    Dim FileNumber As Integer
    Dim FileName As String = ""

    Private Sub ReadWrite()
        FileNumber = FreeFile()
        FileOpen(FileNumber, FileName, OpenMode.Output, OpenAccess.Write)
        outFile = New StreamWriter(sFilename)
        inFile = New StreamReader(sFilename)
        Dim i As String() = Split(sFilename, ",", , CompareMethod.Text)
        inputText = inFile.ReadToEnd()
        inFile.Close()
        TextBox2.Text() &= "Testtt mcgee" & vbCrLf
        TextBox2.Text() &= inputText

        TextBox2.Select(0, 0)
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        ReadWrite()
    End Sub
End Class

It is nowhere near complete, but i don't have the faintest of what to do next.

Blackwood
  • 4,504
  • 16
  • 32
  • 41
  • 1
    It looks like a bit of documentation reading would help you. [Common I/O Tasks](https://msdn.microsoft.com/en-us/library/ms404278%28v=vs.110%29.aspx) has some examples which may lead you in the right direction. – Andrew Morton Feb 06 '16 at 15:34
  • Have you seen this question - http://stackoverflow.com/questions/736629/parse-delimited-csv-in-net – John Feb 06 '16 at 15:56
  • OK. I'm just asking these questions for clarification .. What is the layout of each line of your input file? Looking at your code I'm guessing it might be regular comma delimiters. How big is the file and what data do you want to output to the second file? Incidentally as things stand you are trying to open a file called "etc" to read from it and also you're trying to open the same file to write to it. Also What is the purpose of the TextBox? – David Wilson Feb 06 '16 at 18:45
  • *Visual Basic is refusing to work properly* how so? maybe it doesnt like trying to read and write to the same file at the same time. CSVs are not random access, so they do not make good database replacements. VB.NET has much better file File IO methods than those old VB6 functions – user3697824 Feb 07 '16 at 01:46
  • I was trying to access vb in another user on the same computer, and what most likely happened was a file was missing or not being accessed properly. That one was my bad. – N0tAClu3 Feb 07 '16 at 11:07

0 Answers0