Oct 20th, 2006, 06:00 AM
#1
Thread Starter
Frenzied Member
List View (RESOLVED)
Can anybody help me out i'm having a few problems with my address book. The problem is on frmDisplay can you help me display each record in a list view with everything in it. I have also attached my code for you to take a look at
Last edited by Jamie_Garland; Oct 27th, 2006 at 01:20 PM .
Oct 20th, 2006, 06:23 AM
#2
Re: List View
Took only a minute to update the cmdDisplay_Click() event.
Attached Files
Oct 20th, 2006, 06:40 AM
#3
Re: List View
EDIT: Oh, a solution was already provided.
Attached Files
Oct 20th, 2006, 04:06 PM
#4
Thread Starter
Frenzied Member
Re: List View (RESOLVED)
I'm having a problem with the delete code can anyone help me please i ahve attached my project aswell.
VB Code:
Private Sub cmdDelete_Click()
Dim lngIndex As Long
Dim i As Long
If Admin = False Or User = True Then
MsgBox "Sorry, unfortunately only someone with Administrator Access can perform that operation. Please contact your administrator for further queries."
Else
If vbNo = MsgBox("Are you sure?", vbYesNo + vbQuestion, "About to Delete This address") Then
Exit Sub
End If
For lngIndex = 1 To Number - 1
With AddressBook(lngIndex)
.fullname = AddressBook(lngIndex + 1).fullname
.address = AddressBook(lngIndex + 1).address
.town = AddressBook(lngIndex + 1).town
.postcode = AddressBook(lngIndex + 1).postcode
.dob = AddressBook(lngIndex + 1).dob
.house = AddressBook(lngIndex + 1).house
.mobile = AddressBook(lngIndex + 1).mobile
End With
Next
Kill FileName
Number = Number - 1
Open FileName For Output As #1
For i = 1 To Number ' - 1
With AddressBook(i)
Write #1, .fullname
Write #1, .address
Write #1, .town
Write #1, .postcode
Write #1, .dob
Write #1, .house
Write #1, .mobile
End With
Next i
Close #1
'new
With AddressBook(1)
Text1.Text = .fullname
Text2.Text = .address
Text3.Text = .town
Text4.Text = .postcode
Text5.Text = .dob
Text6.Text = .house
Text7.Text = .mobile
End With
End If
End Sub
Oct 21st, 2006, 03:02 AM
#5
Re: List View (RESOLVED)
Your always deleting the first item in the array cause your starting your "shift" loop there.
VB Code:
Public Sub ShiftDown(ByVal currpos As Long)
Dim i As Long
If currpos < LBound(AddressBook) Or currpos > UBound(AddressBook)
For i = currpos To UBound(AddressBook) - 1 'start shift at current position
With AddressBook(i)
.fullname = AddressBook(i + 1).fullname
.address = AddressBook(i + 1).address
.town = AddressBook(i + 1).town
.postcode = AddressBook(i + 1).postcode
.dob = AddressBook(i + 1).dob
.house = AddressBook(i + 1).house
.mobile = AddressBook(i + 1).mobile
End With
Next
ReDim Preserve AddressBook(UBound(AddressBook) - 1)
End Sub
Oct 21st, 2006, 05:45 AM
#6
Thread Starter
Frenzied Member
Re: List View (RESOLVED)
How would i get it to delete the record that i choose instead of deleting the first one.?
Last edited by Jamie_Garland; Oct 21st, 2006 at 05:55 AM .
Oct 21st, 2006, 11:00 AM
#7
Re: List View
You pass currpos to the function I gave you, its an array index where you want to start the deletion.
If your indices for AddressBook() were 0,1,2,3,4,5 or lower bound zero and upper bound 5 then calling ShiftDown(2) will result with 0,1,3,4,5 (these are previous index values).
You can then go on as you did before, killing the previous copy of the file and creating a new one from AddressBook().
Oct 21st, 2006, 12:50 PM
#8
Thread Starter
Frenzied Member
Re: List View
Im lost now can you put it in to the project
Oct 21st, 2006, 01:01 PM
#9
Re: List View
VB Code:
Private Sub cmdDelete_Click()
Dim lngIndex As Long
Dim i As Long
If Admin = False Or User = True Then
MsgBox "Sorry, unfortunately only someone with Administrator Access can perform that operation. Please contact your administrator for further queries."
Else
If vbNo = MsgBox("Are you sure?", vbYesNo + vbQuestion, "About to Delete This address") Then
Exit Sub
End If
'For lngIndex = 1 To Number - 1
' With AddressBook(lngIndex)
' .fullname = AddressBook(lngIndex + 1).fullname
' .address = AddressBook(lngIndex + 1).address
' .town = AddressBook(lngIndex + 1).town
' .postcode = AddressBook(lngIndex + 1).postcode
' .dob = AddressBook(lngIndex + 1).dob
' .house = AddressBook(lngIndex + 1).house
' .mobile = AddressBook(lngIndex + 1).mobile
' End With
'Next
'Are you still using nextrec variable for storing array index reference? If so...
Call ShiftDown(nextrec - 1)
Kill FileName
Number = Number - 1
Open FileName For Output As #1
For i = 1 To Number ' - 1
With AddressBook(i)
Write #1, .fullname
Write #1, .address
Write #1, .town
Write #1, .postcode
Write #1, .dob
Write #1, .house
Write #1, .mobile
End With
Next i
Close #1
'new
With AddressBook(1)
Text1.Text = .fullname
Text2.Text = .address
Text3.Text = .town
Text4.Text = .postcode
Text5.Text = .dob
Text6.Text = .house
Text7.Text = .mobile
End With
End If
End Sub
Public Sub ShiftDown(ByVal currpos As Long)
Dim i As Long
If currpos < LBound(AddressBook) Or currpos > UBound(AddressBook)
For i = currpos To UBound(AddressBook) - 1 'start shift at current position
With AddressBook(i)
.fullname = AddressBook(i + 1).fullname
.address = AddressBook(i + 1).address
.town = AddressBook(i + 1).town
.postcode = AddressBook(i + 1).postcode
.dob = AddressBook(i + 1).dob
.house = AddressBook(i + 1).house
.mobile = AddressBook(i + 1).mobile
End With
Next
ReDim Preserve AddressBook(UBound(AddressBook) - 1)
End Sub
Oct 21st, 2006, 01:03 PM
#10
Thread Starter
Frenzied Member
Re: List View
this part of the code comes up red.
Compile Error
Syntax error
VB Code:
If currpos < LBound(AddressBook) Or currpos > UBound(AddressBook)
Last edited by Jamie_Garland; Oct 21st, 2006 at 01:07 PM .
Oct 21st, 2006, 01:07 PM
#11
Re: List View
Forgot the Then part
If currpos < LBound(AddressBook) Or currpos > UBound(AddressBook) Then Exit Sub
Oct 21st, 2006, 01:12 PM
#12
Thread Starter
Frenzied Member
Re: List View
Problem now fixed thank you
Oct 22nd, 2006, 06:24 PM
#13
Thread Starter
Frenzied Member
Re: List View (RESOLVED)
Do you know howe i can get it so on the list view it shows me how many records there is in a label.
Oct 22nd, 2006, 07:56 PM
#14
Re: List View (RESOLVED)
Originally Posted by
Jamie_Garland
Do you know howe i can get it so on the list view it shows me how many records there is in a label.
VB Code:
Label.Caption = UBound(AddressBook) + 1
Please don't PM me asking for help in your thread.
Oct 26th, 2006, 09:26 AM
#15
Thread Starter
Frenzied Member
Re: List View (RESOLVED)
See if i was to double click on the listview how would i beable to show the record thats been clicked on.
Oct 26th, 2006, 09:38 AM
#16
Re: List View
Store the array index into listitem.tag
So on click/dblclick you can access the array index through listview1.selecteditem.tag
Oct 26th, 2006, 09:45 AM
#17
Thread Starter
Frenzied Member
Oct 26th, 2006, 11:24 AM
#18
Re: List View
When your adding items to the listview also include .tag
VB Code:
Dim lstNew As ListItem
Set lstNew = ListView1.ListItems.Add
lstNew.Text = AddressBook(lngIndex + 1).fullnam
lstNew.Tag = lngIndex + 1 'the array index of AddressBook() entry
So on double click, the selected listitem supplies the index
MsgBox AddressBook(Val(ListView1.SelectedItem.Tag)).fullnam
Last edited by leinad31; Oct 27th, 2006 at 01:00 PM .
Oct 26th, 2006, 11:41 AM
#19
Thread Starter
Frenzied Member
Re: List View
This is my ListView code.
VB Code:
Option Explicit
Private Sub cmdBack_Click()
Unload Me
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
Private Sub cmdNext_Click()
If lvwDisplay.SelectedItem.Index < lvwDisplay.ListItems.Count Then
lvwDisplay.ListItems(lvwDisplay.SelectedItem.Index + 1).Selected = True
Else
lvwDisplay.ListItems(1).Selected = True
End If
lvwDisplay.SelectedItem.EnsureVisible
lvwDisplay.SetFocus
End Sub
Private Sub cmdPrev_Click()
If lvwDisplay.SelectedItem.Index < lvwDisplay.ListItems.Count Then
lvwDisplay.ListItems(lvwDisplay.SelectedItem.Index - 1).Selected = True
Else
lvwDisplay.ListItems(1).Selected = True
End If
lvwDisplay.SelectedItem.EnsureVisible
lvwDisplay.SetFocus
End Sub
Private Sub Form_Load()
Label1.Caption = UBound(AddressBook) & " Players In The Database "
CenterMe Me
Dim lstAdd As ListItem
Dim i As Long
With lvwDisplay
.AllowColumnReorder = False
.FullRowSelect = True
.HideColumnHeaders = False
.HideSelection = False
.LabelEdit = lvwManual
.MultiSelect = False
.Sorted = True
.SortKey = 0
.View = lvwReport
.ColumnHeaders.Clear
.ColumnHeaders.Add , , "FULL NAME", 2000
.ColumnHeaders.Add , , "FULL ADDRESS", 3000
.ColumnHeaders.Add , , "TOWN", 1200
.ColumnHeaders.Add , , "POST CODE", 1500
.ColumnHeaders.Add , , "DATE OF BIRTH", 2000
.ColumnHeaders.Add , , "HOUSE NUMBER", 2000
.ColumnHeaders.Add , , "MOBILE NUMBER", 2000
.ListItems.Clear
For i = LBound(AddressBook) To UBound(AddressBook)
Set lstAdd = .ListItems.Add
lstAdd.Text = AddressBook(i).fullname
lstAdd.SubItems(1) = AddressBook(i).address
lstAdd.SubItems(2) = AddressBook(i).town
lstAdd.SubItems(3) = AddressBook(i).postcode
lstAdd.SubItems(4) = AddressBook(i).dob
lstAdd.SubItems(5) = AddressBook(i).mobile
lstAdd.SubItems(6) = AddressBook(i).house
Next
End With
End Sub
Private Sub lvwDisplay_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
If lvwDisplay.SortKey = ColumnHeader.Index - 1 Then
If lvwDisplay.SortOrder = lvwAscending Then
lvwDisplay.SortOrder = lvwDescending
Else
lvwDisplay.SortOrder = lvwAscending
End If
Else
lvwDisplay.SortKey = ColumnHeader.Index - 1
End If
End Sub
Oct 26th, 2006, 11:46 AM
#20
Re: List View
So what's your existing code for double click? We don't even have an idea what you mean by showing the record.. showing in another form? Showing in textboxes? etc?
You have to learn to be more informative and don't expect someone will always do most of the coding for you.
Oct 26th, 2006, 11:50 AM
#21
Thread Starter
Frenzied Member
Re: List View
I want it to show on another form im sorry i should have been more informative in the future.
Oct 26th, 2006, 11:57 AM
#22
Re: List View
VB Code:
Dim oFrm As New YourShowForm
Load oFrm
With AddressBook(Val(lvwDisplay.SelectedItem.Tag))
oFrm.txtFullName.Text = .fullnam
oFrm.txtFullName.Tag = Val(lvwDisplay.SelectedItem.Tag) 'in case you need to know array index in other form
oFrm.txtAddress.Text = .address
'etc etc
End With
Oct 26th, 2006, 05:52 PM
#23
Thread Starter
Frenzied Member
Re: List View
What do i do to get it on the new form.
Do i do this first.
VB Code:
Private Sub lvwDisplay_DblClick()
frmPeople.Show
End Sub
Last edited by Jamie_Garland; Oct 26th, 2006 at 05:57 PM .
Oct 27th, 2006, 02:08 AM
#24
Re: List View
VB Code:
[b]Private Sub lvwDisplay_DblClick()[/b]
Dim oFrm As New YourShowForm
Load oFrm
With AddressBook(Val(lvwDisplay.SelectedItem.Tag))
oFrm.txtFullName.Text = .fullnam
oFrm.txtFullName.Tag = Val(lvwDisplay.SelectedItem.Tag) 'in case you need to know array index in other form
oFrm.txtAddress.Text = .address
'etc etc
End With
[b]oFrm.Show
End Sub[/b]
Oct 27th, 2006, 03:20 AM
#25
Thread Starter
Frenzied Member
Re: List View
I'll test this code as soon as i get home.
Oct 27th, 2006, 11:55 AM
#26
Thread Starter
Frenzied Member
Re: List View
When i try to double click on one of the records i get an error.
Run-time error '9':
Subscript out of range
here is the code.
This part is the where is highlighted
With AddressBook(Val(lvwDisplay.SelectedItem.Tag))
VB Code:
Private Sub lvwDisplay_DblClick()
Dim oFrm As New oFrm
Load oFrm
With AddressBook(Val(lvwDisplay.SelectedItem.Tag))
oFrm.txtFirst.Text = .fullname
oFrm.txtFirst.Tag = Val(lvwDisplay.SelectedItem.Tag)
End With
oFrm.Show
End Sub
Oct 27th, 2006, 12:59 PM
#27
Re: List View
* sigh * This is getting frustrating.
You will get that error if you didn't assign anything to the Tag property, so the Val() function will return zero if Tag has no value... and you declared "Option Base 1" so your arrays have no zero index.. hence "subscript out of range"
You can also get that error if you assigned wrong indices to the Tag property due to wrong arithmetic.
Now, DID you include, during adding listitems to the listview, saving the array index to the Tag property like I told you a couple of posts back?!?!?
Or did you just copy paste post #25 disregarding the instruction to initialize values for the Tag property of the listitems in the listview?
Oct 27th, 2006, 01:06 PM
#28
Thread Starter
Frenzied Member
Re: List View
This is the code i use below.
VB Code:
Option Explicit
Private Sub cmdBack_Click()
Unload Me
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
Private Sub cmdNext_Click()
If lvwDisplay.SelectedItem.Index < lvwDisplay.ListItems.Count Then
lvwDisplay.ListItems(lvwDisplay.SelectedItem.Index + 1).Selected = True
Else
lvwDisplay.ListItems(1).Selected = True
End If
lvwDisplay.SelectedItem.EnsureVisible
lvwDisplay.SetFocus
End Sub
Private Sub cmdPrev_Click()
If lvwDisplay.SelectedItem.Index < lvwDisplay.ListItems.Count Then
lvwDisplay.ListItems(lvwDisplay.SelectedItem.Index - 1).Selected = True
Else
lvwDisplay.ListItems(1).Selected = True
End If
lvwDisplay.SelectedItem.EnsureVisible
lvwDisplay.SetFocus
End Sub
Private Sub Form_Load()
Label1.Caption = UBound(AddressBook) & " Players In The Database "
CenterMe Me
Dim lstAdd As ListItem
Dim i As Long
With lvwDisplay
.AllowColumnReorder = False
.FullRowSelect = True
.HideColumnHeaders = False
.HideSelection = False
.LabelEdit = lvwManual
.MultiSelect = False
.Sorted = True
.SortKey = 0
.View = lvwReport
.ColumnHeaders.Clear
.ColumnHeaders.Add , , "FULL NAME", 2000
.ColumnHeaders.Add , , "FULL ADDRESS", 3000
.ColumnHeaders.Add , , "TOWN", 1200
.ColumnHeaders.Add , , "POST CODE", 1500
.ColumnHeaders.Add , , "DATE OF BIRTH", 2000
.ColumnHeaders.Add , , "HOUSE NUMBER", 2000
.ColumnHeaders.Add , , "MOBILE NUMBER", 2000
.ListItems.Clear
For i = LBound(AddressBook) To UBound(AddressBook)
Set lstAdd = .ListItems.Add
lstAdd.Text = AddressBook(i).fullname
lstAdd.SubItems(1) = AddressBook(i).address
lstAdd.SubItems(2) = AddressBook(i).town
lstAdd.SubItems(3) = AddressBook(i).postcode
lstAdd.SubItems(4) = AddressBook(i).dob
lstAdd.SubItems(5) = AddressBook(i).mobile
lstAdd.SubItems(6) = AddressBook(i).house
Next
End With
End Sub
Private Sub lvwDisplay_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
If lvwDisplay.SortKey = ColumnHeader.Index - 1 Then
If lvwDisplay.SortOrder = lvwAscending Then
lvwDisplay.SortOrder = lvwDescending
Else
lvwDisplay.SortOrder = lvwAscending
End If
Else
lvwDisplay.SortKey = ColumnHeader.Index - 1
End If
End Sub
Private Sub lvwDisplay_DblClick()
Dim oFrm As New oFrm
Load oFrm
With AddressBook(Val(lvwDisplay.SelectedItem.Tag))
oFrm.txtFirst.Text = .fullname
oFrm.txtFirst.Tag = Val(lvwDisplay.SelectedItem.Tag)
End With
oFrm.Show
End Sub
Oct 27th, 2006, 01:14 PM
#29
Re: List View
God, can't you do anything besides copying and pasting? We do your code, we even do the debugging for you.
And now just understanding instructions, which was explained again and again, to add one line you can't do?!?
VB Code:
.ListItems.Clear
For i = LBound(AddressBook) To UBound(AddressBook)
Set lstAdd = .ListItems.Add
lstAdd.Text = AddressBook(i).fullname
[b]lstAdd.Tag = i[/b]
lstAdd.SubItems(1) = AddressBook(i).address
lstAdd.SubItems(2) = AddressBook(i).town
lstAdd.SubItems(3) = AddressBook(i).postcode
lstAdd.SubItems(4) = AddressBook(i).dob
lstAdd.SubItems(5) = AddressBook(i).mobile
lstAdd.SubItems(6) = AddressBook(i).house
Next
That's it. that's my last post in this thread.
Oct 27th, 2006, 01:18 PM
#30
Thread Starter
Frenzied Member
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width