Zot
asked on
Splitting a Stack, Inserting into a ListView
High points b/c I need it answered quickly and throughly.
Anywyas..
I have a variable called listStackUser
listStackUser looks a lil like this
username,0|username1,0|use rname2,2|u sername3,2 |
Username = the persons alias
the number = the image on the imagelist ot put next to their name
I need for the code to do this..
take listStackUser
split it using |
with leftover username,0
or whatever.
and then split it again so its
username (variable = username)
and
0 (variable = adminnumber)
and then add that to the userlist like this
lstUsersClient.ListItems.A dd , , username, , adminnumber
And loop it or whateve ryou have to do, so it adds all the users from the stack to the lstUsersClients.
Now, the only thing is that I want them sorted alphabetically, in this order, dev, admin, peon
Dev's admin number is 0
Admins is 1
Peons is 2
Hopefully you understand what I need.
Thank you.
Anywyas..
I have a variable called listStackUser
listStackUser looks a lil like this
username,0|username1,0|use
Username = the persons alias
the number = the image on the imagelist ot put next to their name
I need for the code to do this..
take listStackUser
split it using |
with leftover username,0
or whatever.
and then split it again so its
username (variable = username)
and
0 (variable = adminnumber)
and then add that to the userlist like this
lstUsersClient.ListItems.A
And loop it or whateve ryou have to do, so it adds all the users from the stack to the lstUsersClients.
Now, the only thing is that I want them sorted alphabetically, in this order, dev, admin, peon
Dev's admin number is 0
Admins is 1
Peons is 2
Hopefully you understand what I need.
Thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I need to sort from image numbers. sorry about that. 0s come first, then 1s, then 2s. Thx.
ASKER
I also need it to send the images and the names to the listview.
it should be
lstUsersClient.ListItems.A dd , , username, , adminnumber
it should be
lstUsersClient.ListItems.A
yup
ASKER
I also need it to send the images and the names to the listview.
it should be
lstUsersClient.ListItems.A dd , , username, , adminnumber
it should be
lstUsersClient.ListItems.A
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I also need it to send the images and the names to the listview.
it should be
lstUsersClient.ListItems.A dd , , username, , adminnumber
it should be
lstUsersClient.ListItems.A
Ops...forgot to add line i = i+1 inside the do loop.
also change add
If (Err.Number <> 0) then
Exit do
else
If (Trim(strCode) <> "") Then
UserName = Split(strCode, ",")(0)
AdminNumber = Split(strCode, ",")(1)
lstUsersClient.ListItems.A dd , , UserName, , AdminNumber
End If
End if
i= i+1
also change add
If (Err.Number <> 0) then
Exit do
else
If (Trim(strCode) <> "") Then
UserName = Split(strCode, ",")(0)
AdminNumber = Split(strCode, ",")(1)
lstUsersClient.ListItems.A
End If
End if
i= i+1
I redid the code for ListView
:::
Dim UserNameArray() As String
Dim UserPictureArray() As String
Dim SeperationArray() As String
Private Sub cmdParse_Click()
On Error Resume Next
Dim i As Integer
SeperationArray = Split(txtParseMe, "|", -1)
For i = 0 To UBound(SeperationArray) - 1
ReDim Preserve UserNameArray(0 To UBound(SeperationArray))
UserNameArray(i) = Left(SeperationArray(i), (InStr(1, SeperationArray(i), ",", vbTextCompare)) - 1)
Next
For i = 0 To UBound(SeperationArray) - 1
ReDim Preserve UserPictureArray(0 To UBound(SeperationArray))
UserPictureArray(i) = Mid(SeperationArray(i), Len(UserNameArray(i)) + 2, Len(SeperationArray(i)))
lstUsersClient.ListItems.A dd , , UserNameArray(i), , UserPictureArray(i)
Next
End Sub
:::
Dim UserNameArray() As String
Dim UserPictureArray() As String
Dim SeperationArray() As String
Private Sub cmdParse_Click()
On Error Resume Next
Dim i As Integer
SeperationArray = Split(txtParseMe, "|", -1)
For i = 0 To UBound(SeperationArray) - 1
ReDim Preserve UserNameArray(0 To UBound(SeperationArray))
UserNameArray(i) = Left(SeperationArray(i), (InStr(1, SeperationArray(i), ",", vbTextCompare)) - 1)
Next
For i = 0 To UBound(SeperationArray) - 1
ReDim Preserve UserPictureArray(0 To UBound(SeperationArray))
UserPictureArray(i) = Mid(SeperationArray(i), Len(UserNameArray(i)) + 2, Len(SeperationArray(i)))
lstUsersClient.ListItems.A
Next
End Sub
OK, here is the full thing....with sorting of the user name
Private Sub SplitAndAdd(listStackUser As String)
Dim strCode As String
Dim Users() As UserDesc
Dim TmpUser As UserDesc
Dim UsersCount As Long
Dim i As Long
Dim j As Long
i = 0
UsersCount = 0
Do While (True) ' inifinite loop until end of list
On Error Resume Next
Err.Number = 0
strCode = Split(listStackUser, "|")(i)
If (Err.Number = 0) Then
If (Trim(strCode) <> "") Then
ReDim Preserve Users(UsersCount + 1)
Users(UsersCount).UserName = Split(strCode, ",")(0)
Users(UsersCount).AdminNum ber = Split(strCode, ",")(1)
UsersCount = UsersCount + 1
End If
Else
Exit Do
End If
i = i + 1
Loop
' sort the array
For i = 0 To UsersCount - 2
For j = i + 1 To UsersCount - 1
If (Users(j).UserName < Users(i).UserName) Then
' swap the 2 users
TmpUser = Users(j).UserName
Users(j).UserName = Users(i).UserName
Users(i).UserName = TmpUser
End If
Next j
Next i
' now add items to the list
For i = 0 To UsersCount - 1
lstUsersClient.ListItems.A dd , , Users(i).UserName, , Users(i).AdminNumber
Next i
End Sub
if you want to sort by AdminNumber, then simply change the line:
If (Users(j).UserName < Users(i).UserName) Then
to
If (Users(j).AdminNumber < Users(i).AdminNumber) Then
Private Sub SplitAndAdd(listStackUser As String)
Dim strCode As String
Dim Users() As UserDesc
Dim TmpUser As UserDesc
Dim UsersCount As Long
Dim i As Long
Dim j As Long
i = 0
UsersCount = 0
Do While (True) ' inifinite loop until end of list
On Error Resume Next
Err.Number = 0
strCode = Split(listStackUser, "|")(i)
If (Err.Number = 0) Then
If (Trim(strCode) <> "") Then
ReDim Preserve Users(UsersCount + 1)
Users(UsersCount).UserName
Users(UsersCount).AdminNum
UsersCount = UsersCount + 1
End If
Else
Exit Do
End If
i = i + 1
Loop
' sort the array
For i = 0 To UsersCount - 2
For j = i + 1 To UsersCount - 1
If (Users(j).UserName < Users(i).UserName) Then
' swap the 2 users
TmpUser = Users(j).UserName
Users(j).UserName = Users(i).UserName
Users(i).UserName = TmpUser
End If
Next j
Next i
' now add items to the list
For i = 0 To UsersCount - 1
lstUsersClient.ListItems.A
Next i
End Sub
if you want to sort by AdminNumber, then simply change the line:
If (Users(j).UserName < Users(i).UserName) Then
to
If (Users(j).AdminNumber < Users(i).AdminNumber) Then
he doesnt want sorting of username
he wants sorting of the picture's, therefore a bubble sort. im working on it right now.
he wants sorting of the picture's, therefore a bubble sort. im working on it right now.
You might not have to do the sorting beforehand. Listview control might already have sort option. Just investigate about that. Good Luck!
ASKER
Developer comes before Admins.
Zot, u want 2 columns in the listview, 1 for Username 1 for Picture, then in the picture one, sort by descending
i think.. maybe ascending owell, try them.
i think.. maybe ascending owell, try them.
OK, here is the updated code with imagenumber.
Private Type UserDesc
UserName As String
AdminNumber As String
ImageNumber As Long
End Type
Private Sub SplitAndAdd(listStackUser As String)
Dim strCode As String
Dim Users() As UserDesc
Dim TmpUser As UserDesc
Dim UsersCount As Long
Dim i As Long
Dim j As Long
i = 0
UsersCount = 0
Do While (True) ' inifinite loop until end of list
On Error Resume Next
Err.Number = 0
strCode = Split(listStackUser, "|")(i)
If (Err.Number = 0) Then
If (Trim(strCode) <> "") Then
ReDim Preserve Users(UsersCount + 1)
Users(UsersCount).UserName = Split(strCode, ",")(0)
Users(UsersCount).ImageNum ber = Val(Right(Users(UsersCount ).UserName , 1))
Users(UsersCount).UserName = Left(Users(UsersCount).Use rName, Len(Users(UsersCount).User Name) - 1)
Users(UsersCount).AdminNum ber = Split(strCode, ",")(1)
UsersCount = UsersCount + 1
End If
Else
Exit Do
End If
i = i + 1
Loop
' sort the array
For i = 0 To UsersCount - 2
For j = i + 1 To UsersCount - 1
If (Users(j).ImageNumber < Users(i).ImageNumber) Then
' swap the 2 users
TmpUser = Users(j).UserName
Users(j).UserName = Users(i).UserName
Users(i).UserName = TmpUser
End If
Next j
Next i
' now add items to the list
For i = 0 To UsersCount - 1
lstUsersClient.ListItems.A dd , , Users(i).UserName, , Users(i).AdminNumber
Next i
End Sub
Good Luck!
Private Type UserDesc
UserName As String
AdminNumber As String
ImageNumber As Long
End Type
Private Sub SplitAndAdd(listStackUser As String)
Dim strCode As String
Dim Users() As UserDesc
Dim TmpUser As UserDesc
Dim UsersCount As Long
Dim i As Long
Dim j As Long
i = 0
UsersCount = 0
Do While (True) ' inifinite loop until end of list
On Error Resume Next
Err.Number = 0
strCode = Split(listStackUser, "|")(i)
If (Err.Number = 0) Then
If (Trim(strCode) <> "") Then
ReDim Preserve Users(UsersCount + 1)
Users(UsersCount).UserName
Users(UsersCount).ImageNum
Users(UsersCount).UserName
Users(UsersCount).AdminNum
UsersCount = UsersCount + 1
End If
Else
Exit Do
End If
i = i + 1
Loop
' sort the array
For i = 0 To UsersCount - 2
For j = i + 1 To UsersCount - 1
If (Users(j).ImageNumber < Users(i).ImageNumber) Then
' swap the 2 users
TmpUser = Users(j).UserName
Users(j).UserName = Users(i).UserName
Users(i).UserName = TmpUser
End If
Next j
Next i
' now add items to the list
For i = 0 To UsersCount - 1
lstUsersClient.ListItems.A
Next i
End Sub
Good Luck!
ASKER
Dim Users() As UserDesc
User-defined type not defined
User-defined type not defined
well, my mistake again....correct the sorting to ....
' sort the array
For i = 0 To UsersCount - 2
For j = i + 1 To UsersCount - 1
If (Users(j).ImageNumber < Users(i).ImageNumber) Then
' swap the 2 users
TmpUser = Users(j)
Users(j) = Users(i)
Users(i) = TmpUser
End If
Next j
Next i
' sort the array
For i = 0 To UsersCount - 2
For j = i + 1 To UsersCount - 1
If (Users(j).ImageNumber < Users(i).ImageNumber) Then
' swap the 2 users
TmpUser = Users(j)
Users(j) = Users(i)
Users(i) = TmpUser
End If
Next j
Next i
well, my mistake again....correct the sorting to ....
' sort the array
For i = 0 To UsersCount - 2
For j = i + 1 To UsersCount - 1
If (Users(j).ImageNumber < Users(i).ImageNumber) Then
' swap the 2 users
TmpUser = Users(j)
Users(j) = Users(i)
Users(i) = TmpUser
End If
Next j
Next i
' sort the array
For i = 0 To UsersCount - 2
For j = i + 1 To UsersCount - 1
If (Users(j).ImageNumber < Users(i).ImageNumber) Then
' swap the 2 users
TmpUser = Users(j)
Users(j) = Users(i)
Users(i) = TmpUser
End If
Next j
Next i
ASKER
Type mismatch
TmpUser = Users(j).UserName
with
TmpUser =
highlighted
TmpUser = Users(j).UserName
with
TmpUser =
highlighted
well, my mistake again....correct the sorting to ....
' sort the array
For i = 0 To UsersCount - 2
For j = i + 1 To UsersCount - 1
If (Users(j).ImageNumber < Users(i).ImageNumber) Then
' swap the 2 users
TmpUser = Users(j)
Users(j) = Users(i)
Users(i) = TmpUser
End If
Next j
Next i
' sort the array
For i = 0 To UsersCount - 2
For j = i + 1 To UsersCount - 1
If (Users(j).ImageNumber < Users(i).ImageNumber) Then
' swap the 2 users
TmpUser = Users(j)
Users(j) = Users(i)
Users(i) = TmpUser
End If
Next j
Next i
well, my mistake again....correct the sorting to ....
' sort the array
For i = 0 To UsersCount - 2
For j = i + 1 To UsersCount - 1
If (Users(j).ImageNumber < Users(i).ImageNumber) Then
' swap the 2 users
TmpUser = Users(j)
Users(j) = Users(i)
Users(i) = TmpUser
End If
Next j
Next i
' sort the array
For i = 0 To UsersCount - 2
For j = i + 1 To UsersCount - 1
If (Users(j).ImageNumber < Users(i).ImageNumber) Then
' swap the 2 users
TmpUser = Users(j)
Users(j) = Users(i)
Users(i) = TmpUser
End If
Next j
Next i
Option Explicit
Private Type USER_NAME_AND_PIC
UserName As String
PicIndex As Integer
End Type
Dim UserNameArray() As USER_NAME_AND_PIC
Private Sub cmdParse_Click()
CreateUserNameArray
AddToList
End Sub
Private Sub CreateUserNameArray()
Dim tmpArray() As String
Dim i As Integer
tmpArray = Split(txtParseMe, "|", -1)
ReDim Preserve UserNameArray(0 To UBound(tmpArray))
For i = 0 To UBound(tmpArray) - 1
With UserNameArray(i)
.UserName = Left(tmpArray(i), (InStr(1, tmpArray(i), ",", vbTextCompare)) - 1)
.PicIndex = Mid(tmpArray(i), Len(UserNameArray(i).UserN ame) + 2, Len(tmpArray(i)))
End With
Next i
End Sub
Private Function AddToList()
Dim i As Integer
Dim intIndex As Integer
Dim HighIndex As Integer
For i = 0 To UBound(UserNameArray) - 1
With UserNameArray(i)
If .PicIndex > HighIndex Then HighIndex = .PicIndex
End With
Next i
For intIndex = 0 To HighIndex
For i = 0 To UBound(UserNameArray) - 1
With UserNameArray(i)
If .PicIndex = intIndex Then
lstUsersClient.ListItems.A dd , , .UserName, .PicIndex, .PicIndex
End If
End With
Next i
Next intIndex
End Function
Private Type USER_NAME_AND_PIC
UserName As String
PicIndex As Integer
End Type
Dim UserNameArray() As USER_NAME_AND_PIC
Private Sub cmdParse_Click()
CreateUserNameArray
AddToList
End Sub
Private Sub CreateUserNameArray()
Dim tmpArray() As String
Dim i As Integer
tmpArray = Split(txtParseMe, "|", -1)
ReDim Preserve UserNameArray(0 To UBound(tmpArray))
For i = 0 To UBound(tmpArray) - 1
With UserNameArray(i)
.UserName = Left(tmpArray(i), (InStr(1, tmpArray(i), ",", vbTextCompare)) - 1)
.PicIndex = Mid(tmpArray(i), Len(UserNameArray(i).UserN
End With
Next i
End Sub
Private Function AddToList()
Dim i As Integer
Dim intIndex As Integer
Dim HighIndex As Integer
For i = 0 To UBound(UserNameArray) - 1
With UserNameArray(i)
If .PicIndex > HighIndex Then HighIndex = .PicIndex
End With
Next i
For intIndex = 0 To HighIndex
For i = 0 To UBound(UserNameArray) - 1
With UserNameArray(i)
If .PicIndex = intIndex Then
lstUsersClient.ListItems.A
End If
End With
Next i
Next intIndex
End Function
Replace txParseMe with listStackUser
ASKER
No errors now. But still no names, and no icons!
Is the listview even setup properly?
with an imagelist and indexes and stuff?
well, my mistake again....correct the sorting to ....
' sort the array
For i = 0 To UsersCount - 2
For j = i + 1 To UsersCount - 1
If (Users(j).ImageNumber < Users(i).ImageNumber) Then
' swap the 2 users
TmpUser = Users(j)
Users(j) = Users(i)
Users(i) = TmpUser
End If
Next j
Next i
' sort the array
For i = 0 To UsersCount - 2
For j = i + 1 To UsersCount - 1
If (Users(j).ImageNumber < Users(i).ImageNumber) Then
' swap the 2 users
TmpUser = Users(j)
Users(j) = Users(i)
Users(i) = TmpUser
End If
Next j
Next i
ASKER
Type mismatch
.PicIndex = Mid(tmpArray(i), Len(UserNameArray(i).UserN ame) + 2, Len(tmpArray(i)))
.PicIndex = Mid(tmpArray(i), Len(UserNameArray(i).UserN
Zot, do u have an image list all setup, or another way to put images into your ListView?
well, my mistake again....correct the sorting to ....
' sort the array
For i = 0 To UsersCount - 2
For j = i + 1 To UsersCount - 1
If (Users(j).ImageNumber < Users(i).ImageNumber) Then
' swap the 2 users
TmpUser = Users(j)
Users(j) = Users(i)
Users(i) = TmpUser
End If
Next j
Next i
' sort the array
For i = 0 To UsersCount - 2
For j = i + 1 To UsersCount - 1
If (Users(j).ImageNumber < Users(i).ImageNumber) Then
' swap the 2 users
TmpUser = Users(j)
Users(j) = Users(i)
Users(i) = TmpUser
End If
Next j
Next i
Zot,
I have tested the code aboce and it works
Try it
I have tested the code aboce and it works
Try it
you need to have already an imagelist right John?
ASKER
Type mismatch
.PicIndex = Mid(tmpArray(i), Len(UserNameArray(i).UserN ame) + 2, Len(tmpArray(i)))
.PicIndex = Mid(tmpArray(i), Len(UserNameArray(i).UserN
well, my mistake again....correct the sorting to ....
' sort the array
For i = 0 To UsersCount - 2
For j = i + 1 To UsersCount - 1
If (Users(j).ImageNumber < Users(i).ImageNumber) Then
' swap the 2 users
TmpUser = Users(j)
Users(j) = Users(i)
Users(i) = TmpUser
End If
Next j
Next i
' sort the array
For i = 0 To UsersCount - 2
For j = i + 1 To UsersCount - 1
If (Users(j).ImageNumber < Users(i).ImageNumber) Then
' swap the 2 users
TmpUser = Users(j)
Users(j) = Users(i)
Users(i) = TmpUser
End If
Next j
Next i
John, i dont know much about ListView's.
What settings must it have so i can use like List1.Additem
when i use lstUsersClient.ListItems.A dd i + 1, "abc", UserNameArray(i)
it only adds the first one and the rest it ignores!
What settings must it have so i can use like List1.Additem
when i use lstUsersClient.ListItems.A
it only adds the first one and the rest it ignores!
ASKER
Type mismatch
.PicIndex = Mid(tmpArray(i), Len(UserNameArray(i).UserN ame) + 2, Len(tmpArray(i)))
.PicIndex = Mid(tmpArray(i), Len(UserNameArray(i).UserN
well, my mistake again....correct the sorting to ....
' sort the array
For i = 0 To UsersCount - 2
For j = i + 1 To UsersCount - 1
If (Users(j).ImageNumber < Users(i).ImageNumber) Then
' swap the 2 users
TmpUser = Users(j)
Users(j) = Users(i)
Users(i) = TmpUser
End If
Next j
Next i
' sort the array
For i = 0 To UsersCount - 2
For j = i + 1 To UsersCount - 1
If (Users(j).ImageNumber < Users(i).ImageNumber) Then
' swap the 2 users
TmpUser = Users(j)
Users(j) = Users(i)
Users(i) = TmpUser
End If
Next j
Next i
I am sorry about the multiple postings...I been refreshing my window to see if there are any updates and just now found out that it was resending my previous posting.....
hahahah and when it gave u that window, u pressed Retry?
yeap, at least I know now not to do that. I learn a very good leason from that. I am new to this website and do not know that. It is only my 2nd day today. Anyway, hope you have solved your problem.
Are you sure you are using ListView and List
It is found in common controls 6
John i finally got ListView working after finding out index meant which column index.
Now i have 1 Column for Username and 1 column for Picture ID.
Now i have 1 Column for Username and 1 column for Picture ID.
Description of use for previous posting.
Create new exe
Goto projects -> components -> Microsoft common controls 6
Add a textbox (txtParseMe) that I added your string to
A Command button cmdParse
An ImageList with three pictures added to it
Add a listView lstUsersClient
With lstUsersClient click right mouse and properties
Goto the image list tab and pick imagelist1 from the top two combos.
Create new exe
Goto projects -> components -> Microsoft common controls 6
Add a textbox (txtParseMe) that I added your string to
A Command button cmdParse
An ImageList with three pictures added to it
Add a listView lstUsersClient
With lstUsersClient click right mouse and properties
Goto the image list tab and pick imagelist1 from the top two combos.
Is it working as you hoped
When I ran the test I did not use the column propertys and got a ListView similar to the one that appears when you click File - > New in MsWord
damn listview isnt showing the images from the imagelist but its making the 32x32 space thats how big the images are...
its annoying how it doesnt ever work for me for like 5 hours
its annoying how it doesnt ever work for me for like 5 hours
Opps, i didnt goto View and select SmallIcons or anything else. i got it working now
Hi Zot,
It appears that you have forgotten to close this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:
Split points between: tWiZtEr_RX and supunr
Zot, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you. DO NOT accept THIS comment as an answer.
EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
It appears that you have forgotten to close this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:
Split points between: tWiZtEr_RX and supunr
Zot, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you. DO NOT accept THIS comment as an answer.
EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
Are you asking to sort on the UserName's Image number?
thats not hard, but if u want to sort with usernames:
Dev
Admin
Peon
firstly, then anything goes secondly, that would be harder. but im just not sure what you want.