LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

I need help data printing and sorting

Root / Programming Questions / [.]

Tiger2Created:
So, I was trying to figured out how to print my data, but when I sorted it with the sort command, the data appeared more than halfway down the screen and it only seemed to sort two of the data lines even though I specified from 0 to 28. The rest just seemed randomly placed.

This sounds like a specific problem. If you want specific help, you'll need to show the instructions you used.

There are kind of a lot of them. I used Dim first to set an array for the Data I then used restore, for-to-loop, then read After that I used Sort as in: SORT 0,28,ARRAY$ Then I used locate and the y position was done with the for to loop so it all printed. That's where sort was messing everything up. It all looks fine before I sorted it, but then when I sorted it all, it didn't sort everything and all the text appeared more than halfway down the screen.

Can you post the exact code? There shouldn't be any problems with what you described. If anything you may have overlooked your Y location.

ACLS
NM=28
STRNG=1

DIM PG1$[NM],PS1$[NM],TRNS1[NM]

@PRINT
RESTORE @DATA
  READ PG1[I],PS1[I],TRNS[I]
  SORT 0,NM,PG1$
  LOCATE 0,I
  PRINT PG1$[I]
  LOCATE 10,I
  PRINT PS1$[I]
  LOCATE 15,I
  PRINT TRNS1$[I]
NEXT
@DATA
I left out the data because I would be writing forever, but each is written like this:
DATA "ARI","n.","ant"

ACLS
NM=28
STRNG=1

DIM PG1$[NM],PS1$[NM],TRNS1[NM]

@PRINT
RESTORE "DATA
  READ PG1[I],PS1[I],TRNS[I]
  SORT 0,NM,PG1$
  LOCATE 0,I
  PRINT PG1$[I]
  LOCATE 10,I
  PRINT PS1$[I]
  LOCATE 15,I
  PRINT TRNS1$[I]
NEXT
@DATA
I left out the data because I would be writing forever, but each is written like this:
DATA "ARI","n.","ant"
I think you skipped a few lines of code there

ACLS
NM=28
STRNG=1
PG=0

DIM PG1$[NM],PS1$[NM],TRNS1[NM]

@PRINT
RESTORE "DATA
FOR I=0 TO PG+NM-1
  READ PG1[I],PS1[I],TRNS[I]
  SORT 0,NM,PG1$
  LOCATE 0,I
  PRINT PG1$[I]
  LOCATE 10,I
  PRINT PS1$[I]
  LOCATE 15,I
  PRINT TRNS1$[I]
NEXT
@DATA
I left out the data because I would be writing forever, but each is written like this:
DATA "ARI","n.","ant"
I think you skipped a few lines of code there
I fixed the restore thing, but everything should be right.

you have a NEXT without FOR

Oops. That problem does not exist in the actual thing, but I fixed it.

I read you code and I found the following problems. 1- You're calling sort with an array that doesn't contains all the elements. For example, if the data used by PG1$ are:
DATA "3","1","2"
Then the output of PG1$ will be
  'This line is empty because this belong to an unused space on the array.
1
2
You should call sort after reading all the data. 2- You're calling print without ";" at then end. If you don't put that character, then the text above will scroll up if you print something at the bottom of the screen.

But i tried putting the sort command after already. In my example, it is right after READ

OPTION STRICT

VAR PAGE_SIZE% = 28, START% = 0, I%
VAR WORD$, PART_OF_SPEECH$, TRANSLATION$
DIM WORDS$[0]
DIM PARTS_OF_SPEECH$[0]
DIM TRANSLATION$[0]

ACLS

'READ THE DATA - ALL of it.
'I changed some things. Now you put DATA "", "", "" at the end to signify the last data element. 
'This lets you have a dictionary of any size without hard coding a length.
RESTORE @DATA
REPEAT
	READ WORD$, PART_OF_SPEECH$, TRANSLATION$
	IF LEN(WORD$) + LEN(PART_OF_SPEECH$) + LEN(TRANSLATION$) > 0 THEN
		PUSH WORDS$, WORD$
		PUSH PARTS_OF_SPEECH$, PART_OF_SPEECH$
		PUSH TRANSLATIONS$, TRANSLATION$
	ENDIF
UNTIL LEN(WORD$) + LEN(PART_OF_SPEECH$) + LEN(TRANSLATION$) = 0

'SORT the data, all of it. Want to keep things lined up so PARTS_OF_SPEECH$, and TRANSLATIONS$ don't get out of sync with WORDS$ (the key)
SORT WORDS$, PARTS_OF_SPEECH$, TRANSLATIONS$

'PRINT OUT A PAGE
'ADDED THE MIN SO YOU DON'T GO OUTSIDE OF THE ARRAY.
FOR I% = 0 to MIN(START% + PAGE_SIZE%, LEN(WORDS$)) - 1
	LOCATE 0, I%
	PRINT WORDS$[i%];
	LOCATE 10, I%
	PRINT PARTS_OF_SPEECH$[I%];
	LOCATE 15, I%
	PRINT TRANSLATIONS$[I%];
NEXT I%

END
@DATA
DATA "ARI", "n.", "ant"
DATA "tsuchibuta", "n.", "aardvark"
DATA "arumajiro", "n.", "armadillo"
... lots more data statements here ...
DATA "", "", "" 'Stop reading data on blank.
Maybe this will help. I only typed it up in notepad so there may be bugs, etc. I changed variable names to be more readable, and modified the code to allow a dictionary of any size. I sort everything at once and include the other two arrays to keep the three arrays in sync.

Um, I'll try it. Thanks