? I need help data printing and sorting (Page 1) ● SmileBASIC Source Forums

Sign In

Register
*Usernames are case-sensitive
Forgot my password

I need help data printing and sorting

  • #1 ✎ 76 Tiger2 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. Posted
  • #2 ✎ 880 Y_ack Head Admin This sounds like a specific problem. If you want specific help, you'll need to show the instructions you used. Posted
  • #3 ✎ 76 Tiger2 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. Posted
  • #4 ✎ 89 Krondelo 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. Posted
  • #5 ✎ 76 Tiger2 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" Posted Edited by Tiger2
  • #6 ✎ 1537 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself Second Year My account is over 2 years old Website
    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
    Posted
  • #7 ✎ 76 Tiger2
    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.
    Posted Edited by Tiger2
  • #8 ✎ 1537 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself Second Year My account is over 2 years old Website you have a NEXT without FOR Posted
  • #9 ✎ 76 Tiger2 Oops. That problem does not exist in the actual thing, but I fixed it. Posted
  • #10 ✎ 131 raimondz First Week Joined in the very first week of SmileBASIC Source Website Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength Night Person I like the quiet night and sleep late. Express Yourself 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. Posted Edited by raimondz
  • #11 ✎ 76 Tiger2 But i tried putting the sort command after already. In my example, it is right after READ Posted Edited by Tiger2
  • #12 ✎ 60 seggiepants 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. Posted
  • #13 ✎ 76 Tiger2 Um, I'll try it. Thanks Posted