Solved

Sort dbf file with Visual Basic 6 vb6?

Posted on 2010-11-14
10
817 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 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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
 
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
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 …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

730 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