Solved

Sort dbf file with Visual Basic 6 vb6?

Posted on 2010-11-14
10
785 Views
Last Modified: 2012-05-10
I have a simple application that loads a dbf file into a textbox.  It works fine but I would like to sort it by the field called "ID"

here is the top part of my app:

Private Sub cmdLoad_Click()
Dim errrr As Integer
Dim txtID As String
Dim txtShort As String
Dim db As Database
Dim rs As Recordset
errrr = EOFAction
Set db = OpenDatabase("Z:\aloha\vb\dbf", True, False, "dBASE IV;")
Set rs = db.OpenRecordset("ITM")
Do While Not errrr

txtID = rs.Fields("ID")
txtShort = rs.Fields("SHORTNAME")


textID.Text = textID.Text & txtID & vbNewLine
textShort.Text = textShort.Text & txtShort & vbNewLine
0
Comment
Question by:daneburr
10 Comments
 
LVL 25

Expert Comment

by:jogos
ID: 34134919
Before your loop.

rs.Sort = "ID"  
0
 
LVL 3

Expert Comment

by:Rincewindwizz
ID: 34134925
Well you can read the part of the dbf you want to display in the text box into an array and then sort it using one of the sort routines available on the www (e.g. http://www.source-code.biz/snippets/vbasic/1.htm or http://www.vb-helper.com/tut1.htm or http://www.blueclaw-db.com/quick-sort.htm) and then send the output to the text box

If the text box only displays small bits of the file, this will tend to be more efficient better than sorting the whole file.

The other obvious alternative is to use dBase functionality (sort or index) to produce a copy of the file in the desired order before reading it into your vb app.

Each has its pros and cons.

Good Luck


0
 
LVL 45

Accepted Solution

by:
aikimark earned 500 total points
ID: 34140072
Try this statement:

Set rs = db.OpenRecordset("Select * From ITM Order By ID")

Open in new window

0
 

Author Comment

by:daneburr
ID: 34146206
If I use Set rs = db.OpenRecordset(ITM, "Select * From ITM Order By ID")
it gives and error but during the debug stage if I delete " ITM," and continue to run it it works perfect.  Any ideas??
0
 
LVL 45

Expert Comment

by:aikimark
ID: 34146743
What error do you get?
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 45

Expert Comment

by:aikimark
ID: 34146792
Have you tried
"From ITM.DBF" ?
0
 

Author Comment

by:daneburr
ID: 34146817
When I use:
Set rs = db.OpenRecordset("ITM", "Select * From ITM Order By ID")

Runtime Error "3421"
Data Type Conversion Error

Runtime Error "3228"

Selected Collating sequence Not Supported by the operating system.

Then debug and take out "ITM",

And It works how I want
0
 

Author Comment

by:daneburr
ID: 34147393
If I use:
Set rs = db.OpenRecordset("Select * From ITM.DBF Order By ID")

I get this error:
Runtime Error "3228"
Selected Collating sequence Not Supported by the operating system.

But if I click the "Start" button in vb it continues and works.  So how can I get rid of the error?
0
 
LVL 45

Expert Comment

by:aikimark
ID: 34148272
If you compile the application, does it produce the 3228 error?

A work-around would be to trap errors before you instantiate the recordset.

On Error Resume Next

Open in new window

0
 

Author Comment

by:daneburr
ID: 34148696
Thanks aikimark,
No error after I compile the program.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now