Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • CreatiCode
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

CreatiCode Scratch Forum

  1. CreatiCode Forum
  2. Knowledge Base
  3. 2D Blocks
  4. Reading from a Table

Reading from a Table

Scheduled Pinned Locked Moved 2D Blocks
1 Posts 1 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • CreatiCodeI Offline
    CreatiCodeI Offline
    CreatiCode
    wrote on last edited by admin
    #1

     

    Prerequisite

     

    • Introduction to Tables

     
     

    Description

     

    Reading from a table is similar to reading from a list:

    • When reading from a list, we just need to specify the row number;
    • When reading from a table, we need to specify the column name and the row number.

    We will use the table “t1” in our examples below. It has 4 columns and 3 rows.

    a3d55d7d-3b81-414b-a24e-c31fd8cfab89.png

     
     

    Get the number of rows in a table

     

    You can use the “row count” block to get the number of rows in a table. If the table is empty, then this block will report 0.

    cd8cd0bf-4aa7-4f4b-80fc-253432c070b5.gif

     
     

    Reading the Value of One Item

     

    If you already know the column name and row number of an item you are interested in, you can use this block to read its value.

    8459e939-4be9-4dec-bd05-c209a55828d5.png

     
     

    Parameters

     

    • Row Number: The row number has to be between 1 and the total number of rows in the table.
    • Column Name: The column name is not case-sensitive. For example, you can use “Name” or “name” to refer to the “NAME” column. Note that a very common mistake is to use a number instead of the column name.

     
     

    Demo

     

    bc3e5f63-9e84-4a2b-b9d4-e1c1de3f695b.gif

     
     

    Reading an Entire Row

     

    Sometimes you may want to read the values of all items in a row. You can use this block to get all the values joined together with the given separator.

    2b7d2f4f-b33d-422d-ba8b-b55c46cb1b91.png

     
     

    Parameters

     

    • Row Number: The row number has to be between 1 and the total number of rows in the table.
    • Table Name: Select the name of the table from the dropdown.
    • Separator: Which symbol to use to separate the values of different columns in this row.

     
     

    Demo

     

    1abbb054-629f-484e-b33f-34719243e934.gif

     
     

    Looking for an Item in a Column

     

    You can search for an item in any column of a table using this block:

    80941970-1e2c-4205-be46-ec264fa9518d.png

     
     

    Parameters

     

    • Item to look for: The exact text of the item you are looking for.
    • Column Name: The column that you want to search.
    • Table Name: Select the name of the table from the dropdown.

     
     

    Demo

     

    For example, we can look for the name of any student in the “Name” column, and this block will return the row number. If that item is not found, then this block will return -1.

    726e1418-fdb3-49ae-8b13-01f3d3255aa3.gif

     
     

    Looking for an Item that contains a value in a Column

     

    Sometimes, you don’t want an exact match. For example, you only know part of an item, but not the exact value of that item. You can look for any item that contains a value with this block:

    0bf86c87-0d04-4a27-8907-9edab9d0d91c.png

     
     

    Parameters

     

    • Part of item to look for: The part of the item you are looking for.
    • Column Name: The column that you want to search.
    • Table Name: Select the name of the table from the dropdown.

     
     

    Demo

     

    For example, suppose we know a student’s first name is “Aiden”, but we do not know his full name. We can look for any student whose name contains “Aiden”. This block will return the row number. If no name contains “Aiden”, then this block will return -1.

    500010aa-46ba-457e-ae12-bb7be13dc7d0.gif

     
     

    Looking Up in One Column Using Another Column

     

    Sometimes, you may want to look up a table using a different column. For example, you might want to know the height of the student with an ID of 101. Essentially, we first find the row number using that ID, and then read the value in that row for the given column.

    This look-up operation can be done using this block:

    053f8977-df1f-4856-ac11-1f7701f6e1af.png

     
     

    Parameters

     

    • Target Column: The column you want to query about, such as “height” in our example.
    • Table Name: Select the name of the table from the dropdown.
    • Lookup Column: The column that you want to look up with, such as “ID” in our example.
    • Item in Lookup Column: The value you are searching for in the lookup column, such as 101 in our example.

     
     

    Demo

     

    0bde4ed5-64ad-4324-b80a-44a91871e5c6.gif

    1 Reply Last reply
    0
    • CreatiCodeI CreatiCode pinned this topic on

    Hello! It looks like you're interested in this conversation, but you don't have an account yet.

    Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

    With your input, this post could be even better 💗

    Register Login
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • CreatiCode