Microsoft® Small Basic

Slides:



Advertisements
Similar presentations
Microsoft® Small Basic Graduating to the Microsoft Visual Basic® development environment Estimated time to complete this lesson: 1 hour.
Advertisements

Microsoft® Small Basic
Microsoft® Small Basic Statements, Properties, and Operations Estimated time to complete this lesson: 1 hour.
Microsoft® Small Basic
* 1 Common Dialog Control. * 2 You want your user to set property or provide your application with some information easily? How do you do it? The Common.
Tutorial 6: Managing Multiple Worksheets and Workbooks
Microsoft® Small Basic
Microsoft® Small Basic Debugging Aids Estimated time to complete this lesson: 1 hour.
Microsoft® Small Basic Clock, Desktop, and Dictionary Objects Estimated time to complete this lesson: 1 hour.
Files & Streams. Files Introduction Files are used for long-term retention of large amounts of data, even after the program that created the data terminates.
EAS781 Practical Geophysics: The Tools and How to Use Them ArcGis Introduction ArcView ArcInfo ArcGis ?
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.
Chapter 7: Sub and Function Procedures
Update the PATH variable Trying to run the command: “javac Ex1.java” you’ve may encountered the error: “javac is not recognized as internal or external.
Grep, comm, and uniq. The grep Command The grep command allows a user to search for specific text inside a file. The grep command will find all occurrences.
Lync 2013 for Office 365 Quick Reference © 2012 Microsoft Corporation. All rights reserved. With Lync you can start collaborating without having to schedule.
The Internet & The World Wide Web Notes
Microsoft® Small Basic Sharing Code Estimated time to complete this lesson: 1 hour.
An Introduction to Operating Systems. Definition  An Operating System, or OS, is low-level software that enables a user and higher-level application.
Microsoft® Small Basic Clock, Desktop, and Dictionary Objects Estimated time to complete this lesson: 1 hour.
Microsoft® Small Basic The Controls Object Estimated time to complete this lesson: 1 hour.
1 ADVANCED MICROSOFT WORD Lesson 15 – Creating Forms and Working with Web Documents Microsoft Office 2003: Advanced.
Microsoft Windows 2003 Server. Client/Server Environment Many client computers connect to a server.
Microsoft® Small Basic
Operating Systems  By the end of this session, you will know: What an Operating System is. The functions it performs.
6.1 © 2004 Pearson Education, Inc. Exam Managing and Maintaining a Microsoft® Windows® Server 2003 Environment Lesson 6: Administering User Accounts.
5 Chapter Five Web Servers. 5 Chapter Objectives Learn about the Microsoft Personal Web Server Software Learn how to improve Web site performance Learn.
®® Microsoft Windows 7 for Power Users Tutorial 13 Using the Command-Line Environment.
XP. The Start menu New streamlined design No more “My” Recently programs now sport Jump Lists All Programs menu slides in and out of existing space Search.
Microsoft FrontPage 2003 Illustrated Complete Finalizing a Web Site.
Chapter Two Defining Network Objects. Chapter Objectives Describe how a workstation communicates with the network, and list the software components required.
Object-Oriented Analysis & Design Subversion. Contents  Configuration management  The repository  Versioning  Tags  Branches  Subversion 2.
Professor Michael J. Losacco CIS 1110 – Using Computers Database Management Chapter 9.
Performing Software Installation with Group Policy Lesson 9.
Performing Software Installation with Group Policy BAI516.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Module 5: Configuring Internet Explorer and Supporting Applications.
With Windows 7 Introductory© 2011 Pearson Education, Inc. Publishing as Prentice Hall1 Windows 7 Introductory Chapter 3 Advanced File Management and Advanced.
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.
JDBC Tutorial CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Microsoft® Small Basic Collision Detection Estimated time to complete this lesson: 1 hour.
Microsoft® Small Basic
Lesson 3: Migrating and Configuring User Data
Solutions for the First Quiz COSC 6360 Spring 2014.
OLE Slide No. 1 Object Linking and Embedding H OLE H definition H add other information to documents H copy.
Define and describe operating systems which contain a Command Line Interface (CLI) Define and describe operating systems which contain a Graphical User.
HTML IMAGES. CONTENTS IMG Tag Alt Attribute Setting Width and Height Of An Image Summary Exercise.
1 Installing Java on Your PC. Installing Java To develop Java programs on your PC: Install JDK (Java Development Kit) Add the directory where JDK was.
Configuring, Managing and Maintaining Windows Server® 2008 Servers Course 6419A.
The Development Process Compilation. Compilation - Dr. Craig A. Struble 2 Programming Process Problem Solving Phase We will spend significant time on.
Steps for Developing a Visual C# 2010 Application MIT By: S. Sabraz Nawaz.
Ch 26 & 27 Operating Systems.  Understand the purpose of an operating system  Be able to describe the tasks performed by an operating system.
Microsoft® Small Basic Flickr, ImageList, and Network Objects Estimated time to complete this lesson: 1 hour.
Hands-On Microsoft Windows Server Implementing User Profiles A local user profile is automatically created at the local computer when you log on.
Files and Streams. Objectives Learn about the classes that support file input/output Understand the concept of abstraction and how it related to the file.
PeopleCode and the Component Processor
Introducing Windows 95 Session Two. Today’s Agenda u Formatting Disks u Copying Disks u Mapping Network Drives u Connecting to Network Printers.
XINFO – Scanner DS – File Content
File Handling.
Starter Write a program that asks the user if it is raining today.
PRG 421 MART Knowledge is divine-- prg421mart.com.
PRG 421 MART Lessons in Excellence-- prg421mart.com.
PRG 421 GUIDE Lessons in Excellence -- prg421guide.com.
PRG 421 GUIDE Education for Service-- prg421guide.com.
Files and Streams Lect3 CT1411.
Microsoft® Small Basic
Microsoft® Small Basic
Files & Streams.
Microsoft® Small Basic
3.1 Basic Concept of Directory and Sub-directory
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 how to: Use different properties of the File object. Use different operations of the File object.

