edit button

hello,
im having a problem with an edit button I have,
when I select the record from the listbox and
click edit I go to edit and then correct the data
then click save and it makes a new line in the
ini file. im also getting a warning in here
Warning 1 Variable 'strLine' is used before it has been assigned a value.

edit button in main.vb
    Private Sub cmdEdit_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdEdit.Click
        Dim frmAD As frmAdd_Edit
        frmAD = New frmAdd_Edit
        frmAD.Populate((lstAccounts.SelectedIndex))
        frmAD.ShowDialog()
    End Sub


button in edit.vb
Populate and the save button
    Private Sub cmdSave_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdSave.Click
        Dim FileNo As Short
        On Error Resume Next

        FileNo = FreeFile
        FileOpen(FileNo, "Accounts.ini", OpenMode.Append, , OpenShare.Shared)
        PrintLine(FileNo, Text_Email.Text & ";" & Text_Passwd.Text & ";")
        FileClose(FileNo)

        frmMain.Enabled = True
        frmMain.Activate()
        Me.Close()
        Call frmMain.ReloadINI()
    End Sub

    Public Sub Populate(ByVal Record As Integer)
        On Error Resume Next
        Dim FileNo As Integer
        Dim strLine As String
        FileNo = FreeFile
        FileOpen(FileNo, "Accounts.ini", OpenMode.Input)
        Dim intRecord As Integer
        For intRecord = 0 To Record
            strLine = LineInput(FileNo)
        Next

        Text_Email.Text = Split(strLine, ";")(0)
        Text_Passwd.Text = Split(strLine, ";")(1)
        FileClose(FileNo)

    End Sub
apleloisAsked:
Who is Participating?
 
Bob LearnedCommented:
Stupid warning.  This is the simple solution:

Dim strLine As String = ""

Bob
0
 
apleloisAuthor Commented:
thanks and can you please tell me why when I click save it makes a new line
instead of saving the corrected data?
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
gbzhhuCommented:
Stupid suggestion but I can't see anything else wrong

Do the Text_Email  and Text_Passwd contain data at the time of saving?

0
 
apleloisAuthor Commented:
the data of the text boxes in edit.vb
when you click in main.vb you go there
and theere you see the data in the textbox
0
 
SanclerCommented:
>>
can you please tell me why when I click save it makes a new line instead of saving the corrected data
<<

The simple answer is: because that's what your code tells it to do.

        FileNo = FreeFile
        FileOpen(FileNo, "Accounts.ini", OpenMode.Append, , OpenShare.Shared)
        PrintLine(FileNo, Text_Email.Text & ";" & Text_Passwd.Text & ";")
        FileClose(FileNo)

The file OpenMode is Append, so the PrintLine "appends" a line at the end of the file.

The more complicated answer is that you cannot amend a line in a text file, or insert a line into a text file, without opening a new file, writing into it all the lines from the old file up to but not including the line you want to amend, then writing into it the amended line (or a new line that you want to insert), then writing into all the lines after but not including the line you wanted to amend/insert, then saving the new file, deleting the old file and renaming the new file as the old file.

To be able to replace one record with another, you will need to use a different file structure - e.g. with fixed length, rather than delimited - records and different approaches for reading and writing.

Roger
0
 
apleloisAuthor Commented:
then what about If I add a new button called Edit in edit.vb
that way Ill have Save and Edit
0
 
apleloisAuthor Commented:
ok how do I do it with fixed length?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.