Microsoft® Small Basic

Slides:



Advertisements
Similar presentations
Microsoft® Small Basic
Advertisements

Microsoft® Small Basic Statements, Properties, and Operations Estimated time to complete this lesson: 1 hour.
Program Design. Objectives Students should understand the basic steps in the programming process. Students should understand the need for good design.
Installing geant4 v9.5 using Windows Daniel Brandt, 06 April 2012 Installing Geant4 v9.5 for Windows A step-by-step guide for Windows XP/Vista/7 using.
Microsoft® Small Basic Debugging Aids Estimated time to complete this lesson: 1 hour.
The Internet. Telnet Telnet means using your computer as a terminal. All commands you type are sent to the host computer you are connected to and executed.
Installing geant4 v9.5 using Windows Daniel Brandt, 06 April 2012 Installing Geant4 v9.5 for Windows A step-by-step guide for Windows XP/Vista/7 using.
Creating Functions Deborah Nelson Duke University Professor Susan Rodger July 22, 2008.
MATLAB File Management. MATLAB User File Management Matlab provides a group of commands to manage user files. For more information, type help iofun. pwd.
®® Microsoft Windows 7 for Power Users Tutorial 13 Using the Command-Line Environment.
Python File Handling. In all the programs you have made so far when program is closed all the data is lost, but what if you want to keep the data to use.
Object-Oriented Analysis & Design Subversion. Contents  Configuration management  The repository  Versioning  Tags  Branches  Subversion 2.
1 Back Up with Each Submit One approach for keeping a dynamic back up copy of your current work.
Chapter Ten Structures and Sequential Access Files Programming with Microsoft Visual Basic th Edition.
By Rachel Thompson and Michael Deck.  Java.io- a package for input and output  File I/O  Reads data into and out of the console  Writes and reads.
Files Tutor: You will need ….
FILES. open() The open() function takes a filename and path as input and returns a file object. file object = open(file_name [, access_mode][, buffering])
THE C PROGRAMMING ENVIRONMENT. Four parts of C environment  Main menu  Editor status line and edit window  Compiler message window  “Hot Keys” quick.
The Development Process Compilation. Compilation - Dr. Craig A. Struble 2 Programming Process Problem Solving Phase We will spend significant time on.
Microsoft® Small Basic Flickr, ImageList, and Network Objects Estimated time to complete this lesson: 1 hour.
15 – PHP(5) Informatics Department Parahyangan Catholic University.
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
Sage Franch | Technical Evangelist Susan Ibach | Technical Evangelist.
1 Displaying Dialog Boxes Kashef Mughal. 2 Midterm Stats Here we go  Average was  Low was 116  High was 184  Mid Quarter Grade - check any.
Development Environment
Fundamentals of Python: First Programs
3.1 Fundamentals of algorithms
User-Written Functions
Links and Comments in HTML5
Chapter 7 Text Input/Output Objectives
Chapter 7 Text Input/Output Objectives
Microsoft Official Academic Course, Microsoft Access 2013
Data Virtualization Demoette… Data Lineage Reporting
Chapter 22 – part a Stream refer to any source of input or any destination for output. Many small programs, obtain all their input from one stream usually.
Matlab Training Session 4: Control, Flow and Functions
Chapter 7 Text Input/Output Objectives
File Handling.
Computer Programming I
Coding Defensively Coding Defensively
Executing Runtime Checks (For Comp401 and Comp410)
Repair Outlook Error 0x800ccc78
Visual programming Chapter 1: Introduction
Microsoft FrontPage 2003 Illustrated Complete
Using Procedures and Exception Handling
Starter Write a program that asks the user if it is raining today.
User Defined Functions
Microsoft Visual Basic 2005 BASICS
Files and Streams Lect3 CT1411.
Sequential Input and Output using Text Files
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
elppa legoog erawdrah erawtfos margorp Cisab llams Apple Google
File Handling Programming Guides.
Topics Introduction to File Input and Output
Microsoft® Small Basic
Microsoft® Small Basic
1. Open Visual Studio 2008.
Files & Streams.
A look at Small basic The Text Window 2017.
Microsoft Office Access 2003
CIS16 Application Development and Programming using Visual Basic.net
Scripts In Matlab.
How to work with files and data streams
Basic Lessons 5 & 6 Mr. Kalmes.
Microsoft Office Excel 2003
Basic Mr. Husch.
Topics Introduction to File Input and Output
CSCE 206 Lab Structured Programming in C
CSC 221: Introduction to Programming Fall 2018
Unit Testing.
Presentation transcript:

Microsoft® Small Basic File Input and Output Estimated time to complete this lesson: 1 hour

File Input and Output In this lesson, you will learn about: Using different properties of the File object. Using different operations of the File object.

The File object includes various operations and properties, such as: A computer file is a collection of data stored by your computer. Small Basic programming allows you to work with external files from your program. With the help of the File object in Small Basic, you can access information from a file stored on your computer. You can also read and write information from and to the file. The File object includes various operations and properties, such as: Using the File object, you can also save and open settings across various sessions of your program. CreateDirectory GetDirectories WriteLine AppendContents ReadContents CopyFile GetFiles LastError DeleteDirectory

