Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with a database program

Status
Not open for further replies.

Grizant

Programmer
Oct 6, 2002
7
0
0
US
I need help with two things, I nedd to incorporate a bubble sort that need to rearrange the entries in both arrays. Also Ive tried to use a search but it didnt work, So any help with a sequential search would be a big help. Heres some of the code.

INCLUDE Irvine16.inc

.DATA


.CODE
Driver PROC
MOV AX, @DATA
MOV DS, AX
TOP:
CALL DisplayMenu
CALL GetChoice
CHECK1:
CMP EAX, 1
JNE CHECK2
CALL Init
JMP TOP
CHECK2:
CMP EAX, 2
JNE CHECK3
CALL Insert
JMP TOP
CHECK3:
CMP EAX, 3
JNE CHECK4
CALL Display
JMP TOP
CHECK4:
CMP EAX, 4
JNE CHECK5
CALL FindEid
JMP TOP
CHECK5:
CMP EAX, 5
JNE CHECK6
CALL FindSsn
JMP TOP
CHECK6:
CMP EAX, 6
JNE CHECK7
CALL Delete
JMP TOP
CHECK7:
CMP EAX, 7
JNE CHECK8
CALL SortEid
JMP TOP
CHECK8:
CMP EAX, 8
JNE CHECK9
CALL SortSsn
JMP TOP
CHECK9:
CALL Quit

exit

Driver ENDP


;--------------------------------------------------------------------
;
;--------------------------------------------------------------------
DisplayMenu PROC USES EDX
.DATA
menuLine1 BYTE "1. Initialize database", 0
menuLine2 BYTE "2. Insert employee", 0
menuLine3 BYTE "3. Display all data", 0
menuLine4 BYTE "4. Search on EID", 0
menuLine5 BYTE "5. Search on SSN", 0
menuLine6 BYTE "6. Delete employee", 0
menuLine7 BYTE "7. Sort by EID", 0
menuLine8 BYTE "8. Sort by SSN", 0
menuLine9 BYTE "9. Quit", 0
.CODE
CALL Crlf
MOV EDX, OFFSET menuLine1
CALL WriteString
CALL Crlf
MOV EDX, OFFSET menuLine2
CALL WriteString
CALL Crlf
MOV EDX, OFFSET menuLine3
CALL WriteString
CALL Crlf
MOV EDX, OFFSET menuLine4
CALL WriteString
CALL Crlf
MOV EDX, OFFSET menuLine5
CALL WriteString
CALL Crlf
MOV EDX, OFFSET menuLine6
CALL WriteString
CALL Crlf
MOV EDX, OFFSET menuLine7
CALL WriteString
CALL Crlf
MOV EDX, OFFSET menuLine8
CALL WriteString
CALL Crlf
MOV EDX, OFFSET menuLine9
CALL WriteString
CALL Crlf
RET
DisplayMenu ENDP


;--------------------------------------------------------------------
;
;--------------------------------------------------------------------
GetChoice PROC USES EDX
.DATA
prompt BYTE "Your choice? (1...9) ", 0
bad_choice BYTE "...invalid choice...try again...", 0
.CODE
TOP:
CALL Crlf
MOV EDX, OFFSET prompt
CALL WriteString
CALL ReadInt
JNC VALID_INT
INVALID_CHOICE:
CALL Crlf
MOV EDX, OFFSET bad_choice
CALL WriteString
CALL Crlf
JMP TOP
VALID_INT:
CALL Crlf
CMP EAX, 1
JL INVALID_CHOICE
CMP EAX, 9
JG INVALID_CHOICE
RET
GetChoice ENDP


;--------------------------------------------------------------------
;
;--------------------------------------------------------------------
ProcessChoice PROC
PUSHFD
CHECK1:
CMP EAX, 1
JNE CHECK2
CALL Init
JMP DONE
CHECK2:
CMP EAX, 2
JNE CHECK3
CALL Insert
JMP DONE
CHECK3:
CMP EAX, 3
JNE CHECK4
CALL Display
JMP DONE
CHECK4:
CMP EAX, 4
JNE CHECK5
CALL FindEid
JMP DONE
CHECK5:
CMP EAX, 5
JNE CHECK6
CALL FindSsn
JMP DONE
CHECK6:
CMP EAX, 6
JNE CHECK7
CALL Delete
JMP DONE
CHECK7:
CMP EAX, 7
JNE CHECK8
CALL SortEid
JMP DONE
CHECK8:
CMP EAX, 8
JNE CHECK9
CALL SortSsn
JMP DONE
CHECK9:
CALL Quit
DONE:
POPFD
RET
ProcessChoice ENDP


