Студопедия

Главная страница Случайная страница

КАТЕГОРИИ:

АвтомобилиАстрономияБиологияГеографияДом и садДругие языкиДругоеИнформатикаИсторияКультураЛитератураЛогикаМатематикаМедицинаМеталлургияМеханикаОбразованиеОхрана трудаПедагогикаПолитикаПравоПсихологияРелигияРиторикаСоциологияСпортСтроительствоТехнологияТуризмФизикаФилософияФинансыХимияЧерчениеЭкологияЭкономикаЭлектроника






Text Editor App




Here is a full text editor app that allows you to choose a file from your Android storage card, edit it, and then save it back to the file system when done.

! The following flag variable will be used later to determine if the user! has already entered a starting folder: flag = 0! This label marks a point in the code which can be jumped back to later: start:! After the program runs once, the flag variable gets set to 1 and the! startfolder$ variable gets choosen by the user. If this is the first! time through the program loop (" flag" variable still equals 0), then a! default starting folder needs to be set: if flag = 0 then startfolder$ = " /sdcard/rfo-basic/data/"! This line asks the user for a folder, with the default folder displayed.! If the startfolder$ variable has been set on a previous loop through the! program, that value is used as the default: input " Folder", folder$, startfolder$! Save the chosen folder in the startfolder$ variable, and set the flag! variable to 1 (to indicate that a starting folder has now been chosen by! the user): startfolder$ = folder$flag = 1! Remember, the default data folder in RFO Basic is! /sdcard/rfo-basic/data/! The characters "../" are used to go up one folder level. So,! for example, "../sdcard/rfo-basic/data/" = " /sdcard/rfo-basic/", and! "../../../sdcard/rfo-basic/data/ is the same as the top level (root)! directory of your Android file system. In order to refer to the folder! chosen by the user, we need to refer to that folder in terms relative! to RFO Basic's default folder. This line concatenates a string to! properly refer to the relative location of the chosen folder: rfofolder$ = "../../../" + folder$! This line deletes the array " files$[]". If the array is not deleted,! the next line of code will produce an error when the program loops! back to the beginning (remember, arrays can't be re-dimensioned without! being deleted): array.delete files$[]! This line reads the directory listing of the chosen folder, and saves! that listing in the array variable " files$[]": file.dir rfofolder$, files$[]! This line sorts the array alphabetically: array.sort files$[]! This line allows the user to choose a file name from the sorted file! list: select s, files$[], " "! This line concatenates the chosen folder together with the selected! file, to create a full path to the desired file: myfile$ = rfofolder$ + files$[s]! This line reads the contents of the file, and saves the read text into! the string variable " unedited$": grabfile unedited$, myfile$! This line allows the user to edit the read text, and saves the edited! content into the string variable " edited$": text.input edited$, unedited$! This line opens a text file for writing, and creates the pointer! variable " filename" to refer to the file: text.open w, filename, myfile$! This line writes the contents of the " edited$" variable to the file: text.writeln filename, edited$! This line closes the file: text.close filename! This line alerts the user with a short message: popup " Saved", 0, 0, 1! This line jumps back to the label at the beginning of the code, and! starts the whole process over again, to choose and edit another file: goto start

Here's the entire program, without comments - it's short and simple:

flag = 0start: if flag = 0 then startfolder$ = " /sdcard/rfo-basic/data/" input " Folder", folder$, startfolder$ startfolder$ = folder$ flag = 1 rfofolder$ = "../../../" + folder$ array.delete files$[] file.dir rfofolder$, files$[] array.sort files$[] select s, files$[], " " myfile$ = rfofolder$ + files$[s] grabfile unedited$, myfile$ text.input edited$, unedited$ text.open w, filename, myfile$ text.writeln filename, edited$ text.close filename popup " Saved", 0, 0, 1goto start

Данная страница нарушает авторские права?


mylektsii.su - Мои Лекции - 2015-2024 год. (0.005 сек.)Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав Пожаловаться на материал