Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Sorting

Posted on 1999-09-27
12
Medium Priority
?
224 Views
Last Modified: 2010-05-02
My rich textbox imports a file containing random (seperated by tabs, commas, new lines etc.) phrases and sentences. I have written a function that will place these phrases/sentences in alphabetical order. However after the sort function is completed, the sorted text appears half way down the rtb box, requiring the user to scroll down.
How can I get the sorted text to appear at the top of the rtb box ?
0
Comment
Question by:fire99
[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
  • Learn & ask questions
  • 5
  • 2
  • 2
  • +3
12 Comments
 
LVL 12

Expert Comment

by:mark2150
ID: 2078130
You've got a bunch of blanks in the RTB.

Don't add if LEN(TRIM()) < 1

M
0
 
LVL 2

Expert Comment

by:srirambm
ID: 2079124
well does mark's solution work ? it has to be the problem
0
 
LVL 3

Expert Comment

by:troywillmot
ID: 2079754
You could also try using LTRIM on the text box contents, that should get rid of any spaces, you could also right a loop that specifically removed vbCrLf's from the text box.

Marks solution should work, unless the lines have vbCrLf's in them, in which case the line will appear blank, but its length will be 2, you could modify Marks code so it was

Don't add if LEN(TRIM())<1 or LEN(TRIM())=vbCrLf
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 12

Expert Comment

by:mark2150
ID: 2080016
Actually if he's doing LINE INPUT from a file, the vbCRLF are not counted as part of each line...

M
0
 
LVL 3

Expert Comment

by:troywillmot
ID: 2080045
Good point, is he using line input ? Regardless, the trim/ltrim should help.

Its been a while since I worked with sequential files like that (my boss insists on using the scripting runtime 'because objects are cool'), so I forgot about line input. You are right though.
0
 

Author Comment

by:fire99
ID: 2081001
This is my code :

Private Sub Sort()
Dim Marker1 As Integer

     'determine number of lines in rtb box object
lineCount% = 0  'this variable holds the total number of lines
charsInFile% = Len(RichTextBox1.Text)  'get total characters in box
For i% = 1 To charsInFile%  'move one char at a time through box
    letter$ = Mid(RichTextBox1.Text, i%, 1) 'put next char in letter$
    If letter$ = Chr$(13) Then 'if carriage ret found (end of line!)
        lineCount% = lineCount% + 1  'go to next line (add to count)
        i% = i% + 1   'skip linefeed char (which always follows cr)
    End If
Next i%

'build an array to hold the text in the text box
ReDim strArray$(lineCount%) 'create array of proper size
curline% = 1
ln$ = ""  'use ln$ to build lines one character at a time
For i% = 1 To charsInFile%     'loop through text again
    letter$ = Mid(RichTextBox1.Text, i%, 1)
    If letter$ = Chr$(13) Then 'if carriage return found
        curline% = curline% + 1    'increment line count
        i% = i% + 1            'skip linefeed char
        ln$ = ""               'clear line and go to next
    Else
        ln$ = ln$ & letter$    'add letter to line
        strArray$(curline%) = ln$  'and put in array
   End If
Next i%

'sort array
ShellSort strArray$(), lineCount%

'then display sorted array in text box

RichTextBox1.Text = ""
Wrap$ = Chr$(13) & Chr$(10)
curline% = 1
For i% = 1 To lineCount%
    RichTextBox1.Text = RichTextBox1.Text & strArray$(curline%) & Wrap$
    curline% = curline% + 1
Next i%


End Sub
0
 
LVL 12

Expert Comment

by:mark2150
ID: 2081057
Try this:

For i% = 1 To charsInFile%     'loop through text again
    letter$ = Mid(RichTextBox1.Text, i%, 1)
    If letter$ = vbCR Then 'if carriage return found
        ln$ = trim(ln$)
        if len(ln$) > 0 then
          strArray$(curline%) = ln$  'and put in array
          curline% = curline% + 1    'increment line count
          i% = i% + 1            'skip linefeed char
          ln$ = ""               'clear line and go to next
        endif
    Else
        ln$ = ln$ & letter$    'add letter to line
   End If
Next i%

M
0
 

Author Comment

by:fire99
ID: 2081097
Thanks M
How about some points ?
0
 
LVL 12

Expert Comment

by:mark2150
ID: 2083137
No prob. Reject Troywilmott's A and I'll post for points! Thanx!

M
0
 
LVL 12

Accepted Solution

by:
mark2150 earned 960 total points
ID: 2086116
Thank You!

M
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6861779
This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects the problem and the expert will now receive these points; points verified.

Please click on your Member Profile and select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.  If you are an EE Pro user, you can also choose Power Search to find all your open questions.

This is the Community Support link, if help is needed, along with the link to All Topics which reflects many TAs recently added.

http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
http://www.experts-exchange.com/jsp/zonesAll.jsp

In efforts to help all Members maintain their open questions, this is a reminder to click your Member Profile, expand your question history and find/update all your Open and Locked questions.
 
Thank you,
Moondancer
Moderator @ Experts Exchange
0
 

Expert Comment

by:mjr896
ID: 10589581
How could i get a file sorted from numbers like say from 1 to like 100 and then call then ordered numbers into my program



>>SRRY FOR THE INTRUSION FIRE99
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question