Question

I have a tricky thing to do for my IT class.

Two Tables: 
Classes |Class C-3, Day N-1, Lessons C-7|
Lessons |Lesson C-1, Lesson_Name C-10|

First table:
IX - 1 - MEP    
X - 2 - MBE
XI - 3 - FCM

Second table:
M - Maths
E - English
B - Biology
F - French
P - Physics
C - Chemistry

In the first table the lessons column is the first character of the lesson name (ex. M - Maths and so on)

In the second table are the lessons entered from the first table. (Lesson - Lesson name ex. M - Maths) I need to enter a class from the keyboard (using input or get/read) and write out the lesson names of that class.

I hope you understand what I'm trying to say here.

I tried to make 2 separate arrays from the first table's class and lessons column in a work area, and then using the second table in another work area to write out the lesson names, but I just can't get it to work. I would appreciate any help.

Was it helpful?

Solution

Here's a quick something for you to chew on. I created the table for you and did the inserts of your sample data even though the table structures you will learn more in time.

As for creating column names for tables, try to never use reserved words or even functions that might cause confusion down the road... such in this case "Class", "Day". When you are coding, you will see the reserved words typically appear in a blue syntax color. If you have then when creating your table, think again for a better name for the column.

As for VFP column names. If the table is NOT part of a "Database Container", then the column name limit is only 10 characters (so I changed your "Lesson_Name" to just "LessonName").

I am doing this sample with simple SQL querying. The difference in querying you see in VFP vs other sql databases is relatively minimal. The one big thing is that in VFP, a semi-colon is an indication that the command CONTINUES on the next line. In SQL, the semi-colon is typically indicating the END of a command.

*/ Sample... create the tables and insert the values
SET SAFETY OFF
CLOSE TABLES ALL 
CREATE TABLE Classes;
    (    Class C(3),;
        Day N(1),;
        Lessons C(7) )

INSERT INTO Classes ( Class, Day, Lessons );
    VALUES ( "IX", 1, "MEP" )

INSERT INTO Classes ( Class, Day, Lessons );
    VALUES ( "X", 2, "MBE" )

INSERT INTO Classes ( Class, Day, Lessons );
    VALUES ( "XI", 3, "FCM" )

*/ Create the next table and insert their records        
CREATE TABLE Lessons ;
    (   Lesson C(1),;
        LessonName C(10) )

INSERT INTO Lessons ( Lesson, LessonName );
    VALUES ( "M", "Math" )

INSERT INTO Lessons ( Lesson, LessonName );
    VALUES ( "E", "English" )

INSERT INTO Lessons ( Lesson, LessonName );
    VALUES ( "B", "Biology" )

INSERT INTO Lessons ( Lesson, LessonName );
    VALUES ( "F", "French" )

INSERT INTO Lessons ( Lesson, LessonName );
    VALUES ( "P", "Physics" )

INSERT INTO Lessons ( Lesson, LessonName );
    VALUES ( "C", "Chemistry" )


*/ Prepare a look and keep asking until a user hits the escape key (ASCII 27)
DO WHILE LASTKEY() <> 27
    */ prepare a value for data entry of the class
    SomeClass = "   "
    @ 1,1 say "Enter a value for a class (escape or leave blank to exit):" get SomeClass picture "!!!" 
    READ 
    IF EMPTY( SomeClass )
        EXIT 
    ENDIF 

    */ Query the classes table for the value entered
    USE IN SELECT( "FoundClass" )
    SELECT Class, Day, Lessons;
       FROM Classes;
       WHERE Class = SomeClass;
       INTO CURSOR FoundClass READWRITE 

    */ Did we find the class?   
    IF RECCOUNT( "FoundClass" ) = 0
       MESSAGEBOX( "Sorry, class was not found" )
    ELSE 
       */ Now, get all lessons associated with the class.
       USE IN SELECT( "FoundLessons" )
       SELECT Lesson, LessonName;
          FROM Lessons;
          WHERE Lesson $ FoundClass.Lessons;
          INTO CURSOR FoundLessons READWRITE 

        IF RECCOUNT( "FoundLessons" ) = 0
            MESSAGEBOX( "Sorry, no lessons found for the class" )
        ELSE 
            CLEAR
            ?
            ?
            ?
            ? "Class: " + FoundClass.Class, ;
              "  Day: ", FoundClass.Day, ;
              " Lessons: " + FoundClass.Lessons
            ? "Lessons:"  
            SELECT FoundLessons
            SCAN
               ? FoundLessons.LessonName
            ENDSCAN 
        ENDIF 
    ENDIF 

    USE IN SELECT( "FoundClass" )
    USE IN SELECT( "FoundLessons" )
ENDDO
CLEAR
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top