Penn State Information

 

Group Overview - CSE-428

Ryan's Code

    SQL Overview

Gaj's Code                                                                Group Paper Info

Michelle's Code

Tehma's Code

Grant's Code

    FoxPro Resource

Cherise's Code

 

 

 

 

 

 

Group Overview

Group Overview

 

Course: CSE 428 “Concepts of programming languages”

Summer Section 101

 

Name                                                                       Preferred Language

 

 

1.      Gajaka Weerasinghe (Leader)                                          C

2.      Michelle (Stellato) Podolak                                                             VB

3.      Grant Galef                                                                      Visual FoxPro

4.      Cherise Lewis                                                                  Perl

5.      Tehma Smith (Programmer)                                              Pascal or Fortran

6.      Ryan (Programmer)                                                          SQL

 

Group Name: Snippets

 

Our goal is to show following steps of a program in different languages.

 

·        File I/O

·        Looping

·        Parsing

·        Arrays

·        Dynamic data

 

 

 

 

<b><u></font>>Ryan's Code</font></u></b> SQL Program Steps

Ryan's Code

SQL Program Steps

 

Step 1:  Create a series of databases that provide the basic data to query from using SQL

 

Step 2:  Write small sections of SQL to perform simple functions

 

Step 3:  Execute the sections individually to test the output

 

Step 4:  Combine the smaller sections to create a larger more functional program

 

SQL Databases

 

Database 1 titled “list” consists of a series of different numbers separated by decimal places from 1 to 5 incremented by a tenth, with added duplicates at the end.  There will be only one field labeled numbers.

 

1.0       1.1       1.2       1.3       1.4       1.5       1.6       1.7       1.8       1.9       2.0       2.1

2.2       2.3       2.4       2.5       2.6       2.7       2.8       2.9       3.0       3.1       3.2       3.3

3.4       3.5       3.6       3.7       3.8       3.9       4.0       4.1       4.2       4.3       4.4       4.5

4.6       4.7       4.8       4.9       5.0       1.0       1.1

 

Database 2 titled “multiple” consists of multiple fields in series either separated by commas or any other type of delimeter, in this case commas.  The fields are from left to right à number, letter, type, status where number can have any number, letter can have any letter, type will either be “old” or “new” and status will either be “open” or “closed”.

 

1.0  , A , old , closed

1.5 , A , old , open

2.0  , B , old , closed

2.5 , B , old , open

3.0  , C , new , closed

3.5 , C , new , open

4.0  , D , new , closed

4.5 , D , new , open

1.5 , A , old , open

 

Extra databases will be added later that are more complex and contain more data.

 

Now with these two databases set up a few simple programs can be utilized.


Example program #1:

 

/* Query from database 1, list, to output only selected data (parse the database) */

 

SELECT numbers                                /* selects from the column of numbers */

FROM list                                            /* identifies the database as list */

WHERE (numbers like ‘1%’)               /* tells it what data to get */

 

Output of program #1:

 

| numbers          | 

| 1.0                 |

| 1.1                 |

| 1.2                 |

| 1.3                 |

| 1.4                 |

| 1.5                 |

| 1.6                 |

| 1.7                 |

| 1.8                 |

| 1.9                 |

| 1.0                 |

| 1.1                 |

 

Example program #2:

 

/* Create a temporary table with only selected distinct data, in a specific order, output it to the screen in array type format, and delete the temporary table (dynamically using space) */

 

CREATE temp                                     /* allots space for the temporary table */

SELECT distinct number, letter, type, status /* picks only distinct numbers and all else */

FROM multiple                                                /* tells it what database to use */

WHERE (number like ‘%.5’) and (type = ‘old’) and (status = ‘open’) /* what to get */

ORDER by number;                                         /* order data by number */

DROP temp                                                     /* deletes the temporary table */

 

Output of program #2:

 

| number           | letter   | type    | status  |

| 1.5                 | A        | old      | open   |

| 2.5                 | B        | old      | open   |

 

These are just a few examples and can very easily be expanded upon…

 

 

Ryan's SQL Overview:

SQL Introduction

