Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Please Help Me
#1
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
PRINT
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
Reply
#2
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
DIM SHARED grid.name$(1 to grid.length%), grid.address$(1 to grid.length%), grid.id%(1 to grid.length%), grid.gender%(1 to grid.length%), grid.hourlysalary&(1 to grid.length%)

DIM SHARED gender.type$(1 TO 2)

gender.type$(1) = "Male"
gender.type$(2) = "Female"

FOR i% = 1 TO grid.length%
PRINT grid.name$(i%)
PRINT grid.address$(i%)
PRINT grid.id%(i%)
PRINT gender.type$(grid.gender%(i%))
PRINT grid.hourlysalary&(i%)
NEXT i%

PS: use [ code ] and [/ code ] tags for your code. (without the spaces)
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#3
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....
Reply
#4
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. Smile
I'd knock on wood, but my desk is particle board.
Reply
#5
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...
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#6
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
Reply
#7
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%)
DIM g2(1 TO a.max%) AS INTEGER, h2(1 TO a.max%) AS INTEGER, i AS INTEGER, j AS INTEGER, k AS INTEGER, r AS INTEGER, e AS INTEGER, g AS INTEGER, h AS INTEGER
e = 1: g2(1) = 1: h2(1) = a.max%
1 g = g2(e): h = h2(e)
2 i = g: j = h: r = (g + h) \ 2: k = array1(r)
3 IF array1(i) < k THEN i = i + 1: GOTO 3 'set 3 to < and 4 to > for low to high. Set 3 to > and 4 to < for high to low.
4 IF array1(j) > k THEN j = j - 1: GOTO 4
IF i <= j THEN SWAP array1(i), array1(j): i = i + 1: j = j - 1
IF i <= j THEN GOTO 3
IF j - g + i < h THEN
IF i < h THEN g2(e) = i: h2(e) = h: e = e + 1
h = j
ELSE
IF g < j THEN g2(e) = g: h2(e) = j: e = e + 1
g = i
END IF
IF g < h THEN GOTO 2 ELSE e = e - 1: IF e THEN GOTO 1
END SUB
ERASE g2, h2

Here is a much much MUCH slower but easier to understand routine:

Code:
FOR i% = 1 to 100
FOR j% = 1 TO i% - 1
IF array1(j%) > array1(i%) THEN SWAP array1(j%), array1(i%)
NEXT j%, i%

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
FOR j% = 1 TO i% - 1
IF array1(j%) > array1(i%) THEN
SWAP array1(j%), array1(i%)
SWAP names(j%), names%(i%)
SWAP bla(j%), bla%(i%)
END IF
NEXT j%, i%

Same thing for the other piece of code.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#8
Can u help me sort it by the variables i have instead of having like i, j, and k....Thanx....
Reply
#9
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.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#10
Im confused i dont know which ones to change though....Could u help....Im a real newb....lol....Thanx
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)