Студопедия

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

КАТЕГОРИИ:

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






A Variety of Useful Function Examples






Here are a few more examples which demonstrate how to perform useful actions and how to process data in useful ways, using functions/commands. Try typing or pasting every one of them into the RFO Basic interpreter, to see how they work:

! The tone function takes 2 parameters, pitch and duration, and plays a! tone: tone 440, 2000! The file.rename function takes 2 parameters, the old and new filenames,! and renames the old file to the new file name in the Android file! system: file.rename " oldname.txt", " newname.txt"! The clipboard.get function takes 1 parameter, a variable name assigned! to the contents retrieved from the device clipboard: clipboard.get c$ print c$ % this prints the data returned by the function above! The tts.init function prepares for the use of text-to-speach functions! No parameter is required: tts.init! The tts.speak function takes 1 parameter, some text to speak: tts.speak " I am alive"! This code reads the current text in the Android clipboard: clipboard.get c$ tts.init tts.speak c$! The audio.record.start takes 1 parameter, the name of a file to record! to: audio.record.start " record.3gp"! The pause function takes 1 parameter, the amount of time to wait (in! milliseconds): pause 5000! The audio.record.stop function doesn't take any parameters. It just! stops the recording previously started: audio.record.stop! The audio.load function takes 2 parameters, the name of a " pointer"! number used to refer to a specified audio file, and the name of the! specified audio file: audio.load s, " record.3gp"! The audio.play function plays the file specified by the pointer number! created in the previous function: audio.play s pause 5000! The clock() function doesn't take any parameter. It returns the number! of milliseconds since your device was turned on: s = clock()! This prints the data contained in the numeric variable created above: print s! The device function takes 1 parameter, the name of a string variable to! store returned information about your device: device s$! This line prints the data contained in the string variable created! above: print s$! The gps.open function doesn't take any parameters. It just prepares for! the use of the GPS function: gps.open! The gps.latitude and gps.longitude functions each take 1 parameter,! a variable name to store the returned latitude and longitude values: gps.latitude l1 gps.longitude l2! The gps.close function doesn't take any parameters. It just closes! the gps device opened above: gps.close! This prints the longitude and latitude values stored in the return! variables created above: print " Your longitude and latitude: "; l1; ", "; l2! This assigns some text to a new string variable: s$ = " three blind mice"! The replace function takes 3 parameters, the name of an input AND return! string variable in which to find and replace text, the text to find and! replace, and the replacement text - all contained inside parentheses: replace$ (s$, " blind", " sexy")! This prints the replaced text string returned by the function above: print s$! The ftp.open function takes 4 parameters, the URL of an FTP server, the! port to open, a username, and a password: ftp.open " ftp.site.com", 21, " username", " password"! The ftp.put function takes 2 parameters, the name of a local file to! tranfer to the remote FTP server, and the path/filename to create and! send to on the server: ftp.put " temp.txt", " /public_html/temp.txt"! The ftp.close function doesn't take a parameter. It just closes the! currently open FTP connection: ftp.close! The graburl function takes 2 parameters, a string variable name in which! to save the returned data from a specified URL, and a URL to read: graburl w$, " https://site.com/temp.txt"! This prints the returned data read from the URL and stored in the! variable created above: print w$! The is_in function takes 2 parameters, a string to search for, and a! string to search within. It returns a value of 1 if the search string! is found within the 2nd string, 0 if not found: q = is_in (" blind", " three blind mice")! This line prints " It's in there" if the search string above is found! (if the returned value is not 0): if q < > 0 then print " It's in there"! The kb.show function shows Android's on-screen keyboard. It does not! take any parameters: kb.show! The kb.hide function hides Android's on-screen keyboard. It does not! take any parameters: kb.hide! The sqr() function takes 1 numeric parameter, between parentheses, and! returns the square root. The returned value can be assigned a variable! name: s = sqr(16) print s! This line does the exact same thing as the previous 2 lines. It just! prints the value of the sqr() function (the return value of the sqr()! function is used as the parameter of the print function): print sqr(16)! The array.load function creates a type of item list. It takes 1 or more! parameters, a variable name to assign to the list, and several items! (in the case below, numbers), to add to the list: array.load p[], 0, 300, 200, 300, 200, 300! The vibrate function takes 2 parameters, an array of durations to pause! and vibrate, and a number to indicate whether that vibration pattern! should be repeated (-1 indicates no repeat): vibrate p[], -1! The gr.camera.manualshoot takes 1 parameter, a " pointer" number used to! refer to the photo image taken: gr.camera.manualshoot p! After the above function, look at the photo! /sdcard/rfo-basic/data/image.jpg on your phone. The results are stored! in that temporary file (later in the tutorial, you'll learn how to use! the returned pointer value to display and manipulate the image in! graphic layouts).

The most important initial step in learning RFO Basic is learning how all the built-in commands/functions work, what their syntax is, and how they can be used together to perform complex operations and interactions with data. Progamming in general, and in fact all of computing, is all about processing data. Text input by the user, read from a file, or returned by a hardware sensor, for example, could potentially be used to determine what operation a program should perform next, or it could potentially contain a value which is plugged into a mathematical formula, or it could be used to move a graphic image to a given position on the screen, or it could be a block of text that needs to be searched and sorted for relavent content, etc. Text, images, sounds, etc. saved to files on your Android device or to FTP folders on a web server can be recalled and used later, edited, categorized, calculated upon, etc. as part of, for example, record keeping software, inventory, sales, and other data management systems, communications software, games, etc. Numbers, text, binary audio data, images and image manipulation parameters, video performance parameters, lists of related and categorized information about any real life topic, graphic coordinates and 3D movement computations in games, saved program settings, etc. - all of those things, and everything else that a computing device can interact with, is data of some sort, and all that data is processed by functions.

The list at https://laughton.com/basic/help/De_Re_BASIC!.htm#_Toc317902038 shows the format for all of RFO Basic's internal functions, also called it's " API". The rest of the document athttps://laughton.com/basic/help/De_Re_BASIC!.htm explains in detail the input and output parameter(s) of each of those functions, and contains several dozen example programs which demonstrate their use.

The example programs from the document above are also installed automatically on your Android device, when you install the RFO Basic app. You can run any of them in RFO Basic by clicking the Android Menu button, then Load -> Sample_Programs(d). A complete list of all the built-in RFO Basic functions is also available by clicking Menu -> More -> Commands. Those two resources together provide essential documentation for the entire RFO Basic language, right on your Android device.


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

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