Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Sort dbf file with Visual Basic 6 vb6?

Posted on 2010-11-14
10
Medium Priority
?
865 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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 

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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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…
Suggested Courses

636 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