How do I pick a random text box to put text in? And is it possible to lock the text box so the user can't edit it?

Hello everyone! Im new to the forum so I don't really know how this works but Im currently trying to create a sudoku app for a school project. If anyone knows how I could pick a random label out of a number of labels please tell me I am really desperate...
(for example: 3 out of 9 text boxes generate a number from 1 to 9 which doesn't duplicate in any of the boxes and then lock it so the user of the app can't put another number in the box)

Any help is appreciated and thank you in advance!!

You will need to make a table (list of lists) of your Textboxes.
For Sudoku, a 9 by 9 table should work well.

You will also need functions (value procedures that take a textbox component and return its row(1-9) and column (1-9).

You will need to code a true/false value procedure sibling that takes the addresses (row1, column1, row2, column2) of two squares and tells you if the two squares are located in the same row, column, or 3 by 3 square of the board. This is needed for checking if a proposed value (1-9) has already been claimed by a sibling and is therefore forbidden.

You will need the for each number loop block to traverse rows and columns to cover them all while keeping track of where you are.

To stop the player from changing a textbox value, turn off (false) its Enabled attribute.
To tell the player that a given number is hard coded as part of the puzzle, also mark that textbox as Bold.

If you haven't yet set up your 81 text boxes, here is a trick to make it easier using Copy (Ctrl-C) and Paste (Ctrl-V) in the Designer:

  • Make a Vertical Arrangement. (Fill Parent, centered)
  • Make a Horizontal Arrangement inside that Vertical Arrangement (Fill Parent, centered)
  • Add a Textbox into the Horizontal Arrangement (empty, centered, numeric, Fill Parent)
  • Select the text box and press Ctrl-C to start the copying
  • Select the Horizontal Arrangement then press CTrl-V 8 times to paste in the rest of the row
  • While the Horizontal Arrangement is selected, Press Ctrl-C to prepare to copy it
  • select the Vertical Arrangement then press CTrl-V (Paste) 8 times to paste in rows 2-9

Here are some projects to study, to learn how to use generic blocks and lists of components ...

the eight queens problem
http://ai2.appinventor.mit.edu/?galleryId=5858910198693888

1 Like

Thank you so much for your reply!! It really helps me a lot and I now have a better overview over the things I still have to do!
Im sorry for asking another question, but Im having problems with the table and functions part since I never really used it before, so ,if you'd like, could you give me some examples or tips on how I can solve this?

Again thank you lots for all the help you've already provided!

Please see http://www.appinventor.org/bookChapters/chapter21.pdf for procedures, and
http://www.appinventor.org/bookChapters/chapter19.pdf for lists, from the free book at
FAQ Section: Books, Tips, Tutorials for AI2

Also see FAQ Section: Lists

1 Like

Try something like this, evety time the procedure is called 3 random out of 9 text boxes generate a number from 1 to 9

image

2 Likes

Thank you so much!!

1 Like

Ahh okay thanks a lot!