Operations of the File Object As you see, the File object provides many ways of working with files. Let’s learn about some operations of the File object… WriteLine You can use the WriteLine operation to write a line of text at the specified line number in a file. AppendContents With the AppendContents operation, you can add the specified text at the end of a file. ReadContents Use the ReadContents operation to read the entire contents of a specified file. If the WriteLine operation is successful, it displays “SUCCESS” in the output window; otherwise, it displays “FAILED”. It will overwrite the previously written content on the specified line.   Likewise, if the AppendContents operation is successful, it displays “SUCCESS” in the output window; it displays “FAILED” if unsuccessful. The ReadContents operation is faster when the size of the file is less than 1 MB. The operation slows down as the size of the file increases—especially for files larger than 10 MB. It displays the entire contents of the specified file on the output window. Code: Writeline: File.WriteLine("C:\Small Basic.txt", 1, "Hello") AppendContents: File.AppendContents("C:\Small Basic.txt","Take Care") ReadContents: File.ReadContents("C:\Small Basic.txt”)

Operations of the File Object Let’s write a program to gain better understanding of these operations. In this example, you specify a file path and use the WriteLine operation to write a sentence to the file. Next, you use the AppendContents operation to add a sentence to the existing content. Finally, you use the ReadContents operation to read the entire contents of the file. output Code: FilePath = "C:\temp\TempSubdirectory\my.txt" TextWindow.WriteLine("Write Content = " + File.WriteLine(FilePath, 1, "Shakespeare was a great writer.")) TextWindow.WriteLine("Append Content = " + File.AppendContents(FilePath, "He wrote many plays.")) TextWindow.WriteLine("Read Content = " + File.WriteLine(FilePath))

Operations of the File Object CopyFile You can use the CopyFile operation to copy the specified file to a destination. GetFiles With the GetFiles operation, you can get a list of all the files present in the specified directory. If the specified destination to copy the file does not exist, the operation will try to create it. If a file of the same name already exists, the operation overwrites the existing file. Make sure to check that a file of the same name does not already exist in the specified destination.   If the CopyFile operation is successful, it displays “SUCCESS”; otherwise, it displays “FAILED”. If the GetFiles operation is successful, it returns the files as an array. If unsuccessful, the operation displays “FAILED” on the output window. Code: CopyFile: File.CopyFile("C:\Small Basic.txt", "C:\temp") GetFiles: File.GetFiles("C:\Documents and Settings")

Operations of the File Object Let’s write a program to better understand these operations. In this example, you use the CopyFile operation to copy the specified source file to the specified destination. You also specify the directory path, and then use the GetFiles operation to display the path of all files in the output window. output Code: sourcefilepath = "C:\temp\TempSubdirectory\my.txt" destinationfilepath ="C:\temp\TempSubdirectory\Move" directorypath = "C:\temp\" TextWindow.WriteLine("Copy file Operation:" + File.CopyFile(sourcefilepath, destinationfilepath)) TextWindow.WriteLine("Files in the directory: " + File.GetFiles(directorypath))

Operations of the File Object CreateDirectory Use the CreateDirectory operation to create the specified directory at the desired location. GetDirectories With the GetDirectories operation, you can get the path of all the directories in the specified directory path. If the CreateDirectory operation is successful, it displays “SUCCESS” in the output window; otherwise, it displays “FAILED”.   If the GetDirectories operation is successful, it displays the list of directories as an array in the output window. If unsuccessful, the operation displays “FAILED”. Code: CreateDirectory: File.CreateDirectory("C:\File Object") GetDirectories: File.GetDirectories("C:\Documents and Settings")

Operations of the File Object Let’s see how we can apply these operations… As you see, you first use the CreateDirectory operation to create a directory. Next, you use the GetDirectories operation to get the path of the all the directories present in the specified location. output Code: directorypath1 = "C:\temp\Small Basic" TextWindow.WriteLine("Create Directory: " + File.CreateDirectory(directorypath1)) directorypath2 = "C:\temp" TextWindow.WriteLine("Directories: " + File.GetDirectories(directorypath2))

The LastError Property With the help of the LastError property, you can get details of the last file-operation-based error in your program. This property is quite useful when you can’t execute a file operation in your program because of some error. In this example, you use the WriteLine operation of the File object to write text to the file at a specific line number. Next you use the LastError property of the File object to get the details of the actual error in the program, if any. output Code: FilePath = "C:\temp\TempSubdirect\my.txt" TextWindow.WriteLine("Write Line Operation: " + File.WriteLine(FilePath, 1, "How are you?")) If File.LastError = "" Then TextWindow.WriteLine("Operation Successful") Else TextWindow.WriteLine(File.LastError) EndIf

Let’s Summarize… Congratulations! Now you know how to: Use different properties of the File object. Use different operations of the File object.

It’s Time to Apply Your Learning… Write a program by performing the following steps: Create a directory by accepting a suitable name from the user. Download a file from the network and copy it to the created directory. Display the contents of the downloaded file in the text window. Accept additional content from the user and add that content to the file. Display the final content from the file in the text window. Please Note: The file must exist at the specified network path for the solution to work. Solution: TextWindow.Write("Enter the name of the new directory: ") DirectoryName = TextWindow.Read() File.CreateDirectory(DirectoryName) filepath = "\\mum-9785sm\Share\FileIO.txt" downloadpath = Network.DownloadFile(filepath)   If File.CopyFile(downloadpath, DirectoryName) = "SUCCESS" Then TextWindow.WriteLine("File has been downloaded from the network and copied to: " + DirectoryName)   files = File.GetFiles(DirectoryName) TextWindow.WriteLine("This is the content in the file: ") TextWindow.WriteLine(File.ReadContents(files[1])) TextWindow.Write("Enter data to be added in the file:") AppendedData = TextWindow.Read() File.AppendContents(files[1]," " + AppendedData) TextWindow.WriteLine("File content after adding data is as follows: ") EndIf