? Out of range error during arrays managing (Page 1) ● SmileBASIC Source Forums

Sign In

Register
*Usernames are case-sensitive
Forgot my password

Migrating to a new website for SmileBASIC 4

Out of range error during arrays managing

  • #1 ✎ 19 Stefano_Lassandro Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Drawing I like to draw! Hobbies Minecraft Is Awesome! I love Minecraft! Express Yourself OPTION STRICT DIM A$[64] VAR I A$[0]="abcdefgh" PRINT (A$[I])[2] 'Error line I thought that this was going to output "c", but looks like there's an out of range error on the PRINT line. I thought il could work because this works: A$="abcdefgh" PRINT A$[2] 'Output: "c" So, I've three questions: 1) Is MID$ the fastest (working with string arrays) way? 2) In the cases where I can't use MID$, what should I do? 3) Is there a way to "fix" this code? Thanks! And sorry for my bad english : ) Posted
  • #2 ✎ 380 MZ952 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Third Year My account is over 3 years old Website Reading I like to read books! Hobbies Your first code should work so long as I is within the array confines. There's really no other way it could break. Posted
  • #3 ✎ 1878 12Me21 Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself A string array is a list of strings, so if you set A$[0], all the other items in the array are still empty strings so A$[1] is an empty string, and A$[1][2] will be an out of range error Posted
  • #4 ✎ 19 Stefano_Lassandro Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Drawing I like to draw! Hobbies Minecraft Is Awesome! I love Minecraft! Express Yourself But if I=0 and in the position 0 of the A$ array there is a string, why the first one is not working? It's strange... Posted Edited by Stefano_Lassandro
  • #5 ✎ 243 niconii Power User Video Games I like to play video games! Hobbies Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength Drawing I like to draw! Hobbies Your code works for me in both the 3DS and Switch versions. Is this really all of the code? Did you make a typo somewhere? Posted
  • #6 ✎ 19 Stefano_Lassandro Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Drawing I like to draw! Hobbies Minecraft Is Awesome! I love Minecraft! Express Yourself
    Your code works for me in both the 3DS and Switch versions. Is this really all of the code? Did you make a typo somewhere?
    Oh, actually separated from the rest of the code works! It's strange becouse it's not in any loop so I doesn't change before PRINT anyway. Dunno why
    Posted
  • #7 ✎ 243 niconii Power User Video Games I like to play video games! Hobbies Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength Drawing I like to draw! Hobbies Does your code look like this, maybe? OPTION STRICT DIM A$[64] VAR I FOR I=0 TO 9 '... NEXT A$[0]="abcdefgh" PRINT (A$[I])[2] 'Error line Note that I will be set to 10 after the loop is finished. Posted