Solved

Sort dbf file with Visual Basic 6 vb6?

Posted on 2010-11-14
10
804 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to With line 4 57
vbModal 12 51
constraint check 2 40
T-SQL Default value in Select? 5 26
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

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