Please Help Me - Printable Version +- Qbasicnews.com (http://qbasicnews.com/newforum) +-- Forum: QBasic (http://qbasicnews.com/newforum/forum-4.html) +--- Forum: QB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-11.html) +--- Thread: Please Help Me (/thread-2552.html) |
Please Help Me - HPLilSnowHP - 11-22-2003 Ok i have having trouble printing this neatly and also sorting it....I have to have the user choose whether or not he wants to sort by name, address, id number, gender, or hourly salary....Oh yea and each grid as information in it....Thanks.... Heres the code: DECLARE SUB Information () DECLARE SUB Display () DIM SHARED Grid$(1 TO 11, 1 TO 5) CALL Information CALL Display SUB Display FOR row = 1 TO 1 FOR col = 1 TO 5 PRINT Grid$(row, 1); Grid$(row, 2); Grid$(row, 3) 'On until Grid$(row, 5) NEXT NEXT END SUB SUB Information CLS FOR row = 1 TO 5 FOR col = 1 TO 11 Grid$(1, 1) = Grid$(1, 2) = Grid$(1, 3) = Grid$(1, 4) = Grid$(1, 5) = Grid$(2, 1) = Grid$(2, 2) = Grid$(2, 3) = Grid$(2, 4) = Grid$(2, 5) = Grid$(3, 1) = Grid$(3, 2) = Grid$(3, 3) = Grid$(3, 4) = Grid$(3, 5) = Grid$(4, 1) = Grid$(4, 2) = Grid$(4, 3) = Grid$(4, 4) = Grid$(4, 5) = Grid$(5, 1) = Grid$(5, 2) = Grid$(5, 3) = Grid$(5, 4) = Grid$(5, 5) = Grid$(6, 1) = Grid$(6, 2) = Grid$(6, 3) = Grid$(6, 4) = Grid$(6, 5) = Grid$(7, 1) = Grid$(7, 2) = Grid$(7, 3) = Grid$(7, 4) = Grid$(7, 5) = Grid$(8, 1) = Grid$(8, 2) = Grid$(8, 3) = Grid$(8, 4) = Grid$(8, 5) = Grid$(9, 1) = Grid$(9, 2) = Grid$(9, 3) = Grid$(9, 4) = Grid$(9, 5) = Grid$(10, 1) = Grid$(10, 2) = Grid$(10, 3) = Grid$(10, 4) = Grid$(10, 5) = Grid$(11, 1) = Grid$(11, 2) = Grid$(11, 3) = Grid$(11, 4) = Grid$(11, 5) = NEXT NEXT END SUB Please Help Me - Agamemnus - 11-22-2003 You need 5 separate arrays. ID, gender, and hourly salary should be strings. How do you sort addresses? Which parts? Alphabetically..? It would be nice if you gave actual data, too. So to print it, try something like this, with the following different variable names: Code: grid.length% = 5 PS: use [ code ] and [/ code ] tags for your code. (without the spaces) Please Help Me - HPLilSnowHP - 11-22-2003 Im just confused on sorting them....Like when u run the program its comes up with a menu saying which do u wanna sort by....name, address, id number, gender, or hourly salary....Then the user inputs number of whichever he chooses to sort by then it sorts them by it in ascending order.... Please Help Me - adosorken - 11-22-2003 It's too bad no one uses Power Basic...it has built-in array sorting. HPLilSnowHP, what you probably want to look into is called a bubble sort algorithm. I'm not sure off the top of my head how to do it but information is easily found on google. Please Help Me - Agamemnus - 11-22-2003 First of all, get the rest of your program set up, and I'll show you how to sort your variables both alphabetically and numerically... Please Help Me - HPLilSnowHP - 11-22-2003 Ok, I have my program printing now how i want it....Now im just confused on sorting....I have to make a menu that askes the user which he wants to sort from....Either name, address, id number, gender, or hourly salary....Thanks for the help Please Help Me - Agamemnus - 11-22-2003 I haven't gotten around to making a fast alphabetic string sort yet, but here is a fast (quicksort) numeric sort SUB: Code: SUB qsort.lowstart (array1() AS INTEGER, a.max%) Here is a much much MUCH slower but easier to understand routine: Code: FOR i% = 1 to 100 EDIT: Oh, and, if you want to sort everything according to one attribute, you have to swap everything when you swap that attribute, like so: Code: FOR i% = 1 to 100 Same thing for the other piece of code. Please Help Me - HPLilSnowHP - 11-22-2003 Can u help me sort it by the variables i have instead of having like i, j, and k....Thanx.... Please Help Me - Agamemnus - 11-22-2003 I, J, and K stay. They are not the array but counter variables... read the code closely. What you need to change is "array1" to your array variable name, for instance... In the first example, all you need to do is insert it and invoke it like so: qsort.lowstart grid.id(), grid.length% (All your variables need to be declared as global, or DIM SHARED!) EDIT: I just tested the second sort technique with strings, and it works. So all you need to do is just copy that code 5 times and substitute your array names in. Please Help Me - HPLilSnowHP - 11-22-2003 Im confused i dont know which ones to change though....Could u help....Im a real newb....lol....Thanx |