SQL stands for Structured Query Language.  SQL is used to communicate with a database.  According to ANSI (American National Standards Institute), it is the standard language for relational database management systems.  SQL statements are used to perform tasks such as update data on a database, or retrieve data from a database.  Some common relational database management systems that use SQL are: Oracle, Sybase, Microsoft SQL Server, Access, Ingres, etc. Although most database systems use SQL, most of them also have their own additional proprietary extensions that are usually only used on their system. However, the standard SQL commands such as "Select", "Insert", "Update", "Delete", "Create", and "Drop" can be used to accomplish almost everything that one needs to do with a database.

 

A relational database system contains one or more objects called tables. The data or information for the database is stored in these tables. Tables are uniquely identified by their names and are comprised of columns and rows. Columns contain the column name, data type, and any other attributes for the column.  Rows contain the records or data for the columns.

 

The select statement is used to query the database and retrieve selected data that match the criteria that you specify. Here is the format of a simple select statement:

select "column1" ,"column2"

from "tablename"

where "condition";

 

The column names that follow the select keyword determine which columns will be returned in the results. You can select as many column names that you'd like, or you can use a "*" to select all columns.

 

The table name that follows the keyword from specifies the table that will be queried to retrieve the desired results.

 

The where clause (optional) specifies which data values or rows will be returned or displayed, based on the criteria described after the keyword where.  Condition statements can be used to get specific data, as well as general information such as all the words beginning with an A.

 

Snippet Functions

Since SQL is a language that is used to communicate with a database it functions much differently than a conventional programming language like C or VB.  Therefore doing something like looping is inherent in the select process.  This advantage is a good point to make in our project and papers.  It may be hard to compare SQL in the terms of some of the snippets we picked but it will allow for good point / counterpoint discussions in our papers.

Input / Output

                Input is done by creating tables, and output is done by selecting information from a database.  The create table statement is used to create a new table.  Here is the format of a simple create table statement:

 

                           create table "tablename"

                           ("column1" "data type",

                           "column2" "data type",

                           "column3" "data type");

 

You may have as many columns as you like and the constraints are optional.  To create a new table, enter the keywords create table followed by the table name, followed by an open parenthesis, followed by the first column name, followed by the data type for that column, followed by any optional constraints, and followed by a closing parenthesis. It is important to make sure you use an open parenthesis before the beginning table, and a closing parenthesis after the end of the last column definition. Make sure you separate each column definition with a comma. All SQL statements should end with a ";".  The select statement was discussed above and that is how to obtain information for output.

 

The insert statement can also be used to input data into a table. For example:

                           insert into employee

                           (first, last, age, address, city, state)

                           values ('Ryan', 'Hopper', 22, 'Apartment D27', 'KOP', 'PA');

 

To insert records into a table, enter the key words insert into followed by the table name, followed by an open parenthesis, followed by a list of column names separated by commas, followed by a closing parenthesis, followed by the keyword values, followed by the list of values enclosed in parenthesis. The values that you enter will be held in the rows and they will match up with the column names that you specify. Strings should be enclosed in single quotes, and numbers should not.

 

Looping

                I mentioned this before, but there is no real easy set of commands in SQL to perform loops.  When the go is given to get the specific information from the database, it is essentially looping through the table to get the proper data.  I will check into this further, but this is my conclusion for now.

 

Parsing

                Parsing is done as part of the select and where statements in SQL.  This is the part of the code that allows you to tell it what specific data you would like as output.  The where clause (optional) specifies which data values or rows will be returned or displayed, based on the criteria described after the keyword where.

 

Conditional selections used in where clause:

 

                           =       Equal

                           >       Greater than

                           <       Less than

                           >=     Greater than or equal to

                           <=     Less than or equal to

                           <>     Not equal to

                           LIKE   *See note below

 

* The LIKE pattern matching operator can also be used in the conditional selection of the where clause. Like is a very powerful operator that allows you to select only rows that are "like" what you specify. The percent sign "%" can be used as a wild card to match any possible character that might appear before or after the characters specified. For example, from a database table with employee information:

 

                           select first, last, city

                           from empinfo

                           where first LIKE 'Ry%';

 

