Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2006

Tip: Looking for answers? Try searching our database.

Variable Problem.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tim - 22 Jan 2006 16:52 GMT
Hi folks,

I need a help for my top problem.  I spend a lot of time but I can't find a
solution for it.  The following is my sample of my code.  I want to sort the
value of str in ascending and the max value of str.  Any help will be
appreciated.

Thanks in advance.

Tim.

Example:

Dim str As String

str = ("9, 5, 8, 3, 1, 6")

MsgBox str
Ron Rosenfeld - 22 Jan 2006 17:20 GMT
>Hi folks,
>
[quoted text clipped - 14 lines]
>
>MsgBox str

Here's one way, if you have VBA6 or later:

=================================
Option Explicit

Sub foo()
Dim str As String
Dim TempArray As Variant, Temp As Variant
Dim i As Integer
Dim NoExchanges As Integer

str = ("9, 5, 8, 3, 1, 6")
TempArray = Split(str, ", ")

   ' Loop until no more "exchanges" are made.
   Do
       NoExchanges = True

       ' Loop through each element in the array.
       For i = 0 To UBound(TempArray) - 1

           ' If the element is greater than the element
           ' following it, exchange the two elements.
           If TempArray(i) > TempArray(i + 1) Then
               NoExchanges = False
               Temp = TempArray(i)
               TempArray(i) = TempArray(i + 1)
               TempArray(i + 1) = Temp
           End If
       Next i
   Loop While Not (NoExchanges)
   
str = Join(TempArray, ", ")

MsgBox (str & vbLf & "Max Value:  " & TempArray(UBound(TempArray)))
End Sub
===============================

--ron
Tim - 23 Jan 2006 06:31 GMT
Hi Ron,

Thank you very much for your code.  I have another question regarding the
code.  How to sort the alphabet and date?  Please help.

For example:

str = ("12/1/06, 12/15/05, 1/1/05, 10/10/05")

or

str = ("Peter Smith, John betz, John bocco")

Thanks in advance.

Tim.

> >Hi folks,
> >
[quoted text clipped - 54 lines]
>
> --ron
Ron Rosenfeld - 23 Jan 2006 13:04 GMT
>Hi Ron,
>
[quoted text clipped - 12 lines]
>
>Tim.

What was the problem with the sort you obtained when you tried those values for
str?
--ron
Tim - 23 Jan 2006 16:10 GMT
Hi Ron,

When I ran the code with the following str (date), I got the result like
this:  1/1/05, 10/10/05, 12/1/06, 12/15/05 Max Value:  12/15/05.  I am
expecting 12/1/06 is the last value but it is not.

str = ("12/1/06, 12/15/05, 1/1/05, 10/10/05")

Please help.

Thanks in advance.

Tim.

> >Hi Ron,
> >
[quoted text clipped - 16 lines]
> str?
> --ron
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.