The File object includes the following operations and properties: A computer file is a collection of data that your computer stores. In Small Basic, you can work with external files from your program. By using the File object in Small Basic, you can access information from a file that is stored on your computer. You can also read and write information from and to the file. The File object includes the following operations and properties: By 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, you can work with files in many ways by using the File object. Let’s learn about some operations of the File object… WriteLine You can write a line of text at a line number that you specify in a file by using the WriteLine operation. AppendContents You can add text that you specify at the end of a file by using the AppendContents operation. ReadContents You can read the entire contents of a file by using the ReadContents operation. If the WriteLine or AppendContents operation is successful, “SUCCESS” appears in the output window; otherwise, “FAILED” apears. The WriteLine operation will overwrite the previously written content on the specified line.   The ReadContents operation displays the entire contents of the specified file in the output window. This operation is faster when the file is smaller than 1 MB. This operation slows down as the size of the file increases—especially for files that are larger than 10 MB. 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 the path of a file and write a sentence to it by using the WriteLine operation. Next, you add a sentence to the existing content by using the AppendContents operation. Finally, you read the entire contents of the file by using the ReadContents operation. 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.ReadContents(FilePath))

Operations of the File Object CopyFile You can copy the specified file to a destination by using the CopyFile operation. GetFiles You can get a list of all the files in a directory that you specify by using the GetFiles operation. If you specify a destination that does not exist, the CopyFile operation will try to create it. If a file of the same name already exists, that operation overwrites the existing file. Before you use this operation, verify that a file of the same name does not already exist in the destination that you specify.   If the CopyFile operation succeeds, “SUCCESS” appears; otherwise, “FAILED” appears. If the GetFiles operation is successful, it returns the files as an array. Otherwise, “FAILED” appears in 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 copy the specified source file to the specified destination by using the CopyFile operation. You also specify the directory path, and you then display the paths of all files in the output window by using the GetFiles operation. 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 By using this operation, you can create a directory with a name that you specify at a location that you specify. GetDirectories By using this operation, you can get the paths of all the directories in the directory path that you specify. If the CreateDirectory operation succeeds, “SUCCESS” appears in the output window; otherwise, “FAILED” appears. If the GetDirectories operation succeeds, a list of directories appears as an array in the output window. Otherwise, “FAILED” appears. 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… First, you create a directory by using the CreateDirectory operation. Next, you get the path of all the directories in the location that you specify by using the GetDirectories operation. 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 By using the LastError property, you can get details about the most recent file-operation error that occurred in your program. This property is quite useful when an error prevents your program from performing a file operation. In this example, you write text to a file at a specific line number that you specify by using the WriteLine operation of the File object. Next you get the details of the actual error in the program, if any, by using the LastError property of the File object. 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.

Show What You Know Write a program that performs the following steps: Requests a suitable name for a directory from the user, and creates a directory of that name. Downloads a file from the network, and copies it to the new directory. Displays the contents of the downloaded file in the text window. Accepts additional content from the user, and adds it to the file. Displays the final content from the file in the text window. This solution requires the file to exist with the specified name in the specified location. Solution: TextWindow.Write("Enter the name of the new directory: ") DirectoryName = TextWindow.Read() File.CreateDirectory(DirectoryName) filepath = "\\myserver\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