Arrays

                Arrays are another snippet like loops where they are embedded in SQL as part of a table.  The create and insert functions can input the data in a comma separated array format.  I have yet to find a specific array input or output function.  The information is displayed in a somewhat array format of columns and rows.  I will also look into this, but I think it is just not specifically called out because it is a query language.

 

Dynamic Data

                This function is also not specifically accomplished but can be done by creating and then dropping temporary tables in an SQL script. The drop table command is used to delete a table and all rows in the table. For example:

 

                           drop table employee;

 

To delete an entire table including all of its rows, issue the drop table command followed by the tablename. Drop table is different from deleting all of the records in the table. Deleting all of the records in the table leaves the table including column and constraint information. Dropping the table removes the table definition as well as all of its rows.  The example script that I put together that is on the web site does this.  It creates a temporary table, selects specific data from that table to display, and then drops the data.  The overall idea is allocating some space for this temporary table to occupy and then re open this space by dropping the table.  The actual physical space is allocated automatically by the server, but this serves as dynamic data.

 

Reference

A lot of this information came from the following web site:   http://www.sqlcourse.com/

Database #1

create table list
(numbers varchar(10);

insert into list
(numbers)
values ('1.0');

Database #2

create table multiple
(number varchar(10), letter varchar(10), type varchar(10), status
varchar(10));

insert into multiple
(number,letter,type,status)
values ('1.0','A','old','closed');
 

 

 

 

/* File input output */

Gaj's code:

 

/* File input output */

 

# include <stdio.h>

 

main ()

{

            char a;

            char b;

 

            a= 'Z';

            b= 'z';

            printf("The numeric value of Z is: %d.\n",a);

            printf("The numeric value of z is %d.\n", b);

 

            printf("Good Bye", \n");

            return 0;

}

           

<b>/* File input output */</b>

/* Do While Loop */

 

# include <stdio.h>

main ()

{

 

            int i;

            i =65;

            do{

              printf("the numeric value of %c is %d. \n', i,i);

              i++;

            while (i<100);

 

            return 0;

 

}

/* File input output */

/* passing a array in to a functions*/

# include <stdio.h>

 

int main ()

{

char buffer[80];

printf("enter a string:\n",buffer);

gets(buffer);

printf(" Here is the String you have enterd:%s\n", buffer);

return 0;

}

 

 

 

/* parsing*/

 

 

/******* called header functions****/

 # include <stdlib.h>

 # include <string.h>

 

enum{SUCCESS, FAIL,MAX_LEN =200};

 /***** define functions for later use*****/

void Write_Words(FILE *fin, FILE *fout);    // *fin and *fout are pointers

void Parse_Words (void );

void parse (void);

 /******called the main function*****/

main (void)

{

 /*****defind file pointers*****/

  FILE *fptr1,*fptr2;

 /***** file1 and file2 has to be in the same directory to be open and to write*****/

   char filename1[]="test1.txt";

  char filename2[]="test2.txt";

 // char buff[200];

  int reval = SUCCESS;

   if ((fptr1= fopen(filename1, "w")) == NULL) {

            printf("Cannot open file %s for writing.\n", filename1);

            reval = FAIL;

         }

  if ((fptr2= fopen(filename2, "r")) ==NULL) {

            printf("Cannot open file %s for reading.\n",filename2);

            reval = FAIL;

             }else{

             Write_Words(fptr2,fptr1);

                   fclose(fptr1);

                  fclose(fptr2);

            }

   return reval;

 } 

 void Parse_Words (void)

{

 char buf[BUFSIZ], out[BUFSIZ],str[BUFSIZ], *flds[20], *p;

 int i=0, j;

 int nflds =0;

  while (buf[i] !='\0') {

      for (i=0; buf[i] != '\0' && !isalpha(buf[i]); j++);

             if (buf[i] =='\0') break;

        for (j=0;isalpha(buf[i]);j++){

             out [j++] = buf[i];

       }

       out[j] = '\0';

       printf(" word found; %s\n",out);

       strcpy(out, "\t");

            p = str;

        }

        while (1){

       printf(" enter delimeter(s) for first field[%s]; out");

       gets(buf);

             if (buf[0] !='\0'){

                  strcpy(out,buf);

             flds[nflds] = fopen((p,out), "r");

             }

                  if (flds[nflds] ==NULL){

                  prinf("No more tokens\n");

                  break;

            }

       }

        printf(" End of string\n");

 }

 void Write_Words(FILE *fin, FILE *fout)

{

      char buff[MAX_LEN];

      while (fgets(buff, MAX_LEN, fin) !=NULL){

            fputs(buff, fout);

            printf("%s", buff);

       }

 } 

 void parse (void)

 {

  FILE *fptr3,*fptr4;

  char filename1[]= "test1.txt", buf[80];

  if ((fptr3= fopen(filename1, "r")) != NULL) {

             gets(buf);

             printf("Good Bye!");

       }

  }

 

 

 

 

/* malloc*/

 

/*******calling memry by malloc() function and free up memory by free() function****/

# include <stdio.h>

# include <stdlib.h>

# include <string.h>

 /**** function declaration****/

 void StrCopy(char *str1, char *str2);

 /******Main function*****/

main ( )

{

 

char str[ ] = "use malloc( ) to allocate memory.";

char *ptr_str;

int result;

 /****call malloc ()*****/

ptr_str = malloc(strlen(str) +1);

             if (ptr_str !=NULL){

                         StrCopy(str, ptr_str);

                        printf("The string pointed to by ptr_str is: \n%s\n", ptr_str);

                         /*******free up memory by calling free() function****/

                        free(ptr_str);

                                    result =0;

                        }

                        else{

                                    printf("malloc() function failed.\n");

                                    result =1;

                         }

                        return result;

            }

            /*****function definition****/

  void StrCopy(char *str1, char *str2)

            {

                        int i;

                        for ( i=0;str1[i]; i++){

                                    str2[i] = str1[i];

                        str2[i] = '\0';

            }

 }

 

 

 

 

 

 

 

 

Michelle's code:

 

VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "CPoint"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Private mX As Long
Private mY As Long

Public Property Let X(ByVal Value As Long)
mX = Value
End Property
Public Property Get X() As Long
X = mX
End Property

Public Property Let Y(ByVal Value As Long)
mY = Value
End Property
Public Property Get Y() As Long
Y = mY
End Property

VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 6720
ClientLeft = 1650
ClientTop = 1755
ClientWidth = 6885
LinkTopic = "Form1"
ScaleHeight = 6720
ScaleWidth = 6885
Begin VB.CommandButton cmdDynamicData
Caption = "Dynamic "
Height = 495
Left = 0
TabIndex = 5
Top = 2520
Width = 1215
End
Begin VB.CommandButton cmdParse
Caption = "Parse"
Height = 495
Left = 0
TabIndex = 4
Top = 1920
Width = 1215
End
Begin VB.CommandButton cmdArray
Caption = "Array"
Height = 495
Left = 0
TabIndex = 3
Top = 1320
Width = 1215
End
Begin VB.CommandButton cmdFileIO
Caption = "File I/O"
Height = 495
Left = 0
TabIndex = 2
Top = 720
Width = 1215
End
Begin VB.ListBox List1
Height = 5910
Left = 1440
TabIndex = 1
Top = 120
Width = 4815
End
Begin VB.CommandButton cmdLoop
Caption = "Loop"
Height = 495
Left = 0
TabIndex = 0
Top = 120
Width = 1215
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Option Base 1

Private Sub cmdArray_Click()

' Pros.
' 1. With the option base syntax, an array can be defined with only the upper bound.
' 2. An Array can have any lower bound, not limited to 0 (like in C).
' 3. Can rediminsion the upper bound with Redim statement.
' 4. Support for multiple dimensions.
'
' Cons.
' 1. No pointers in VB so can not access this array through pointers.
' 2.

' One Dimension Array
Dim OneD(0 To 2) As String

OneD(0) = "String 0"
OneD(1) = "String 1"
OneD(2) = "String 2"

' Two Dimension Array
Dim TwoD(0 To 1, 0 To 1) As String
TwoD(0, 0) = "0,0"
TwoD(0, 1) = "0,1"
TwoD(1, 0) = "1,0"
TwoD(1, 1) = "1,1"

End Sub

Private Sub cmdDynamicData_Click()

Dim Point1 As CPoint

Set Point1 = New CPoint
Point1.X = 5
Point1.Y = 6

Set Point1 = Nothing

End Sub

Private Sub cmdFileIO_Click()

' Pros.
' 1. Easy Syntax.

' Cons.
' 1. Not very powerful.

Dim sFileName As String

sFileName = App.Path & "\FileIO.txt"
Kill sFileName ' Delete File.

Open sFileName For Output As #1 ' Open file for output.
Print #1, "This is a test file" ' Print text to file.
Print #1, "Test Line 2"
Print #1, "Test Line 3"
Close #1 ' Close file.

Dim TextLine
Open sFileName For Input As #1 ' Open file.
Do While Not EOF(1) ' Loop until end of file.
Line Input #1, TextLine ' Read line into variable.
List1.AddItem TextLine
Loop
Close #1 ' Close file.

End Sub

Private Sub cmdLoop_Click()

' Pros.
' 1. Easy Syntax.
' 2. Can break out of loop with Exit For statement.

' Cons.
' 1. Have to declare looping variable.
' 2. Can't loop on non-integer index.

Dim i As Long

For i = 1 To 10
Me.List1.AddItem "Loop Index: " & i
Next i

End Sub

Private Sub cmdParse_Click()

' Pros.
' 1. Powerful string parsing functions.
'
' Cons.
' 1. Have to build parsing logic, nothing built into vb.

Dim ParseString As String
ParseString = "The Quick Brown Fox Jumped Over The Lazy Albatros"

Dim lCount As Long
Dim lToken As Long

lCount = 1

Do
lToken = InStr(lCount, ParseString, " ")

If lToken = 0 And lCount < Len(ParseString) Then
List1.AddItem Mid$(ParseString, lCount)
ElseIf lToken > lCount Then
List1.AddItem Mid$(ParseString, lCount, lToken - lCount)
End If
lCount = lToken + 1
Loop While lToken > 0

End Sub



 

 

 

 

 

 

Tehma's code:



 

Pascal: Input/Output

 

 

Program Add;

 

   var

     num1, num2, sum: integer;

 

   begin

     writeln(‘Please enter two numbers:’);

     readln(num1, num2);

     sum: num1 + num2;

     writeln(num1, ‘+’, num2, ‘=’, sum);

   end.                                                                                                                                                                                    

 

 

This program is a basis addition program in Pascal.

bullet Program Add;                                                     

(This is the program title.)

 

bullet var

num1, num2, sum: integer;                                          

(This is the declaration statement - here all the variables are set to integers.)

 

bullet begin                                                                                     

    writeln(‘Please enter two numbers:’);       

                    readln(num1, num2);

                    sum: num1 + num2;

                    writeln(num1, ‘+’, num2, ‘=’, sum);

end.

 

(This is the execution statement)

bullet In Pascal, all execution statements start with “begin” and ends with “end
bullet This execution statement asks the user to input two numbers

writeln (‘Please enter two numbers:’);” is written on the screen. 

bullet The computer then reads the two values and assigns them the label of num1 and num2 “readln (num1, num2);” 
bullet num1 and num2 are then added and the result is given the label sum

sum: num1 + num2;”       

bullet The program then outputs the sum in the format “num1 + num2 = sum”

writeln (num1, ‘+’, num2, ‘=’, sum);

 

 

 

 


 

Pascal: Loop

 

 

Program Sum Loop;

 

   var

     num, sum: real;

     I, nonum: integer;

 

   begin

     write(‘How many numbers to add:’);

     readln(nonum);

     writeln(‘Enter’, nonum:5, ‘numbers:’);

        I: =1;

        sum: =0;

     while I<= nonum do

        begin

           readln(num);

           sum:= sum + num;

           I: =I + 1;

        end;

     writeln(‘sum=’, sum:5:0);

   end.

 

 

This is a loop in Pascal.

 

bullet Program Sum Loop;                                                          

(This is the program title.)

 

bullet var

                    nonum, sum: real;

 I, num: integer;                                                              

(This is the declaration statement - here num and sum are set to real and I and nonum are set to integers.)

 

bullet  begin

      write(‘How many numbers to add:’);

       readln(nonum);

      writeln(‘Enter’, nonum:5, ‘numbers:’);

        I: =1;

        sum: =0;

      while I<= nonum do

        begin

            readln(num);

            sum:= sum + num;

            I: =I + 1;

        end;

     writeln(‘sum=’, sum:5:0);

     end.

        (This is the execution part of the program)

o        This program asks how many number does the user want to add

               write(‘How many numbers to add:’); appears on the screen

o        Once the user enters the value, it is read and assigned the label nonum

              readln(nonum);     

o        The program then asks the user to enter “nonum” numbers (whatever the numerical value of nonum is) writeln(‘Enter’, nonum:5, ‘numbers:’);

o        Variable I is set to 1 “I: =1;” and the variable sum is set to 0 “sum: =0;”

o        This loop is design to run as long as the value of I is less than or equal to the value of nonum

o        The loop begins by reading the first number that was entered readln(num);     

o        The number is then added to the assigned value of sum, which is 0, and the result is stored as the new value for sum  sum:= sum + num;

o        The value of I is then increased by 1 I: =I + 1;

o        The new value of I is then compared to the while statements while I<= nonum do.  As long as the statement is true than the loop is ran.

o        When the while statement becomes false, the loop ends and the program displays the sum on the screen writeln(‘sum=’, sum:5:0);

 

 

Pascal: Parsing

 

Program Backward Odd Numbers;

 

   type

     myarraytype= array[1..8] of integers;

   var

     x: myarraytype;

     I: integer;

   begin

     writeln('Enter 8 numbers:');

     for I:=1 to 8 do

       readln(x[I]);

     for I:= 8 down to 1 do

       if x[I] mod 2= 1 then

         writeln(x[I])

       else

         readln;

   end.

 

This program:

  1. Ask the user to enter 8 numbers and then stores them in an array.
  2. It then reads the array in the order in which the numbers were entered.
  3. Starting from the last number enter to the first number enter, the program then divides each number by 2
  4. If the number is odd (has a remainder of 1), then program then writes the number
  5. If the number is even (has a remainder of 0) the program reads the number and then proceeds to the next number

  

Example:

Enter 8 numbers:                                                                                                                  Output:

2                                                                                                                                              7

25                                                                                                                                            21

23                                                                                                                                            23

21                                                                                                                                            25

8

7

4

6

 

 

 

Program: Array

 

 

Program Reverse List;

                                                        

   type

     myarraytype= array[1..12]of integer;

   var

     x, y, x: myarraytype;

     I: integer;

   begin

     writeln('Enter 12 values for x, y, z arrays:');

     for I:=1 to 12 do

        readln(x[I], y[I], z[I]);

     for I:=12 down to 1 do

        writeln(x[I], y[I], z[I]);

   end.                                                                   

 

This is an array in Pascal.

 

bullet Program Reverse List;                                                     

(This is the program title.)

 

bullet type

   myarraytype= array[1..12]of integers;

var

                    x, y, x: myarraytype;

    I, num: integer;               

(This is the declaration statement - here the array type and variables are identified)

 

bullet begin

                 writeln('Enter 12 values for x, y, z arrays:');

                 for I:=1 to 12 do

                    readln(x[I], y[I], z[I]);

                 for I:=12 down to 1 do

                    writeln(x[I], y[1], z[I]);

              end.

              (This is the execution part of the program)

bullet This program asks the user to enter 12 values for each array writeln('Enter 12 values for x, y, z arrays:'); is written on the screen.
bullet A for loop is then executed to read the values of the arrays

for I:=1 to 12 do

   readln(x[I], y[I], z[I]);

o        Another for loop is executed to write the values of the arrays in the opposite direction in which they were read

for I:=12 down to 1 do

   writeln(x[I], y[1], z[I]);

 

 

Pascal: Dynamic Data

The concept of dynamic data cannot be adequately demonstrated using the Pascal language.

 

 
 

 

 

 

 

 

 

 

 

 

Grant's Code:

 

Looping:

/*there are two loops here, one is a "do while", the other is a "for".  The "for" loop automatically increments each time through, while the "do while" needs to be manually incremented.*/

 

                do while i <= cProgramLength

                                j = j + 1

                                nStart = i

                                nEnd   = AT(CHR(13),cProgram,nOccurance)

                                nChars = nEnd - nStart

                                nOccurance = nOccurance + 1

                                cString = SUBSTR(cProgram, nStart, nChars)

                                IF LEN(cString) <> 0 then

                                                tempString = ""

                                                FOR loop = 1 to 11 DO

                                                                aChar = SUBSTR(cString,loop,1)

                                                                IF aChar == " " .OR. (aChar >= "0" .AND. aChar <= "9") THEN

                                                                                tempString = tempString + aChar

                                                                ENDIF

                                                ENDFOR

                                                Thisform.stringArray[j,1] = tempString

                                ELSE

                                                j = j - 1

                                ENDIF

                                IF nEnd < cProgramLength then

                                                i = nEnd + 2

                                ELSE

                                                i = cProgramLength + 1

                                ENDIF

                enddo                   

               

                for i = 1 to j do

                                memoryuid = LEFT(Thisform.stringArray[i,1],2)

 

                                newvalue = SUBSTR(Thisform.stringArray[i,1],4,2) + ;

                                                SUBSTR(Thisform.stringArray[i,1],7,2) + ;

                                                SUBSTR(Thisform.stringArray[i,1],10,2)

                               

                                update memoryspace set memoryvalue = TRIM(newvalue);

                                where  uid = memoryuid

                endfor

 

Parsing:

 

 

/* the parsing statement below tells the program to search in cProgram for the string "13", and count the number of occurrences*/

 nEnd   = AT(CHR(13),cProgram,nOccurance)

 

/* the parsing statement below tells the program to search in cProgram for the 5th occurrence of ";"*/

 nEnd   = AT(';',cProgram,5)

 

/* the parsing statement below tells the program to search the substring starting at position three, going for two characters to the right*/

Operation1 = SUBSTR(cCurrentOperation,3,2)

 

/* the parsing statement below tells the program to search the subsrting for the left two characters*/

commandOp = LEFT(cCurrentOperation,2)

 

File Input/Output:

CREATE CURSOR textfile ;     /*declaring CURSOR:  temporary memory*/

                (filename c(200), mem m)

               

APPEND BLANK

 

REPLACE textfile.FileName with ;

                GETFILE("ASM")     /*gives user file dialog box*/

               

IF EMPTY(textfile.FileName) THEN

                RETURN

ENDIF

 

APPEND MEMO mem FROM ;

                (textfile.Filename) OVERWRITE

Thisform.edtProgram.ControlSource = "textfile.mem"    /*Thisform.edtProgram is a control from the GUI frame*/

 

Thisform.cmdSave.enabled = .T.

 

Thisform.refresh

 

 

 /* Writing memo block to file below*/

 COPY MEMO textfile.mem TO (textfile.filename)

 

 

Dynamic Data:

 

if cProgram <> ' ' then

                cProgramLength = LEN(cProgram)  /*length of cProgram, created dynamically, then destroyed after run*/

                i = 1

                j = 0

                nOccurance = 1

 

 

Arrays:

Arrays are defined as [100,1], very similar to C++.

Example of using an array in Visual FoxPro:

IF LEN(cString) <> 0 then
tempString = ""
FOR loop = 1 to 11 DO
aChar = SUBSTR(cString,loop,1)
IF aChar == " " .OR. (aChar >= "0" .AND. aChar <= "9") THEN
tempString = tempString + aChar
ENDIF
ENDFOR
Thisform.stringArray[j,1] = tempString
ELSE

This example is assigning a value to an array column.

 

 

Overall FoxPro Info:

Arrays: In Visual FoxPro you define an array with a static size. In some other languages you do not have to define the size of an array and you can add as many array elements as needed. Also, because you don't have to define the size in other languages, you are not allocating space that may or may not be needed.

Looping: Many languages have similar looping capabilities. Visual FoxPro's DO...WHILE and FOR loops offer no real advantage or disadvantage over other languages I am familiar with.

Parsing: Most languages give you the ability to parse strings they just use different commands. For instance, the AT command in VFP is similar to the LOCATE command in OpenROAD. Additionally, SUBSTR in VFP is comparable to OpenROAD's Substring however, substring is a method on OpenROAD's StringObject class so your value must be in a StringObject where in VFP you can take a substring of any character variable.

I don't have too much to say about file i/o. Most languages have the capability but I don't use it all that much. I am usually updating/inserting/deleting rows in a database table which is different than file i/o.

 

FoxPro Resource:

http://databases.about.com/cs/foxpro/

 

 

 

 

 

 

 

 

 

Cherise's Code:

 

 

 

#!/usr/bin/perl -w
# Cherise's ARRAY
# My sources were obtained from one or all of the following
# "Learning Perl" 2nd Edition by Randal L. Schwartz & Tom Christiansen -
# O'Reilly & Associates, Inc.
# Other sources included the following websites
# http://www.comp.leeds.ac.uk/Perl/filehandling.html
# http://www.troubleshooters.com/codecorn/littperl/perlfile.htm
# http://www.personal.psu.edu/~wrp103

#This is an array that reads in a list of jobs then and prints it in sorted order  
print "List the last five jobs you have held?" ;
my (@jobs) = <STDIN>;      
@jobs = sort(@jobs);        
my ($job);
foreach $job (@jobs)
  {        
print "$job";  
  }


 





#!/usr/bin/perl -w
# Cherise's File I/O Snippet
# My sources were obtained from one or all of the following
# "Learning Perl" 2nd Edition by Randal L. Schwartz & Tom Christiansen -
# O'Reilly & Associates, Inc.
# Other sources included the following websites
# http://www.comp.leeds.ac.uk/Perl/filehandling.html
# http://www.troubleshooters.com/codecorn/littperl/perlfile.htm
# http://www.personal.psu.edu/~wrp103

Open(MYFILE, "myfilename");     #open a file        
my($somefile);          
$somefile = <MYFILE>;       #read the file
chomp $somefile;
   {
   print "$somefile";      #print the file            
   }
close(MYFILE);  


 





#!/usr/bin/perl -w
# Cherise's LOOP
# My sources were obtained from one or all of the following
# "Learning Perl" 2nd Edition by Randal L. Schwartz & Tom Christiansen -
# O'Reilly & Associates, Inc.
# "Programming Perl" 2nd Edition Covers Perl 5 by Larry Wall, Randal L. Schwartz
# & Tom Christiansen - O'Reilly & Associates, Inc.
# Other sources included the following websites
# http://www.comp.leeds.ac.uk/Perl/filehandling.html
# http://www.troubleshooters.com/codecorn/littperl/perlfile.htm
# http://www.personal.psu.edu/~wrp103

#This is a if else loop that reads in a number and prints out one of two messages
#depending on the condition the number falls under

print "Pick a number: ";
$num = <STDIN>;
chomp $num;
if ($num < 1) {
  print "Number Invalid! Please try again.\n";
} else {
  print "You chose the number $num. This is a good number!\n";  
}    
 

 

 

 

 

#!/usr/bin/perl -w
# Cherise's PARSING Snippet
# source of information from the following website
# http://www.wdvl.com/Authoring/Languages/Perl/PerlfortheWeb/TokeParser.html

# Parse for the title of a web page

sub parse_title{
#parse and output page title
$parser=HTML::TokeParser->new(\$webPage);
$parser->get_tag("title");
print "<p><h2>Page title</h2> ".
     $parser->get_trimmed_text."</p>";
}
 

 

 

#!/usr/bin/perl -w
# Cherise's Dynamic Data Snippet
# My sources were obtained from
# Concepts of Programming Languages by Robert W. Sebesta

#This is an example of an associative array often called a hash.
#The size of a Perl hash is dynamic: It grows when a new element is added
#and shrinks when an element is deleted.  
 
%gpa = ("Paul" => 4.0, "Sarah" => 3.5, "Melissa" => 3.0, "Greg" => 2.5);    
$gpa{"Joe"} => 1.0;             #adds a new element
delete $gpa{"Greg"};                #deletes an element
print "The group members GPA's are $gpa\n:";    #prints list of remaining gpas