[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
Solved

# Hi, if I have a list of words (see below), how can I add them into an array in order and no duplicate?

Posted on 2003-12-11
Medium Priority
239 Views
Hi, if I have a list of words (see below), how can I add them into an array in order and no duplicate?

abc
bbb
djs
opl
abc
knda
bbb
opl
vvv
0
Question by:musclejack
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 3

LVL 6

Accepted Solution

prasitlee earned 2000 total points
ID: 9924754
Dear musclejack,
Try the following code. I am strongly sure that my code would answer your problem.

Option Explicit

Private Sub Command1_Click()

Dim arrMeng As Variant
Dim i As Integer
Dim strMeng As String

arrMeng = Array("abc", "bbb", "djs", "opl", "abc", "knda", "bbb", "opl", "vvv")

QuickSort arrMeng
strMeng = ""
For i = 0 To UBound(arrMeng)
strMeng = strMeng & arrMeng(i) & vbTab
Next i

MsgBox strMeng

End Sub
Sub QuickSort(arr As Variant, Optional numEls As Variant, _
Optional descending As Boolean)

Dim value As Variant, temp As Variant
Dim sp As Integer
Dim leftStk(32) As Long, rightStk(32) As Long
Dim leftNdx As Long, rightNdx As Long
Dim i As Long, j As Long
Dim k As Long
Dim strPrevious As String
Dim strCurrent As String
Dim colTemp As Collection

' account for optional arguments
If IsMissing(numEls) Then numEls = UBound(arr)
' init pointers
leftNdx = LBound(arr)
rightNdx = numEls
' init stack
sp = 1
leftStk(sp) = leftNdx
rightStk(sp) = rightNdx

Do
If rightNdx > leftNdx Then
value = arr(rightNdx)
i = leftNdx - 1
j = rightNdx
' find the pivot item
If descending Then
Do
Do: i = i + 1: Loop Until arr(i) <= value
Do: j = j - 1: Loop Until j = leftNdx Or arr(j) >= value
temp = arr(i)
arr(i) = arr(j)
arr(j) = temp
Loop Until j <= i
Else
Do
Do: i = i + 1: Loop Until arr(i) >= value
Do: j = j - 1: Loop Until j = leftNdx Or arr(j) <= value
temp = arr(i)
arr(i) = arr(j)
arr(j) = temp
Loop Until j <= i
End If
' swap found items
temp = arr(j)
arr(j) = arr(i)
arr(i) = arr(rightNdx)
arr(rightNdx) = temp
' push on the stack the pair of pointers that differ most
sp = sp + 1
If (i - leftNdx) > (rightNdx - i) Then
leftStk(sp) = leftNdx
rightStk(sp) = i - 1
leftNdx = i + 1
Else
leftStk(sp) = i + 1
rightStk(sp) = rightNdx
rightNdx = i - 1
End If
Else
' pop a new pair of pointers off the stacks
leftNdx = leftStk(sp)
rightNdx = rightStk(sp)
sp = sp - 1
If sp = 0 Then Exit Do
End If
Loop

Set colTemp = New Collection
strPrevious = ""
For k = 0 To UBound(arr)
strCurrent = arr(k)
If strCurrent = strPrevious Then
Else
End If
strPrevious = strCurrent
Next k

ReDim arr(colTemp.Count)

For k = 1 To colTemp.Count
strCurrent = colTemp.Item(k)
arr(k - 1) = strCurrent
Next k

End Sub

0

Author Comment

ID: 9925482
Can you show me the ASP version ?
0

LVL 6

Expert Comment

ID: 9926179
Dear musclejack,
I am not sure if I could write this program in ASP or not. Anyway I would try to modify but it take a little bit time to change. I would tell you the progress later. If you would like to get the faster result, you might need to post this question into the Web Programming Session.
Meng
0

LVL 6

Expert Comment

ID: 9926278
Dear musclejack,
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?lngWId=4&txtCodeId=6495
You might need to modify a little bit further.
Any comment, please let me know.
Meng
0

## Featured Post

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
###### Suggested Courses
Course of the Month13 days, 8 hours left to enroll