;--------------------------------------------------------------------
;
;--------------------------------------------------------------------
Init PROC
.DATA
initMsg BYTE "Hello from 'Init'", 0
.CODE
MOV EDX, OFFSET initMsg
CALL Crlf
CALL WriteString
CALL Crlf
RET
Init ENDP


;--------------------------------------------------------------------
;
;--------------------------------------------------------------------
Insert PROC
.DATA
insertMsg BYTE "Hello from 'Insert'", 0
.CODE
MOV EDX, OFFSET insertMsg
CALL Crlf
CALL WriteString
CALL Crlf
RET
Insert ENDP


;--------------------------------------------------------------------
;
;--------------------------------------------------------------------
Display PROC
.DATA
displayMsg BYTE "Hello from 'Display'", 0
.CODE
MOV EDX, OFFSET displayMsg
CALL Crlf
CALL WriteString
CALL Crlf
RET
Display ENDP


;--------------------------------------------------------------------
;
;--------------------------------------------------------------------
FindEid PROC
.DATA
findEidMsg BYTE "Hello from 'FindEid'", 0
.CODE
MOV EDX, OFFSET findEidMsg
CALL Crlf
CALL WriteString
CALL Crlf
RET
FindEid ENDP


;--------------------------------------------------------------------
;
;--------------------------------------------------------------------
FindSsn PROC
.DATA
findSsnMsg BYTE "Hello from 'FindSsn'", 0
.CODE
MOV EDX, OFFSET findSsnMsg
CALL Crlf
CALL WriteString
CALL Crlf
RET
FindSsn ENDP


;--------------------------------------------------------------------
;
;--------------------------------------------------------------------
Delete PROC
.DATA
deleteMsg BYTE "Hello from 'Delete'", 0
.CODE
MOV EDX, OFFSET deleteMsg
CALL Crlf
CALL WriteString
CALL Crlf
RET
Delete ENDP


;--------------------------------------------------------------------
;
;--------------------------------------------------------------------
SortEid PROC
.DATA
sortEidMsg BYTE "Hello from 'SortEid'", 0
.CODE
MOV EDX, OFFSET sortEidMsg
CALL Crlf
CALL WriteString
CALL Crlf
RET
SortEid ENDP


;--------------------------------------------------------------------
;
;--------------------------------------------------------------------
SortSsn PROC
.DATA
sortSsnMsg BYTE "Hello from 'SortSsn'", 0
.CODE
MOV EDX, OFFSET sortSsnMsg
CALL Crlf
CALL WriteString
CALL Crlf
RET
SortSsn ENDP


;--------------------------------------------------------------------
;
;--------------------------------------------------------------------
Quit PROC
.DATA
byeMsg BYTE "Bye...", 0
.CODE
MOV EDX, OFFSET byeMsg
CALL Crlf
CALL WriteString
CALL Crlf
RET
Quit ENDP


END Driver
 
Where's the array?

If you're doing a lot of repititive code, chances are you're doing it inefficiently.

Also, I suggest you sort INDEXES and not the actual records, moving records around can be *** time-consuming. "Information has a tendency to be free. Which means someone will always tell you something you don't want to know."
 
err... if I understand correctly you haven't sent us any code except the menu-reading bit.
You need to decide how to store your data. There are lots of possibilities, but AmkG is right to suggest you choose something where you don't need to move the actual text around when you sort.
You could try looking at the chapters on linked lists in any good textbook. These are sets of records consisting of all the data, plus pointers to the records "above" and "below" in the list. Well, that's doubly linked. There are also singly linked lists that contain just one pointer, the "next" in the list.
These are relatively easy to sort, because you only need to change the pointers, not move the whole data. For instance,
swapping two elements B&C in the list A,B,C,D is now a matter of setting A's "next" to point to C instead of B, C must point to B, and B must point to D. The rest of the list is unchanged.
You will probably find search algorithms too, which you can simply adapt.
Don't even think bubble-sort. It may be relatively easy to programme, but its performance is about as bad as a search routine can reasonably get. If you don't feel up to implementing quicksort, have a bash at shellsort.
Have fun.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top