0

Hola amigos estoy realizando un proyecto para generar licencias donde tengo un apartado del estado que guarda dicha licencia, al inicio de la app se genera un archivo de texto donde la cadena de texto tiene el dato de el estado de la licencia. el estado inicial es estado = Encriptar(?ACTIVO?), ahora este valor lo quiero sustituir por estado = Encriptar(VENCIDO), para ello estoy utilizando el siguiente código, pero me da error en la cuarta instrucción diciéndome que no existe el archivo pero realmente si existe. Alguien podrá apoyarme, dejo el código

     Dim estado As String
    estado = Encriptar("VENCIDO")

    Using fileWrite As New StreamWriter(Application.StartupPath + "temp.txt")
        Using fielRead As New StreamReader(Application.StartupPath + "licencia_temporal.txt")

            Dim line As String = fielRead.ReadLine

            Do While (Not line Is Nothing)

                'Dim datos As String() = line.Split(New Char() {"|"c})

                Dim partes As String() = line.Split("|"c) ' se establece el separador 

                If (partes(0) = "estado") Then 'ASI BUSCAMOS E IDENTIFICAMOS EL CEBO
                    partes(0) = "estado" 'DE ESTA FORMA SE ALTERA O MODIFICA EL VALOR DE CADA PARTE 
                    'Apellido_lbl.Text = partes(0)
                    'fileWrite.WriteLine(String.Join("|", partes))

                End If
                ' If Sw = False Then
                fileWrite.WriteLine(String.Join("|", partes)) 'PARTES SOLA SON TODAS LAS PARTES O CASILLAS O SEPARACIONES DE _
                'LA LISTA DEL ARCHIVO TXT
                line = fielRead.ReadLine
                'End If

            Loop

        End Using
    End Using
9
  • que no le falta una barra a las rutas? depuraste y viste la cadena resultante?
    – gbianchi
    el 5 mar. 2021 a las 18:00
  • sucede lo mismo con la barra \ antes de las rutas
    – joloco61
    el 5 mar. 2021 a las 18:10
  • Entonces no, no existe el archivo... comproba que estes mirando las mismas rutas...
    – gbianchi
    el 5 mar. 2021 a las 18:12
  • Si utilizo la siguiente instruccion si funciona: Using fielRead As New StreamReader("D:\Codigos fuentes de checker\Prueba de licencia\Prueba de licencia\bin\Debug\licencia_temporal.txt"), pero yo quiero que se pueda uasr en cualquier pc
    – joloco61
    el 6 mar. 2021 a las 2:01
  • Ahhh ya se cual es tu problema... mañana si puedo te armo una respuesta. Cuando usas la ide startuppath es el path de la ide.. no de la app...
    – gbianchi
    el 6 mar. 2021 a las 2:54

1 respuesta 1

0

Para el Acceso y Escritura de Archivos, Puedes Utilizar estas Dos Funciones Que Utilizo Yo y A Mi Me Funcionan Bien...

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
    vb.FileSystem.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

Public Function FileWriteData(ByVal FilePath As String, ByVal FileData As String) As Boolean
    On Error Resume Next
    
    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

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.