Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 90280

VBA EXCEL search value and replace with split delimiter in file .txt

$
0
0

Someone help me Change value in txt file. I have this code from another project of mine, I would like to adapt it to this project:

    Private  Sub TextFile_FindReplace()

Dim y, i As Long, ii As Long
If Me.ListBox1.ListIndex = -1 Then Exit Sub
y = Split(x(Me.ListBox1.ListIndex), "|")
For i = 0 To Me.ListBox1.ColumnCount - 1
    If Me("textbox"& i + 1) <> "" Then y(i) = Me("textbox"& i + 1)
Next
x(Me.ListBox1.ListIndex) = Join(y, "|")
Open ThisWorkbook.Path & "\REGISTER\users.txt" For Output As #1
    Print #1, Join(x, vbNewLine);
Close #1
UserForm_Initialize
End sub

I would like to adapt this code above to the [BtnChangePass]. Explanation: I load the data into some textboxs with this code below:

Private Sub SearchLoginFileTXT()

Dim Registro() As String, blnFound As Boolean
Dim strLine As String
Dim f As Integer
Dim lngLine As Long, iD As Long
Dim strFileName As String
strFileName = ThisWorkbook.Path & "\REGISTER\users.txt"
    If TxtLogin.Text = "" And TxtChangeLogin.Text = "" And TxtCadLogin.Text = "" Then
        'Exit Sub
        'Call ClearFields
    Else
 f = FreeFile

Open strFileName For Input As #f
Do While Not EOF(f)
     lngLine = lngLine + 1
     Line Input #f, strLine
    Registro = Split(strLine, "|")
    blnFound = False
If Registro(2) = TxtLogin.Text Or Registro(2) = TxtChangeLogin.Text Or Registro(2) = TxtCadLogin.Text Then
                    Call LabelPosition
                        iD = Registro(0): TxtCheckCount.Text = Registro(0)
                        iD = Registro(0): TxtCheckID.Text = Registro(1)
                        iD = Registro(0): TxtCheckLogin.Text = Registro(2)
                        iD = Registro(0): TxtCheckName.Text = Registro(3)
                        iD = Registro(0): TxtCheckDateBirthday.Text = Registro(4)
                        iD = Registro(0): TxtCheckPassword.Text = Registro(5)
                        iD = Registro(0): TxtCheckStatus.Text = Registro(6)
                        iD = Registro(0): TxtLevel.Text = Registro(7)
                        blnFound = True
                        Close #f
                        Exit Sub

End If
    Loop
     Close #f
    If blnFound = False Then
        Call LabelPosition2
        'MsgBox "Login Invalid", vbInformation
        'Cancel = True

    End If
     Close #f
End If  
End Sub

I have to change this information when I click the button [BtnChangePass]


Viewing all articles
Browse latest Browse all 90280

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>