?
Solved

Sort dbf file with Visual Basic 6 vb6?

Posted on 2010-11-14
10
Medium Priority
?
849 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
[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
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 46

Accepted Solution

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

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

Open in new window

0
Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

 

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 46

Expert Comment

by:aikimark
ID: 34146743
What error do you get?
0
 
LVL 46

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 46

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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

Make the most of your online learning experience.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
Introduction to Processes
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

770 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