DOC PREVIEW
MSU LBS 126 - vbinputoutput-f03
Course Lbs 126-
Pages 23

This preview shows page 1-2-22-23 out of 23 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Input and OutputAnnouncementsSlide 3File TypesPlain Text filesData Files (pp. 98-102)Opening a Data File for InputReading from Data FileData file formatClose the file when finishedReading Until End of FileAverage Calculation ProgramWorking folderFriday’s ProgramInput Boxes (p.102)Input BoxesFormatting OutputPrint ZonesZones (p.104)Tabs (p.105)TabsWriting to a Data FilePrint to a Data FileInput and OutputInput and OutputAnnouncementsAnnouncementsExam Next WednesdayExam Next Wednesday–Next Monday: Review session.Next Monday: Review session.Invited talk:Invited talk:–7:30 PM ,Tuesday, Oct 28th.7:30 PM ,Tuesday, Oct 28th.–Prof. Katherine SochaProf. Katherine Socha –Mathematics: Morals and Mortals Mathematics: Morals and Mortals –5 extra credits for write-ups 5 extra credits for write-upsInput and OutputInput and OutputFile TypesFile TypesInput filesInput filesInput BoxesInput BoxesFormatting OutputFormatting OutputOutput filesOutput filesRead pp. 57-64Read pp. 57-64File TypesFile TypesSeveral file types are saved in “plain text” or Several file types are saved in “plain text” or ASCII formatted textASCII formatted text–.html, .txt, .csv, ….html, .txt, .csv, …These files can be read by almost all These files can be read by almost all programs, and can be used as inputprograms, and can be used as inputOther file types are saved in special Other file types are saved in special formatting and cannot be read easily formatting and cannot be read easily (.doc, .xls, .ppt, .exe, …)(.doc, .xls, .ppt, .exe, …)Plain Text filesPlain Text filesAll files are formed by bytes.All files are formed by bytes.Text files only use part of all possible bytes: Text files only use part of all possible bytes: The Basic ASCII code The Basic ASCII code –32 (20H) ~ 128 (80H) 32 (20H) ~ 128 (80H) –Every line end with byte 0DH and 0AH, also Every line end with byte 0DH and 0AH, also called CR (carriage return) and LF (line feed) called CR (carriage return) and LF (line feed) Any file that can be read by Any file that can be read by NotePad NotePad normallynormally is plain text and will work for data is plain text and will work for data filesfilesData Files (pp. 98-102)Data Files (pp. 98-102)A plain text data file (example data.txt) A plain text data file (example data.txt) can be read by a VB program. can be read by a VB program. 4444121233336464Create data file using Create data file using NotePad NotePad –Save it in Save it in same directorysame directory as program as programOpening a Data File for InputOpening a Data File for InputYou need to open a file for inputYou need to open a file for inputOpen “DATA.TXT” For Input As #1Open “DATA.TXT” For Input As #1Can use value 1-255 for “As #1”Can use value 1-255 for “As #1”““DATA.TXT” is the data file name.DATA.TXT” is the data file name.How does the program know where the file How does the program know where the file is?is?Reading from Data FileReading from Data FileCalled InputtingCalled InputtingInput #1, age1Input #1, age1Input #1, age2Input #1, age2OrOrInput #1, age1, age2Input #1, age1, age2General format:General format:Input #n, varNameInput #n, varNameData file formatData file formatData can be sepData can be sepaarated by line break rated by line break (CR/LF)(CR/LF)OOr can be separated by commar can be separated by commaIIf it is pure number file: separated by space.f it is pure number file: separated by space.Close the file when finishedClose the file when finishedClose #1 Close #1 ~~ ~~ the file reference numberthe file reference numberUsing a Do while loop, you can read until you reach Using a Do while loop, you can read until you reach the end of the filethe end of the fileDo While Not EOF(1)Do While Not EOF(1)Reading Until End of FileReading Until End of FileThe The EOF(file reference number)EOF(file reference number) function function will return TRUE, when the file pointer will return TRUE, when the file pointer reaches the end of file.reaches the end of file.Using a Do while loop, you can read until Using a Do while loop, you can read until you reach the end of the fileyou reach the end of the fileDo While Not EOF(1)Do While Not EOF(1)‘‘Processing code hereProcessing code hereInput #1, variableInput #1, variableLoopLoopAverage Calculation ProgramAverage Calculation ProgramPrivate Sub AvgCalc_Click()Private Sub AvgCalc_Click()Dim num as single, Sum as single, count as integerDim num as single, Sum as single, count as integerDim average as singleDim average as singleOpen “data.txt” for input as #1Open “data.txt” for input as #1Sum = 0Sum = 0Count = 0Count = 0Do While Not EOF (1)Do While Not EOF (1)Input #1, numInput #1, numSum = Sum + numSum = Sum + numCount = Count + 1Count = Count + 1LoopLoopClose #1Close #1Average = Sum/CountAverage = Sum/CountPicture1.print AveragePicture1.print AverageEnd SubEnd SubWorking folderWorking folderThe visual basic’s default working folder is in the The visual basic’s default working folder is in the path, where the vb6.exe file resides.path, where the vb6.exe file resides.Open a form file directly from its folder will set Open a form file directly from its folder will set ththe e working folder to the form file folder.working folder to the form file folder.App.Path will give the name of the folder where App.Path will give the name of the folder where the .frm file is. the .frm file is. –YYou must save the project first, otherwise the working ou must save the project first, otherwise the working folder is still same as vb6.exefolder is still same as vb6.exe–Open App.Path & “\data.txt” For Input As Open App.Path & “\data.txt” For Input As #1#1Friday’s ProgramFriday’s ProgramCreate a program that calculates the Create a program that calculates the Standard Deviation of a datasetStandard Deviation of a datasetStandard deviation is the average distance Standard deviation is the average distance between a point and the meanbetween a point and the meanSd = sqr(Sd = sqr(∑(num-average)/(n-1))∑(num-average)/(n-1))Input Boxes (p.102)Input Boxes (p.102)Dim temptext As StringDim temptext As Stringtemptext = InputBox("Give me a value", temptext = InputBox("Give me a value", __ "Enter Value")"Enter Value")miles = Val(temptext)miles = Val(temptext)__ (underscore) (underscore) is line continuation characteris line continuation


View Full Document

MSU LBS 126 - vbinputoutput-f03

Course: Lbs 126-
Pages: 23
Download vbinputoutput-f03
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view vbinputoutput-f03 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view vbinputoutput-f03 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?