Студопедия

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

КАТЕГОРИИ:

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






Function Return Values






Most functions produce " return" values. Return values are the output data produced when a function processes any given input data. Data processed and returned by a function is typically stored in variables:

lowered = lower$ (" THIS FUNCTION CONVERTS TEXT TO LOWERCASE.")print lowered

In some cases the output (return value) of one function can be used directly as the input of another function:

print lower$ (" THIS FUNCTION CONVERTS TEXT TO LOWERCASE.")! The previous line contains 2 functions: 'print' and 'lower$'! The output of the lower$ function is used as the input! parameter of the print function.

In RFO Basic, the return value(s) of functions (commands) are most often specified as parameter(s) - placed in the parameter list, immediately after the function word. The following function " grabfile" stores the text read from the specified file, in the arbitrarily chosen variable " s$":

print " Hello World! " % this prints some textconsole.save " temp.txt" % this saves the printed text to a filegrabfile s$, " temp.txt" % this reads the file and stores the % returned data in the variable s$print s$ % this prints the contents of the variable

The return values output by the numerous functions in RFO Basic can be used in your programs to accomplish useful goals. The " input" function allows you to request a single line of text, or a number, from the user:

input " Enter some text", s$ %text input by user is stored in variable s$print s$

Notice the following line contains the return value " n", WITHOUT THE " $" CHARACTER. N is therefore treated as a number variable:

input " Enter a number", nprint n

The " input" function has an optional parameter that allows you to display some default text in the requester:

input " Enter your name", s$, " John" % the " $" in s$ means that it's textprint s$

The " text.input" function allows the user to input, edit, and save large quantities of text. The first parameter is a string variable that holds the final edited text output by the function. The second parameter holds some initial text to appear in the editor window:

text.input r$, " Edit this text" % user edited text is stored in r$print r$

You can assign a variable to text read from a file (using the grabfile function above), and use that text as the second parameter in the text.input function. This allows you to retrieve, edit, and store any text file on your Android device:

grabfile s$, " temp.txt" % The variable s$ is assigned to the text read % from the file " temp.txt" text.input r$, s$ % The initial text in the editor is the text % stored above in the s$ variable. After the % user edits the text, the returned, edited % text is stored in the r$ variable

Поделиться с друзьями:

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