Visual Basic saves bad text file

0

Hi, I'm doing a project with Processing, and Visual Basic. I have an application exported with processing that takes the resolution of the window of a text file. I am programming a launcher in visual basic in which you can select the resolution you want, and this what you do is write in that text file, for when you execute the processing application, use the desired resolution. My problem is that when I modify the text file manually, the application is executed in those resolutions. But when modifying it through the launcher, the application does not run.

The Vb code

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    If ComboBox1.Text = "1920x1080" Then
        Dim file As System.IO.StreamWriter
        file = My.Computer.FileSystem.OpenTextFileWriter(Application.StartupPath & "\application.windows64\data\resolucion.txt", False)
        file.WriteLine("1920")
        file.WriteLine("1080")
        file.Close()
    End If
    If ComboBox1.Text = "1280x720" Then
        Dim file As System.IO.StreamWriter
        file = My.Computer.FileSystem.OpenTextFileWriter(Application.StartupPath & "\application.windows64\data\resolucion.txt", False)
        file.WriteLine("1280")
        file.WriteLine("720")
        file.Close()



    End If
    If ComboBox1.Text = "800x600" Then


        Dim file As System.IO.StreamWriter
        file = My.Computer.FileSystem.OpenTextFileWriter(Application.StartupPath & "\application.windows64\data\resolucion.txt", False)
        file.WriteLine(800)
        file.WriteLine(600)
        file.Close()
     End If
End Sub'

Manually edited file: Arhivo edited by VB:

    
asked by Tutee United 22.10.2017 в 17:52
source

3 answers

1

I have already solved the problem. When writing the file you should use the following;

Dim sw As New System.IO.StreamWriter(Application.StartupPath & "\application.windows64\data\resolucion.txt", False, System.Text.Encoding.GetEncoding(437))
        sw.WriteLine("1920")
        sw.WriteLine("1080")
        sw.Close()
    
answered by 22.10.2017 в 20:05
0

The problem is that what you see is a flat text file that carries special characters, what you need is to know the binary access mode of a file so that it does not happen to you, I pass the code here:

Public Function FileWriteData(ByVal FilePath As String, ByVal FileData As String) As Boolean
        On Error Resume Next
        FileDelete(FilePath)
        Dim NumFile As Integer

        FileWriteData = False

        NumFile = vb.FileSystem.FreeFile
        vb.FileSystem.FileOpen(NumFile, FilePath, OpenMode.Binary, OpenAccess.Write, OpenShare.Shared)
        vb.FileSystem.FilePut(NumFile, FileData)
        vb.FileSystem.FileClose()

        If Err.Number = 0 Then
            FileWriteData = True
        End If

    End Function

Public Function FileReadData(ByVal FilePath As String) As String
        On Error Resume Next
        Dim NumFile As Integer, Datos As String, SubDatos As String
        Dim Man As Long, LenghtTempo As Long, LongitudSP As Integer

        FileReadData = vbNullString

        Datos = vbNullString

        NumFile = vb.FileSystem.FreeFile
        FileOpen(NumFile, FilePath, OpenMode.Binary, OpenAccess.Read, OpenShare.Shared)
        If Err.Number <> 0 Then Exit Function
        SubDatos = vbNullString
        LenghtTempo = LOF(NumFile)

        If LenghtTempo > 50000 Then
            For Man = 1 To LenghtTempo Step 50000
                LongitudSP = LenghtTempo - Man
                If LongitudSP < 50000 Then
                    Datos = Datos & Space(LongitudSP)
                    FileGet(NumFile, Datos)
                    SubDatos = SubDatos & Datos
                    Exit For
                Else
                    Datos = Datos & Space(50000)
                    FileGet(NumFile, Datos)
                    SubDatos = SubDatos & Datos
                End If
            Next
        Else
            Datos = Datos & Space(LenghtTempo)
            FileGet(NumFile, Datos)
            SubDatos = Datos
        End If

        FileReadData = SubDatos
        vb.FileSystem.FileClose()
    End Function
    
answered by 29.05.2018 в 16:04
0
If ComboBox1.Text = "1280x720" Then
    Dim file As System.IO.StreamWriter
    file = My.Computer.FileSystem.OpenTextFileWriter(Application.StartupPath & "\application.windows64\data\resolucion.txt", False)
    file.WriteLine("1920")
    file.WriteLine("1080")
    file.Close()

The writeLine should not be 1280 and 720?

The same is not the answer but there I already see a failure or not ... regards.

    
answered by 22.10.2017 в 18:37