edit listbox content

hello,
I have this in Form_Load()

    Dim lngFHandle As Long
    lngFHandle = FreeFile()
    Open "Accounts.ini" For Input As #lngFHandle
    Do
        Line Input #lngFHandle, strLine
        lstAccounts.AddItem Split(strLine, ";")(0)
    Loop Until EOF(lngFHandle)
    Close #lngFHandle

its working fine but right next to it I have a button called add/edit
when I select the email that I want to edit its only showing me the first
record in Accounts.ini, how can I make it so I can edit the one I select?
apleloisAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TimCotteeHead of Software ServicesCommented:
Hi aplelois,

txtEdit.Text = lstAccounts.List(lstAccounts.ListIndex)

Will drop the selected item into the textbox txtEdit for you to do what you want with it.

Tim Cottee
0
apleloisAuthor Commented:
hum, where im I suppossed to locate that line ? in edit.frm or main.frm
cause the code I have is in main!
0
apleloisAuthor Commented:
this is my button

Private Sub cmdEdit_Click()
Enabled = False
EditDetails.Show
End Sub
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

TimCotteeHead of Software ServicesCommented:
aplelois,

That depends, you haven't really given very much information. All this does is show you how you can get the value of the currently selected item in the listbox. What you do with it then very much depends on your application which I obviously don't know.

Tim
0
TimCotteeHead of Software ServicesCommented:
aplelois,

That makes more sense, in that case what you need to do is pass this information to the editdetails form:

Private Sub cmdEdit_Click()
Enabled = False
Load EditDetails
EditDetails.txtEdit.Text = lstAccounts.List(lstAccounts.ListIndex)
EditDetails.Show
End Sub

This will open the form, set the value of txtEdit on the new form to the selected entry then show it.
Tim
0
apleloisAuthor Commented:
when I try to compile this line gets yellow
Private Sub cmdEdit_Click()

and it selects the (.txtEdit)

why is that?
0
apleloisAuthor Commented:
cause in the edit.frm I have this

Private Sub Form_Load()

Dim ff As Integer, Filename As String, s As String
Filename = "Accounts.ini"
ff = FreeFile
Open Filename For Binary Access Read Lock Read Write As #ff
s = Space$(LOF(ff))
Get #ff, , s
Close ff

Text_Email = Split(s, ";")(0)
'Text_Passwd = Split(s, ";")(1)

End Sub
0
List244Commented:
Apleois he is expecting that you have a textbox on the form EditDetails named txtEdit which you wish
to contain the e-mail.  Change .txtEdit to the name of the textbox which should hold the value from the
listbox and the error will go away.

--Do not accept this comment for points.
0
apleloisAuthor Commented:
yes, I see that the errors goes aways but now its only showing the email and not the pass
I have two textbox in the edit.frm those are email and pass
this is what I have in account.txt email@domain.com;pass
so when I open the software I see only the email in the listbox, so If i click on edit
I go to the edit page.
0
TimCotteeHead of Software ServicesCommented:
aplelois,

Ok, txtEdit was my guess at your field. So I guess you need to use Text_Email instead. And possibly also need to add in the password. You can then do away with that code in the edit.frm as it will no longer be required.

The problem then is that you don't have the password to edit! Your code in form_load is what was always giving you the first record out of your accounts.ini file. You need to determine which record you want to get out, you can do this a number of ways, if the records are fixed length (which they probably aren't you can read record by record) or in your situation then it may be best to read line by line till you get the right one.

In edit.frm, remove the code from form_load, create a new PUBLIC sub as follows:

Public Sub Populate(ByVal Record As Long)
    Dim lngFHandle As Long
    Dim strLine As String
    lngFHandle = FreeFile()
    Open "Accounts.ini" For Input As #lngFHandle
    Dim intRecord As Long
    For intRecord = 0 To Record
       Line Input #lngFHandle,strLine
    Next
    'That has gone through the file till we have the correct record
    Text_Email = Split(strLine,";")(0)
    Text_Passwd = Split(strLine,";")(1)
End Sub

Then back in the main.frm change the sub to

Private Sub cmdEdit_Click()
Enabled = False
Load EditDetails
EditDetails.Populate(lstAccounts.ListIndex)
EditDetails.Show
End Sub

This will basically make the populate sub read through the records until it finds the one selected and then populate those fields.        


Tim
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
apleloisAuthor Commented:
thank you very much!!!
0
apleloisAuthor Commented:
could you please check http:Q_21826169.html maybe you could help me out in that one too!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

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.