100 likes | 224 Views
Understanding the significance of reading and writing files is crucial for effective programming. This functionality allows programs to store and retrieve data, enabling persistent data management. You'll need this skill when creating applications like high score trackers or inventory systems. In this project, you'll create a simple application with two buttons to open and write text files, demonstrating file manipulation using code examples. Additionally, you'll develop a program that handles high scores and calculates movie prices based on user input, reinforcing your understanding of file operations.
E N D
Why is it important to read and write files? • Evaluate the importance of it and describe when you would need it
Make a new project • 2 buttons – open and write • 1 textbox – with multiline • Efficient and extended: make sure they all have suitable names
Make a file in your my documents • Make a text file in your my documents called – test
Add this code to write • Dim FILE_NAME As String = "C:\Users\Miles Conway\Documents\test2.txt" • Dim objWriter As New System.IO.StreamWriter(FILE_NAME) • objWriter.WriteLine(TextBox1.Text) • objWriter.Close() • MsgBox("Text written to file") • Extended: use the if statement to check if the file exists
Add this code for read • Dim FILE_NAME As String = "C:\Users\Miles Conway\Documents\test2.txt“ • Dim objReader As New System.IO.StreamReader(FILE_NAME) • TextBox1.Text = objReader.ReadToEnd • objReader.Close() • Extended: use the if statement to check if the file exists
Evaluation • What is the program doing so far? • How is your efficient is your programming?
Task 1 • Make a program where you can add a new high score each time • You should be able to open text file • You should be able to write to the text file • Use IF statements and different text boxes
Extended challenge: Task 2 • Make a program that has a list of films and the price of them • The program should let the user enter the quantity • The quantity is multiplied by the price of the film
Evaluation of programming • How well did the programming go today? • How can you improve? • Evaluate the importance of reading and writing files