[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

edit button

Posted on 2006-04-28
8
Medium Priority
?
289 Views
Last Modified: 2010-04-23
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
0
Comment
Question by:aplelois
8 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16568561
Stupid warning.  This is the simple solution:

Dim strLine As String = ""

Bob
0
 

Author Comment

by:aplelois
ID: 16568571
thanks and can you please tell me why when I click save it makes a new line
instead of saving the corrected data?
0
 
LVL 12

Expert Comment

by:gbzhhu
ID: 16569140
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:aplelois
ID: 16569237
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
 
LVL 34

Expert Comment

by:Sancler
ID: 16569253
>>
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
 

Author Comment

by:aplelois
ID: 16569282
then what about If I add a new button called Edit in edit.vb
that way Ill have Save and Edit
0
 

Author Comment

by:aplelois
ID: 16569313
ok how do I do it with fixed length?
0
 
LVL 34

Accepted Solution

by:
Sancler earned 2000 total points
ID: 16569443
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question