Hey i am at college doing an assignment, i just need a little bit of help can some one help me put in a delete button in to my code some how or some how help me to be able to delete a record from interface.
Here is the form working
and here is the code
Code:
Private somedata As String
Private Sub Command3_Click()
Open "E:\Movies.txt" For Append As #1
Print #1, Text1.Text
Print #1, Text2.Text
Print #1, Text3.Text
Print #1, Text4.Text
Print #1, Text5.Text
Close #1
List1.Clear
List2.Clear
List3.Clear
List4.Clear
List5.Clear
Call Form_Load
End Sub
Private Sub Form_Load()
Open "E:\Movies.txt" For Input As #1
Do While Not EOF(1)
Input #1, somedata
List1.AddItem somedata
Input #1, somedata
List2.AddItem somedata
Input #1, somedata
List3.AddItem somedata
Input #1, somedata
List4.AddItem somedata
Input #1, somedata
List5.AddItem somedata
Loop
Close #1
End Sub
Last edited by S_A_M.1990; Dec 3rd, 2009 at 11:40 AM.
Here's some suggestions.
1. Add a button to delete records
2. When button is clicked
-- ensure List1 has an item selected (List1 is the movie names, correct?)
-- remove the same item index from all listboxes.
-- The selected item index in any listbox is .ListIndex
3. After deleting from the listboxes, re-write your Movies.Txt file (i.e., Open for Output not Append) from the remaining entries in your listboxes
-- alternatively, you can set a flag indicating the "database" has changed and requires re-writing when the app is closing.
Insomnia is just a byproduct of, "It can't be done"
1. Add a button to delete records
2. When button is clicked
-- ensure List1 has an item selected (List1 is the movie names, correct?)
Will this only delete whats in list 1 ? if so is there any way to be able to select something from each list and delete them all ?
Also could you show me the code that i need for it to delete something from the list after the button is clicked
1. Add a button to delete records
2. When button is clicked
-- ensure List1 has an item selected (List1 is the movie names, correct?)
Will this only delete whats in list 1 ? if so is there any way to be able to select something from each list and delete them all ?
Also could you show me the code that i need for it to delete something from the list after the button is clicked
To remove the selected item:
Code:
List1.RemoveItem List1.ListIndex
You will have to remove the list item from each listbox individually. Recommend removing from the others and do List1 last.
You can kind of synchronize your listboxes a bit. Each time a list item is selected the Click event of the listbox fires. You can ensure each listbox has the same list item selected any time any of the listboxes change. To select a listitem via code:
Code:
List3.ListIndex = x
' you supply X which is an valid value between 0 and the number of items
' in the listbox less one. In otherwords: .ListCount - 1
Edited: Probably not addressed yet in your class. But using a array of listboxes would reduce amount of code needed each time you had to do something to all listboxes and make your job easier too.
Last edited by LaVolpe; Dec 2nd, 2009 at 01:05 PM.
Insomnia is just a byproduct of, "It can't be done"
Thank you so much for your help.
I have got it working, it deletes from the list but i can't get it to delete the data from the file it is reading it out of.
Is it possible to get it to delete the data from the file aswel?
Thank you so much for your help.
I have got it working, it deletes from the list but i can't get it to delete the data from the file it is reading it out of.
Is it possible to get it to delete the data from the file aswel?
You are welcome.
You cannot just remove a line from a file (99.99% of the time). Updating a file almost always requires rewriting the file. Therefore, you would rewrite it as I suggested in post #2 above.
Insomnia is just a byproduct of, "It can't be done"
So if i add a new button in and call it update after i use the delete button then click update would it be possible to do it that way?
Or you can write the code for saving the data to the file, inside the delete button, ie. after the code for deleting..
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video) My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet Social Group:VBForums - Developers from India
If so could you tell me the code i need to get that to work
File input/output tutorial is available in our Classic VB6 FAQ section...
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video) My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet Social Group:VBForums - Developers from India
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video) My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet Social Group:VBForums - Developers from India
Private somedata As String
Private Sub Command1_Click()
List1.RemoveItem List1.ListIndex
List2.RemoveItem List2.ListIndex
List3.RemoveItem List3.ListIndex
List4.RemoveItem List4.ListIndex
List5.RemoveItem List5.ListIndex
End Sub
Private Sub Command3_Click()
Open "X:\Movies.txt" For Append As #1
Print #1, Text1.Text
Print #1, Text2.Text
Print #1, Text3.Text
Print #1, Text4.Text
Print #1, Text5.Text
Close #1
List1.Clear
List2.Clear
List3.Clear
List4.Clear
List5.Clear
Call Form_Load
End Sub
Private Sub Form_Load()
Open "X:\Movies.txt" For Input As #1
Do While Not EOF(1)
Input #1, somedata
List1.AddItem somedata
Input #1, somedata
List2.AddItem somedata
Input #1, somedata
List3.AddItem somedata
Input #1, somedata
List4.AddItem somedata
Input #1, somedata
List5.AddItem somedata
Loop
Close #1
End Sub
There is the code as you can see i have added in the delete button and it works but doesnt delete from the file
you need to change your code. You are opening the file in append mode. if you opened then saved your file would suddenly be twice as big. Open it in output mode to write it. Whenever you delete a listing from the listbox, simply call the write routine again. This way it will always be up to date.
you need to change your code. You are opening the file in append mode. if you opened then saved your file would suddenly be twice as big. Open it in output mode to write it. Whenever you delete a listing from the listbox, simply call the write routine again. This way it will always be up to date.
Open "X:\Movies.txt" For Output As #1
What is the code to call write routine again? sorry about this
What is the code to call write routine again? sorry about this
What routine ?
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video) My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet Social Group:VBForums - Developers from India
I still cant get it to delete something from the file it deletes on the form but then when you restart the program its still there any one know the code i need to remove it from the file ??
I still cant get it to delete something from the file it deletes on the form but then when you restart the program its still there any one know the code i need to remove it from the file ??
Ok.......?
Please go to the Thread Tools menu and click Mark Thread Resolved when you have your answer.
Last edited by 5ms?; Dec 3rd, 2009 at 10:37 AM.
.
The answer to your question is Here
And here
C:\Program Files\Microsoft Visual Studio\MSDN98\98VSa\1033\SAMPLES\VB98
Please go to the "Thread Tools" menu at the top of this Thread, and click "Mark Thread Resolved" when you have your answer.
So I can fine the answer when I need it.
So please install VB6 service pack 6 as its the latest and last supported service pack MS will ever make. http://support.microsoft.com/kb/q198880/ I'm sure this will fix your issue
The only reason some people get lost in thought is because it’s unfamiliar territory. —Paul Fix
Private Sub Command3_Click()
Open "X:\Movies.txt" For Append As #1
Write #1, Text1.Text,Text2.Text,Text3.Text,Text4.Text,Text5.Text
Close #1
List1.Clear
List2.Clear
List3.Clear
List4.Clear
List5.Clear
Call Form_Load
End Sub
Private Sub Form_Load()
dim a as string,b as string,c as string,d as string,e as string
Open "X:\Movies.txt" For Input As #1
Do While Not EOF(1)
Input #1, a,b,c,d,e
List1.AddItem a
List2.AddItem b
List3.AddItem c
List4.AddItem d
List5.AddItem e
Loop
Close #1
End Sub
I made small corrections to your code...
And inside the delete button, you can write this code for saving the data after deleting:
Code:
dim i as integer
Open "X:\Movies.txt" For output As #1
for i=0 to list1.listcount-1
Write #1, list1.(i),list2.(i),list3.list(i),list4.list(i),list5.list(i)
next i
close #1
I haven't tested them...
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video) My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet Social Group:VBForums - Developers from India
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video) My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet Social Group:VBForums - Developers from India
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video) My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet Social Group:VBForums - Developers from India
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video) My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet Social Group:VBForums - Developers from India
dim strSearch as string
strsearch = txtsearch.Text
For i = 0 To List1.ListCount - 1
If List1.List(i) = strsearch Then
MsgBox List1.List(i) & " " & List2.List(i)
exit for '~~~~> escape from the loop
End If
Next i
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video) My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet Social Group:VBForums - Developers from India
If your problem is solved, please Mark the Thread as RESOLVED
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video) My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet Social Group:VBForums - Developers from India