SlideShare a Scribd company logo
1 of 10
Download to read offline
Ring Documentation, Release 1.5.1
See "log(2) = " + oMath.log(2) + nl
See "log10(1) = " + oMath.log10(1) + nl
See "log10(2) = " + oMath.log10(2) + nl
See "log10(10) = " + oMath.log10(10) + nl
See "Ceil(1.12) = " + oMath.Ceil(1.12) + nl
See "Ceil(1.72) = " + oMath.Ceil(1.72) + nl
See "Floor(1.12) = " + oMath.floor(1.12) + nl
See "Floor(1.72) = " + oMath.floor(1.72) + nl
See "fabs(1.12) = " + oMath.fabs(1.12) + nl
See "fabs(1.72) = " + oMath.fabs(1.72) + nl
See "pow(2,3) = " + oMath.pow(2,3) + nl
see "sqrt(16) = " + oMath.sqrt(16) + nl
for x = 1 to 20
see "Random number Max (100) : " + oMath.random(100) + nl
next
x = 1.1234567890123
for d = 0 to 14
oMath.decimals(d)
see x + nl
next
cKey = "hello"
h = 0
for x in cKey
h = oMath.unsigned(h,ascii(x),"+")
h = oMath.unsigned(h,oMath.unsigned(h,10,"<<"),"+")
r = oMath.unsigned(h,6,">>")
h = oMath.unsigned(h, r,"^")
next
h = oMath.unsigned(h,oMath.unsigned(h,3,"<<"),"+")
h = oMath.unsigned(h,oMath.unsigned(h,11,">>"),"^")
h = oMath.unsigned(h,oMath.unsigned(h,15,"<<"),"+")
see "Hash : " + h
output:
Test the Math Class Methods
Sin(0) = 0
Sin(90) radians = 0.89
Sin(90) degree = 1.00
Cos(0) = 1
Cos(90) radians = -0.45
Cos(90) degree = 0.00
Tan(0) = 0
Tan(90) radians = -2.00
Tan(90) degree = 1255.77
asin(0) = 0
acos(0) = 1.57
atan(0) = 0
atan2(1,1) = 0.79
43.8. Math Class 315
Ring Documentation, Release 1.5.1
sinh(0) = 0
sinh(1) = 1.18
cosh(0) = 1
cosh(1) = 1.54
tanh(0) = 0
tanh(1) = 0.76
exp(0) = 1
exp(1) = 2.72
log(1) = 0
log(2) = 0.69
log10(1) = 0
log10(2) = 0.30
log10(10) = 1
Ceil(1.12) = 2
Ceil(1.72) = 2
Floor(1.12) = 1
Floor(1.72) = 1
fabs(1.12) = 1.12
fabs(1.72) = 1.72
pow(2,3) = 8
sqrt(16) = 4
Random number Max (100) : 87
Random number Max (100) : 49
Random number Max (100) : 99
Random number Max (100) : 58
Random number Max (100) : 15
Random number Max (100) : 46
Random number Max (100) : 37
Random number Max (100) : 64
Random number Max (100) : 73
Random number Max (100) : 35
Random number Max (100) : 89
Random number Max (100) : 80
Random number Max (100) : 20
Random number Max (100) : 33
Random number Max (100) : 44
Random number Max (100) : 89
Random number Max (100) : 82
Random number Max (100) : 94
Random number Max (100) : 83
Random number Max (100) : 68
1
1.1
1.12
1.123
1.1235
1.12346
1.123457
1.1234568
1.12345679
1.123456789
1.1234567890
1.12345678901
1.123456789012
1.1234567890123
1.12345678901230
Hash : 3372029979.00000000000000
43.8. Math Class 316
Ring Documentation, Release 1.5.1
43.9 DateTime Class
Methods:
Method Description/Output
clock() The number of clock ticks from program start.
time() Get the system time.
date() Get the date.
timelist() List contains the date and the time information.
adddays(cDate,nDays) Return Date from cDate and after nDays
diffdays(cDate1,cDate2) Return the Number of days (cDate1 - cDate2)
example:
Load "stdlib.ring"
oDateTime = new datetime
See "Test the datetime Class Methods" + nl
See "Calculate performance" + nl
t1 = oDateTime.clock()
for x = 1 to 1000000 next
see oDateTime.clock() - t1 + nl
See "Time : " + oDateTime.time() + nl
See "Date : " + oDateTime.date() + nl
See oDateTime.TimeList()
See "Month Name : " + oDateTime.TimeList()[4]
cDate = oDateTime.date()
see cDate + nl
cDate = oDateTime.adddays(cDate,10)
see cDate + nl
cDate1 = oDateTime.date()
see cDate1 + nl
cDate2 = oDateTime.adddays(cDate1,10)
see cDate2 + nl
see "DiffDays = " + oDateTime.diffdays(cDate1,cDate2) + nl
see "DiffDays = " + oDateTime.diffdays(cDate2,cDate1) + nl
output:
Test the datetime Class Methods
Calculate performance
85
Time : 02:53:35
Date : 31/08/2016
Wed
Wednesday
Aug
August
08/31/16 02:53:35
31
43.9. DateTime Class 317
Ring Documentation, Release 1.5.1
02
02
244
08
53
AM
35
35
3
08/31/16
02:53:35
16
2016
Arab Standard Time
%
Month Name : August31/08/2016
10/09/2016
31/08/2016
10/09/2016
DiffDays = -10
DiffDays = 10
43.10 File Class
Methods:
43.10. File Class 318
Ring Documentation, Release 1.5.1
Method Description/Output
read(cFileName) Read the file content
write(cFileName,cStr) Write string to file
dir(cFolderPath) Get the folder contents (files & sub folders)
rename(cOld,cNew) Rename files using the Rename() function
remove(cFileName) Delete a file using the Remove() function
open(cFileName,cMode) Open a file using the Fopen() function
close() Close file
flush() Flushes the output buffer of a stream
reopen(cFileName,cMode) Open another file using the same file handle
tempfile() Creates a temp. file (binary).
seek(noffset,nwhence) Set the file position of the stream
tell() Know the current file position of a stream
rewind() Set the file position to the beginning of the file
getpos() Get handle to the current file position
setpos(poshandle) Set the current file position
clearerr() Clear the EOF error and the error indicators of a stream
eof() Test the end-of-file indicator
error() Test the error indicator
perror(cErrorMessage) Print error message to the stderr
getc() Get the next character from the stream
gets(nsize) Read new line from the stream
putc(cchar) Write a character to the stream
puts(cStr) Write a string to the stream
ungetc(cchar) Push a character to the stream
fread(nsize) Read data from a stream
fwrite(cString) Write data to a stream
exists(cFileName) Check if a file exists
example:
Load "stdlib.ring"
ofile = new file
See "Test the file Class Methods" + nl
see ofile.read(filename())
see nl
ofile.open(filename(),"r")
see ofile.gets(100) + nl
ofile.close()
43.11 System Class
Methods:
43.11. System Class 319
Ring Documentation, Release 1.5.1
Method Description/Output
system() Execute system commands
sysget() Get environment variables
ismsdos() Check if the operating system is MSDOS or not
iswindows() Check if the operating system is Windows or not
iswindows64() Check if the operating system is Windows 64bit or not
isunix() Check if the operating system is Unix or not
ismacosx() Check if the operating system is Mac OS X or not
islinux() Check if the operating system is Linux or not
isfreebsd() Check if the operating system is FreeBSD or not
isandroid() Check if the operating system is Android or not
windowsnl() Get the windows new line string
sysargv() Get the command line arguments passed to the ring script
filename() Get the active source file
example:
Load "stdlib.ring"
oSystem = new System
See "Test the System Class Methods" + nl
oSystem.system("dir")
see oSystem.sysget("path") + nl
see oSystem.ismsdos() + nl
see oSystem.iswindows() + nl
see oSystem.iswindows64() + nl
see oSystem.isunix() + nl
see oSystem.ismacosx() + nl
see oSystem.islinux() + nl
see oSystem.isfreebsd() + nl
see oSystem.isandroid() + nl
see oSystem.windowsnl() + nl
see oSystem.sysargv() + nl
see oSystem.filename() + nl
43.12 Debug Class
Methods:
Method Description/Output
eval(cCode) Execute code during the runtime from string.
raise(cError) Raise an exception.
assert(cCondition) Test condition before executing the code.
example:
Load "stdlib.ring"
oDebug = new Debug
See "Test the Debug Class Methods" + nl
oDebug.eval("see 'Hello'+nl")
try
x = 10
oDebug.assert(x=11)
43.12. Debug Class 320
Ring Documentation, Release 1.5.1
catch see "assert" + nl done
raise("Error!")
43.13 DataType Class
Methods:
Method Description/Output
isstring(vValue) We can know if the value is a string or not.
isnumber(vValue) We can know if the value is a number or not.
islist(vValue) We can know if the value is a list or not.
type(vValue) Know the type of a value
isnull(vValue) Check the value to know if it’s null or not.
isalnum(vValue) 1 if the value is digit/letter or 0 if not
isalpha(vValue) 1 if the value is a letter or 0 if not
iscntrl(vValue) 1 if the value is a control character (no printing position)
isdigit(vValue) 1 if the value is a digit or 0 if not
isgraph(vValue) 1 if the value can be printed (Except space) or 0 if not
islower(vValue) 1 if the value is lowercase letter or 0 if not
isprint(vValue) 1 if the value occupies a printing position or 0 if not
ispunct(vValue) 1 if the value is a punctuation character or 0 if not
isspace(vValue) 1 if the value is a white-space or 0 if not
isupper(vValue) 1 if the value is an uppercase alphabetic letter or 0 if not
isxdigit(vValue) 1 if the value is a hexdecimal digit character or 0 if not
example:
Load "stdlib.ring"
oDataType = new DataType
See "Test the DataType Class Methods" + nl
see oDataType.isstring("test") + nl
see oDataType.isnumber(1) + nl
see oDataType.islist(1:3) + nl
see oDataType.type("test") + nl
see oDataType.isnull(null) + nl
see oDataType.isalnum("Hello") + nl + # print 1
oDataType.isalnum("123456") + nl + # print 1
oDataType.isalnum("ABCabc123") + nl + # print 1
oDataType.isalnum("How are you") + nl # print 0 because of spaces
see oDataType.isalpha("Hello") + nl + # print 1
oDataType.isalpha("123456") + nl + # print 0
oDataType.isalpha("ABCabc123") + nl + # print 0
oDataType.isalpha("How are you") + nl # print 0
See oDataType.iscntrl("hello") + nl + # print 0
oDataType.iscntrl(nl) # print 1
see oDataType.isdigit("0123456789") + nl + # print 1
oDataType.isdigit("0123a") + nl
see oDataType.isgraph("abcdef") + nl + # print 1
oDataType.isgraph("abc def") + nl # print 0
see oDataType.islower("abcDEF") + nl + # print 0
oDataType.islower("ghi") + nl # print 1
see oDataType.isprint("Hello") + nl + # print 1
oDataType.isprint("Nice to see you") + nl + # print 1
oDataType.isprint(nl) + nl # print 0
43.13. DataType Class 321
Ring Documentation, Release 1.5.1
see oDataType.isprint("Hello") + nl # print 1
see oDataType.isupper("welcome") + nl + # print 0
oDataType.isupper("WELCOME") + nl # print 1
see oDataType.isxdigit("0123456789abcdef") + nl + # print 1
oDataType.isxdigit("123z") # print 0
Output:
Test the DataType Class Methods
1
1
1
STRING
1
1
1
1
0
1
0
0
0
0
11
0
1
0
0
1
1
1
0
1
0
1
1
0
43.14 Conversion Class
Methods:
Method Description/Output
number(vValue) Convert strings to numbers.
string(vValue) Convert numbers to strings.
ascii(vValue) Get the ASCII code for a letter.
char(vValue) Convert the ASCII code to character.
hex(vValue) Convert decimal to hexadecimal.
dec(vValue) Convert hexadecimal to decimal.
str2hex(vValue) Convert string characters to hexadecimal characters.
hex2str(vValue) Convert hexadecimal characters to string.
example:
Load "stdlib.ring"
43.14. Conversion Class 322
Ring Documentation, Release 1.5.1
oConversion = new conversion
See "Test the conversion Class Methods" + nl
See oConversion.number("3") + 5 + nl
See oConversion.string(3) + "5" + nl
See oConversion.Ascii("m") + nl
See oConversion.char(77) + nl
see oConversion.hex(162) + nl
see oConversion.dec("a2") + nl
cHex = oConversion.str2hex("Hello")
see cHex + nl
see oConversion.hex2str(cHex) + nl
Output:
Test the conversion Class Methods
8
35
109
M
a2
162
48656c6c6f
Hello
43.15 ODBC Class
Methods:
Method Description/Output
drivers() Get a list of ODBC drivers.
datasources() Get a list of ODBC data sources.
close() Free resources.
connect(cConString) Connect to the database.
disconnect() Close the connection.
execute(cSQL) Execute SQL Statements
colcount() Get columns count in the query result
fetch() Fetch a row from the query result
getdata(nCol) Get column value from the fetched row
tables() Get a list of tables inside the database
columns(cTableName) Get a list of columns inside the table
autocommit(lStatus) Enable or disable the auto commit feature
commit() Commit updates to the database
rollback() Rollback updates to the database
example:
Load "stdlib.ring"
oodbc = new odbc
See "Test the odbc Class Methods" + nl
oODBC {
see drivers()
see datasources()
See "Connect to database" + nl
see connect("DBQ=test.mdb;Driver={Microsoft Access Driver (*.mdb)}") + nl
See "Select data" + nl
43.15. ODBC Class 323
Ring Documentation, Release 1.5.1
see execute("select * from person") + nl
nMax = colcount()
See "Columns Count : " + nMax + nl
while fetch()
See "Row data:" + nl
for x = 1 to nMax
see getdata(x) + " - "
next
end
See "Close database..." + nl
disconnect()
close()
}
43.16 MySQL Class
Methods:
Method Description/Output
info() Return string contains the MySQL Client version.
error() Get the error message from the MySQL Client.
connect(cServer,cUser,cPass,cDatabase) Connect to the MySQL database server.
close() Close the connection to the MySQL database.
query(cQuery) Execute SQL queries.
insert_id() Get the inserted row id.
result() Get the query result (data without column names).
next_result() Move to the next query result.
columns() Get a list of columns names.
result2() Get all of the column names then the query result in one list.
escape_string(cStr) Before storing binary data and special characters in the database.
autocommit(lStatus) Enable or disable the auto commit feature.
commit() Commit updates to the database.
rollback() Rollback updates to the database.
example:
Load "stdlib.ring"
omysql = new mysql
See "Test the MySQL Class Methods" + nl
omysql {
see info() + nl
connect("localhost", "root", "root","mahdb")
see "Execute Query" + nl
query("SELECT * FROM Employee")
see "Print Result" + nl
see result2()
see "Close database" + nl
close()
}
Output:
Test the MySQL Class Methods
5.5.30
43.16. MySQL Class 324

More Related Content

What's hot

What's hot (20)

The Ring programming language version 1.6 book - Part 27 of 189
The Ring programming language version 1.6 book - Part 27 of 189The Ring programming language version 1.6 book - Part 27 of 189
The Ring programming language version 1.6 book - Part 27 of 189
 
The Ring programming language version 1.10 book - Part 54 of 212
The Ring programming language version 1.10 book - Part 54 of 212The Ring programming language version 1.10 book - Part 54 of 212
The Ring programming language version 1.10 book - Part 54 of 212
 
The Ring programming language version 1.8 book - Part 30 of 202
The Ring programming language version 1.8 book - Part 30 of 202The Ring programming language version 1.8 book - Part 30 of 202
The Ring programming language version 1.8 book - Part 30 of 202
 
The Ring programming language version 1.5.3 book - Part 44 of 184
The Ring programming language version 1.5.3 book - Part 44 of 184The Ring programming language version 1.5.3 book - Part 44 of 184
The Ring programming language version 1.5.3 book - Part 44 of 184
 
The Ring programming language version 1.4.1 book - Part 13 of 31
The Ring programming language version 1.4.1 book - Part 13 of 31The Ring programming language version 1.4.1 book - Part 13 of 31
The Ring programming language version 1.4.1 book - Part 13 of 31
 
The Ring programming language version 1.6 book - Part 38 of 189
The Ring programming language version 1.6 book - Part 38 of 189The Ring programming language version 1.6 book - Part 38 of 189
The Ring programming language version 1.6 book - Part 38 of 189
 
The Ring programming language version 1.9 book - Part 32 of 210
The Ring programming language version 1.9 book - Part 32 of 210The Ring programming language version 1.9 book - Part 32 of 210
The Ring programming language version 1.9 book - Part 32 of 210
 
The Ring programming language version 1.9 book - Part 53 of 210
The Ring programming language version 1.9 book - Part 53 of 210The Ring programming language version 1.9 book - Part 53 of 210
The Ring programming language version 1.9 book - Part 53 of 210
 
The Ring programming language version 1.5.1 book - Part 34 of 180
The Ring programming language version 1.5.1 book - Part 34 of 180The Ring programming language version 1.5.1 book - Part 34 of 180
The Ring programming language version 1.5.1 book - Part 34 of 180
 
The Ring programming language version 1.5.4 book - Part 44 of 185
The Ring programming language version 1.5.4 book - Part 44 of 185The Ring programming language version 1.5.4 book - Part 44 of 185
The Ring programming language version 1.5.4 book - Part 44 of 185
 
The Ring programming language version 1.5.4 book - Part 25 of 185
The Ring programming language version 1.5.4 book - Part 25 of 185The Ring programming language version 1.5.4 book - Part 25 of 185
The Ring programming language version 1.5.4 book - Part 25 of 185
 
The Ring programming language version 1.2 book - Part 24 of 84
The Ring programming language version 1.2 book - Part 24 of 84The Ring programming language version 1.2 book - Part 24 of 84
The Ring programming language version 1.2 book - Part 24 of 84
 
The Ring programming language version 1.5.2 book - Part 35 of 181
The Ring programming language version 1.5.2 book - Part 35 of 181The Ring programming language version 1.5.2 book - Part 35 of 181
The Ring programming language version 1.5.2 book - Part 35 of 181
 
The Ring programming language version 1.3 book - Part 16 of 88
The Ring programming language version 1.3 book - Part 16 of 88The Ring programming language version 1.3 book - Part 16 of 88
The Ring programming language version 1.3 book - Part 16 of 88
 
The Ring programming language version 1.2 book - Part 14 of 84
The Ring programming language version 1.2 book - Part 14 of 84The Ring programming language version 1.2 book - Part 14 of 84
The Ring programming language version 1.2 book - Part 14 of 84
 
The Ring programming language version 1.7 book - Part 39 of 196
The Ring programming language version 1.7 book - Part 39 of 196The Ring programming language version 1.7 book - Part 39 of 196
The Ring programming language version 1.7 book - Part 39 of 196
 
The Ring programming language version 1.9 book - Part 46 of 210
The Ring programming language version 1.9 book - Part 46 of 210The Ring programming language version 1.9 book - Part 46 of 210
The Ring programming language version 1.9 book - Part 46 of 210
 
The Ring programming language version 1.5.2 book - Part 33 of 181
The Ring programming language version 1.5.2 book - Part 33 of 181The Ring programming language version 1.5.2 book - Part 33 of 181
The Ring programming language version 1.5.2 book - Part 33 of 181
 
The Ring programming language version 1.8 book - Part 50 of 202
The Ring programming language version 1.8 book - Part 50 of 202The Ring programming language version 1.8 book - Part 50 of 202
The Ring programming language version 1.8 book - Part 50 of 202
 
Xm lparsers
Xm lparsersXm lparsers
Xm lparsers
 

Similar to The Ring programming language version 1.5.1 book - Part 35 of 180

Similar to The Ring programming language version 1.5.1 book - Part 35 of 180 (17)

The Ring programming language version 1.2 book - Part 25 of 84
The Ring programming language version 1.2 book - Part 25 of 84The Ring programming language version 1.2 book - Part 25 of 84
The Ring programming language version 1.2 book - Part 25 of 84
 
The Ring programming language version 1.5.3 book - Part 37 of 184
The Ring programming language version 1.5.3 book - Part 37 of 184The Ring programming language version 1.5.3 book - Part 37 of 184
The Ring programming language version 1.5.3 book - Part 37 of 184
 
The Ring programming language version 1.3 book - Part 28 of 88
The Ring programming language version 1.3 book - Part 28 of 88The Ring programming language version 1.3 book - Part 28 of 88
The Ring programming language version 1.3 book - Part 28 of 88
 
The Ring programming language version 1.5.3 book - Part 36 of 184
The Ring programming language version 1.5.3 book - Part 36 of 184The Ring programming language version 1.5.3 book - Part 36 of 184
The Ring programming language version 1.5.3 book - Part 36 of 184
 
The Ring programming language version 1.5.2 book - Part 24 of 181
The Ring programming language version 1.5.2 book - Part 24 of 181The Ring programming language version 1.5.2 book - Part 24 of 181
The Ring programming language version 1.5.2 book - Part 24 of 181
 
The Ring programming language version 1.3 book - Part 27 of 88
The Ring programming language version 1.3 book - Part 27 of 88The Ring programming language version 1.3 book - Part 27 of 88
The Ring programming language version 1.3 book - Part 27 of 88
 
The Ring programming language version 1.10 book - Part 46 of 212
The Ring programming language version 1.10 book - Part 46 of 212The Ring programming language version 1.10 book - Part 46 of 212
The Ring programming language version 1.10 book - Part 46 of 212
 
The Ring programming language version 1.4.1 book - Part 10 of 31
The Ring programming language version 1.4.1 book - Part 10 of 31The Ring programming language version 1.4.1 book - Part 10 of 31
The Ring programming language version 1.4.1 book - Part 10 of 31
 
The Ring programming language version 1.5.4 book - Part 36 of 185
The Ring programming language version 1.5.4 book - Part 36 of 185The Ring programming language version 1.5.4 book - Part 36 of 185
The Ring programming language version 1.5.4 book - Part 36 of 185
 
The Ring programming language version 1.5.2 book - Part 26 of 181
The Ring programming language version 1.5.2 book - Part 26 of 181The Ring programming language version 1.5.2 book - Part 26 of 181
The Ring programming language version 1.5.2 book - Part 26 of 181
 
The Ring programming language version 1.4 book - Part 10 of 30
The Ring programming language version 1.4 book - Part 10 of 30The Ring programming language version 1.4 book - Part 10 of 30
The Ring programming language version 1.4 book - Part 10 of 30
 
The Ring programming language version 1.7 book - Part 28 of 196
The Ring programming language version 1.7 book - Part 28 of 196The Ring programming language version 1.7 book - Part 28 of 196
The Ring programming language version 1.7 book - Part 28 of 196
 
The Ring programming language version 1.10 book - Part 33 of 212
The Ring programming language version 1.10 book - Part 33 of 212The Ring programming language version 1.10 book - Part 33 of 212
The Ring programming language version 1.10 book - Part 33 of 212
 
The Ring programming language version 1.2 book - Part 16 of 84
The Ring programming language version 1.2 book - Part 16 of 84The Ring programming language version 1.2 book - Part 16 of 84
The Ring programming language version 1.2 book - Part 16 of 84
 
The Ring programming language version 1.5.3 book - Part 54 of 184
The Ring programming language version 1.5.3 book - Part 54 of 184The Ring programming language version 1.5.3 book - Part 54 of 184
The Ring programming language version 1.5.3 book - Part 54 of 184
 
The Ring programming language version 1.8 book - Part 41 of 202
The Ring programming language version 1.8 book - Part 41 of 202The Ring programming language version 1.8 book - Part 41 of 202
The Ring programming language version 1.8 book - Part 41 of 202
 
The Ring programming language version 1.6 book - Part 183 of 189
The Ring programming language version 1.6 book - Part 183 of 189The Ring programming language version 1.6 book - Part 183 of 189
The Ring programming language version 1.6 book - Part 183 of 189
 

More from Mahmoud Samir Fayed

More from Mahmoud Samir Fayed (20)

The Ring programming language version 1.10 book - Part 212 of 212
The Ring programming language version 1.10 book - Part 212 of 212The Ring programming language version 1.10 book - Part 212 of 212
The Ring programming language version 1.10 book - Part 212 of 212
 
The Ring programming language version 1.10 book - Part 211 of 212
The Ring programming language version 1.10 book - Part 211 of 212The Ring programming language version 1.10 book - Part 211 of 212
The Ring programming language version 1.10 book - Part 211 of 212
 
The Ring programming language version 1.10 book - Part 210 of 212
The Ring programming language version 1.10 book - Part 210 of 212The Ring programming language version 1.10 book - Part 210 of 212
The Ring programming language version 1.10 book - Part 210 of 212
 
The Ring programming language version 1.10 book - Part 208 of 212
The Ring programming language version 1.10 book - Part 208 of 212The Ring programming language version 1.10 book - Part 208 of 212
The Ring programming language version 1.10 book - Part 208 of 212
 
The Ring programming language version 1.10 book - Part 207 of 212
The Ring programming language version 1.10 book - Part 207 of 212The Ring programming language version 1.10 book - Part 207 of 212
The Ring programming language version 1.10 book - Part 207 of 212
 
The Ring programming language version 1.10 book - Part 205 of 212
The Ring programming language version 1.10 book - Part 205 of 212The Ring programming language version 1.10 book - Part 205 of 212
The Ring programming language version 1.10 book - Part 205 of 212
 
The Ring programming language version 1.10 book - Part 206 of 212
The Ring programming language version 1.10 book - Part 206 of 212The Ring programming language version 1.10 book - Part 206 of 212
The Ring programming language version 1.10 book - Part 206 of 212
 
The Ring programming language version 1.10 book - Part 204 of 212
The Ring programming language version 1.10 book - Part 204 of 212The Ring programming language version 1.10 book - Part 204 of 212
The Ring programming language version 1.10 book - Part 204 of 212
 
The Ring programming language version 1.10 book - Part 203 of 212
The Ring programming language version 1.10 book - Part 203 of 212The Ring programming language version 1.10 book - Part 203 of 212
The Ring programming language version 1.10 book - Part 203 of 212
 
The Ring programming language version 1.10 book - Part 202 of 212
The Ring programming language version 1.10 book - Part 202 of 212The Ring programming language version 1.10 book - Part 202 of 212
The Ring programming language version 1.10 book - Part 202 of 212
 
The Ring programming language version 1.10 book - Part 201 of 212
The Ring programming language version 1.10 book - Part 201 of 212The Ring programming language version 1.10 book - Part 201 of 212
The Ring programming language version 1.10 book - Part 201 of 212
 
The Ring programming language version 1.10 book - Part 200 of 212
The Ring programming language version 1.10 book - Part 200 of 212The Ring programming language version 1.10 book - Part 200 of 212
The Ring programming language version 1.10 book - Part 200 of 212
 
The Ring programming language version 1.10 book - Part 199 of 212
The Ring programming language version 1.10 book - Part 199 of 212The Ring programming language version 1.10 book - Part 199 of 212
The Ring programming language version 1.10 book - Part 199 of 212
 
The Ring programming language version 1.10 book - Part 198 of 212
The Ring programming language version 1.10 book - Part 198 of 212The Ring programming language version 1.10 book - Part 198 of 212
The Ring programming language version 1.10 book - Part 198 of 212
 
The Ring programming language version 1.10 book - Part 197 of 212
The Ring programming language version 1.10 book - Part 197 of 212The Ring programming language version 1.10 book - Part 197 of 212
The Ring programming language version 1.10 book - Part 197 of 212
 
The Ring programming language version 1.10 book - Part 196 of 212
The Ring programming language version 1.10 book - Part 196 of 212The Ring programming language version 1.10 book - Part 196 of 212
The Ring programming language version 1.10 book - Part 196 of 212
 
The Ring programming language version 1.10 book - Part 195 of 212
The Ring programming language version 1.10 book - Part 195 of 212The Ring programming language version 1.10 book - Part 195 of 212
The Ring programming language version 1.10 book - Part 195 of 212
 
The Ring programming language version 1.10 book - Part 194 of 212
The Ring programming language version 1.10 book - Part 194 of 212The Ring programming language version 1.10 book - Part 194 of 212
The Ring programming language version 1.10 book - Part 194 of 212
 
The Ring programming language version 1.10 book - Part 193 of 212
The Ring programming language version 1.10 book - Part 193 of 212The Ring programming language version 1.10 book - Part 193 of 212
The Ring programming language version 1.10 book - Part 193 of 212
 
The Ring programming language version 1.10 book - Part 192 of 212
The Ring programming language version 1.10 book - Part 192 of 212The Ring programming language version 1.10 book - Part 192 of 212
The Ring programming language version 1.10 book - Part 192 of 212
 

Recently uploaded

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

The Ring programming language version 1.5.1 book - Part 35 of 180

  • 1. Ring Documentation, Release 1.5.1 See "log(2) = " + oMath.log(2) + nl See "log10(1) = " + oMath.log10(1) + nl See "log10(2) = " + oMath.log10(2) + nl See "log10(10) = " + oMath.log10(10) + nl See "Ceil(1.12) = " + oMath.Ceil(1.12) + nl See "Ceil(1.72) = " + oMath.Ceil(1.72) + nl See "Floor(1.12) = " + oMath.floor(1.12) + nl See "Floor(1.72) = " + oMath.floor(1.72) + nl See "fabs(1.12) = " + oMath.fabs(1.12) + nl See "fabs(1.72) = " + oMath.fabs(1.72) + nl See "pow(2,3) = " + oMath.pow(2,3) + nl see "sqrt(16) = " + oMath.sqrt(16) + nl for x = 1 to 20 see "Random number Max (100) : " + oMath.random(100) + nl next x = 1.1234567890123 for d = 0 to 14 oMath.decimals(d) see x + nl next cKey = "hello" h = 0 for x in cKey h = oMath.unsigned(h,ascii(x),"+") h = oMath.unsigned(h,oMath.unsigned(h,10,"<<"),"+") r = oMath.unsigned(h,6,">>") h = oMath.unsigned(h, r,"^") next h = oMath.unsigned(h,oMath.unsigned(h,3,"<<"),"+") h = oMath.unsigned(h,oMath.unsigned(h,11,">>"),"^") h = oMath.unsigned(h,oMath.unsigned(h,15,"<<"),"+") see "Hash : " + h output: Test the Math Class Methods Sin(0) = 0 Sin(90) radians = 0.89 Sin(90) degree = 1.00 Cos(0) = 1 Cos(90) radians = -0.45 Cos(90) degree = 0.00 Tan(0) = 0 Tan(90) radians = -2.00 Tan(90) degree = 1255.77 asin(0) = 0 acos(0) = 1.57 atan(0) = 0 atan2(1,1) = 0.79 43.8. Math Class 315
  • 2. Ring Documentation, Release 1.5.1 sinh(0) = 0 sinh(1) = 1.18 cosh(0) = 1 cosh(1) = 1.54 tanh(0) = 0 tanh(1) = 0.76 exp(0) = 1 exp(1) = 2.72 log(1) = 0 log(2) = 0.69 log10(1) = 0 log10(2) = 0.30 log10(10) = 1 Ceil(1.12) = 2 Ceil(1.72) = 2 Floor(1.12) = 1 Floor(1.72) = 1 fabs(1.12) = 1.12 fabs(1.72) = 1.72 pow(2,3) = 8 sqrt(16) = 4 Random number Max (100) : 87 Random number Max (100) : 49 Random number Max (100) : 99 Random number Max (100) : 58 Random number Max (100) : 15 Random number Max (100) : 46 Random number Max (100) : 37 Random number Max (100) : 64 Random number Max (100) : 73 Random number Max (100) : 35 Random number Max (100) : 89 Random number Max (100) : 80 Random number Max (100) : 20 Random number Max (100) : 33 Random number Max (100) : 44 Random number Max (100) : 89 Random number Max (100) : 82 Random number Max (100) : 94 Random number Max (100) : 83 Random number Max (100) : 68 1 1.1 1.12 1.123 1.1235 1.12346 1.123457 1.1234568 1.12345679 1.123456789 1.1234567890 1.12345678901 1.123456789012 1.1234567890123 1.12345678901230 Hash : 3372029979.00000000000000 43.8. Math Class 316
  • 3. Ring Documentation, Release 1.5.1 43.9 DateTime Class Methods: Method Description/Output clock() The number of clock ticks from program start. time() Get the system time. date() Get the date. timelist() List contains the date and the time information. adddays(cDate,nDays) Return Date from cDate and after nDays diffdays(cDate1,cDate2) Return the Number of days (cDate1 - cDate2) example: Load "stdlib.ring" oDateTime = new datetime See "Test the datetime Class Methods" + nl See "Calculate performance" + nl t1 = oDateTime.clock() for x = 1 to 1000000 next see oDateTime.clock() - t1 + nl See "Time : " + oDateTime.time() + nl See "Date : " + oDateTime.date() + nl See oDateTime.TimeList() See "Month Name : " + oDateTime.TimeList()[4] cDate = oDateTime.date() see cDate + nl cDate = oDateTime.adddays(cDate,10) see cDate + nl cDate1 = oDateTime.date() see cDate1 + nl cDate2 = oDateTime.adddays(cDate1,10) see cDate2 + nl see "DiffDays = " + oDateTime.diffdays(cDate1,cDate2) + nl see "DiffDays = " + oDateTime.diffdays(cDate2,cDate1) + nl output: Test the datetime Class Methods Calculate performance 85 Time : 02:53:35 Date : 31/08/2016 Wed Wednesday Aug August 08/31/16 02:53:35 31 43.9. DateTime Class 317
  • 4. Ring Documentation, Release 1.5.1 02 02 244 08 53 AM 35 35 3 08/31/16 02:53:35 16 2016 Arab Standard Time % Month Name : August31/08/2016 10/09/2016 31/08/2016 10/09/2016 DiffDays = -10 DiffDays = 10 43.10 File Class Methods: 43.10. File Class 318
  • 5. Ring Documentation, Release 1.5.1 Method Description/Output read(cFileName) Read the file content write(cFileName,cStr) Write string to file dir(cFolderPath) Get the folder contents (files & sub folders) rename(cOld,cNew) Rename files using the Rename() function remove(cFileName) Delete a file using the Remove() function open(cFileName,cMode) Open a file using the Fopen() function close() Close file flush() Flushes the output buffer of a stream reopen(cFileName,cMode) Open another file using the same file handle tempfile() Creates a temp. file (binary). seek(noffset,nwhence) Set the file position of the stream tell() Know the current file position of a stream rewind() Set the file position to the beginning of the file getpos() Get handle to the current file position setpos(poshandle) Set the current file position clearerr() Clear the EOF error and the error indicators of a stream eof() Test the end-of-file indicator error() Test the error indicator perror(cErrorMessage) Print error message to the stderr getc() Get the next character from the stream gets(nsize) Read new line from the stream putc(cchar) Write a character to the stream puts(cStr) Write a string to the stream ungetc(cchar) Push a character to the stream fread(nsize) Read data from a stream fwrite(cString) Write data to a stream exists(cFileName) Check if a file exists example: Load "stdlib.ring" ofile = new file See "Test the file Class Methods" + nl see ofile.read(filename()) see nl ofile.open(filename(),"r") see ofile.gets(100) + nl ofile.close() 43.11 System Class Methods: 43.11. System Class 319
  • 6. Ring Documentation, Release 1.5.1 Method Description/Output system() Execute system commands sysget() Get environment variables ismsdos() Check if the operating system is MSDOS or not iswindows() Check if the operating system is Windows or not iswindows64() Check if the operating system is Windows 64bit or not isunix() Check if the operating system is Unix or not ismacosx() Check if the operating system is Mac OS X or not islinux() Check if the operating system is Linux or not isfreebsd() Check if the operating system is FreeBSD or not isandroid() Check if the operating system is Android or not windowsnl() Get the windows new line string sysargv() Get the command line arguments passed to the ring script filename() Get the active source file example: Load "stdlib.ring" oSystem = new System See "Test the System Class Methods" + nl oSystem.system("dir") see oSystem.sysget("path") + nl see oSystem.ismsdos() + nl see oSystem.iswindows() + nl see oSystem.iswindows64() + nl see oSystem.isunix() + nl see oSystem.ismacosx() + nl see oSystem.islinux() + nl see oSystem.isfreebsd() + nl see oSystem.isandroid() + nl see oSystem.windowsnl() + nl see oSystem.sysargv() + nl see oSystem.filename() + nl 43.12 Debug Class Methods: Method Description/Output eval(cCode) Execute code during the runtime from string. raise(cError) Raise an exception. assert(cCondition) Test condition before executing the code. example: Load "stdlib.ring" oDebug = new Debug See "Test the Debug Class Methods" + nl oDebug.eval("see 'Hello'+nl") try x = 10 oDebug.assert(x=11) 43.12. Debug Class 320
  • 7. Ring Documentation, Release 1.5.1 catch see "assert" + nl done raise("Error!") 43.13 DataType Class Methods: Method Description/Output isstring(vValue) We can know if the value is a string or not. isnumber(vValue) We can know if the value is a number or not. islist(vValue) We can know if the value is a list or not. type(vValue) Know the type of a value isnull(vValue) Check the value to know if it’s null or not. isalnum(vValue) 1 if the value is digit/letter or 0 if not isalpha(vValue) 1 if the value is a letter or 0 if not iscntrl(vValue) 1 if the value is a control character (no printing position) isdigit(vValue) 1 if the value is a digit or 0 if not isgraph(vValue) 1 if the value can be printed (Except space) or 0 if not islower(vValue) 1 if the value is lowercase letter or 0 if not isprint(vValue) 1 if the value occupies a printing position or 0 if not ispunct(vValue) 1 if the value is a punctuation character or 0 if not isspace(vValue) 1 if the value is a white-space or 0 if not isupper(vValue) 1 if the value is an uppercase alphabetic letter or 0 if not isxdigit(vValue) 1 if the value is a hexdecimal digit character or 0 if not example: Load "stdlib.ring" oDataType = new DataType See "Test the DataType Class Methods" + nl see oDataType.isstring("test") + nl see oDataType.isnumber(1) + nl see oDataType.islist(1:3) + nl see oDataType.type("test") + nl see oDataType.isnull(null) + nl see oDataType.isalnum("Hello") + nl + # print 1 oDataType.isalnum("123456") + nl + # print 1 oDataType.isalnum("ABCabc123") + nl + # print 1 oDataType.isalnum("How are you") + nl # print 0 because of spaces see oDataType.isalpha("Hello") + nl + # print 1 oDataType.isalpha("123456") + nl + # print 0 oDataType.isalpha("ABCabc123") + nl + # print 0 oDataType.isalpha("How are you") + nl # print 0 See oDataType.iscntrl("hello") + nl + # print 0 oDataType.iscntrl(nl) # print 1 see oDataType.isdigit("0123456789") + nl + # print 1 oDataType.isdigit("0123a") + nl see oDataType.isgraph("abcdef") + nl + # print 1 oDataType.isgraph("abc def") + nl # print 0 see oDataType.islower("abcDEF") + nl + # print 0 oDataType.islower("ghi") + nl # print 1 see oDataType.isprint("Hello") + nl + # print 1 oDataType.isprint("Nice to see you") + nl + # print 1 oDataType.isprint(nl) + nl # print 0 43.13. DataType Class 321
  • 8. Ring Documentation, Release 1.5.1 see oDataType.isprint("Hello") + nl # print 1 see oDataType.isupper("welcome") + nl + # print 0 oDataType.isupper("WELCOME") + nl # print 1 see oDataType.isxdigit("0123456789abcdef") + nl + # print 1 oDataType.isxdigit("123z") # print 0 Output: Test the DataType Class Methods 1 1 1 STRING 1 1 1 1 0 1 0 0 0 0 11 0 1 0 0 1 1 1 0 1 0 1 1 0 43.14 Conversion Class Methods: Method Description/Output number(vValue) Convert strings to numbers. string(vValue) Convert numbers to strings. ascii(vValue) Get the ASCII code for a letter. char(vValue) Convert the ASCII code to character. hex(vValue) Convert decimal to hexadecimal. dec(vValue) Convert hexadecimal to decimal. str2hex(vValue) Convert string characters to hexadecimal characters. hex2str(vValue) Convert hexadecimal characters to string. example: Load "stdlib.ring" 43.14. Conversion Class 322
  • 9. Ring Documentation, Release 1.5.1 oConversion = new conversion See "Test the conversion Class Methods" + nl See oConversion.number("3") + 5 + nl See oConversion.string(3) + "5" + nl See oConversion.Ascii("m") + nl See oConversion.char(77) + nl see oConversion.hex(162) + nl see oConversion.dec("a2") + nl cHex = oConversion.str2hex("Hello") see cHex + nl see oConversion.hex2str(cHex) + nl Output: Test the conversion Class Methods 8 35 109 M a2 162 48656c6c6f Hello 43.15 ODBC Class Methods: Method Description/Output drivers() Get a list of ODBC drivers. datasources() Get a list of ODBC data sources. close() Free resources. connect(cConString) Connect to the database. disconnect() Close the connection. execute(cSQL) Execute SQL Statements colcount() Get columns count in the query result fetch() Fetch a row from the query result getdata(nCol) Get column value from the fetched row tables() Get a list of tables inside the database columns(cTableName) Get a list of columns inside the table autocommit(lStatus) Enable or disable the auto commit feature commit() Commit updates to the database rollback() Rollback updates to the database example: Load "stdlib.ring" oodbc = new odbc See "Test the odbc Class Methods" + nl oODBC { see drivers() see datasources() See "Connect to database" + nl see connect("DBQ=test.mdb;Driver={Microsoft Access Driver (*.mdb)}") + nl See "Select data" + nl 43.15. ODBC Class 323
  • 10. Ring Documentation, Release 1.5.1 see execute("select * from person") + nl nMax = colcount() See "Columns Count : " + nMax + nl while fetch() See "Row data:" + nl for x = 1 to nMax see getdata(x) + " - " next end See "Close database..." + nl disconnect() close() } 43.16 MySQL Class Methods: Method Description/Output info() Return string contains the MySQL Client version. error() Get the error message from the MySQL Client. connect(cServer,cUser,cPass,cDatabase) Connect to the MySQL database server. close() Close the connection to the MySQL database. query(cQuery) Execute SQL queries. insert_id() Get the inserted row id. result() Get the query result (data without column names). next_result() Move to the next query result. columns() Get a list of columns names. result2() Get all of the column names then the query result in one list. escape_string(cStr) Before storing binary data and special characters in the database. autocommit(lStatus) Enable or disable the auto commit feature. commit() Commit updates to the database. rollback() Rollback updates to the database. example: Load "stdlib.ring" omysql = new mysql See "Test the MySQL Class Methods" + nl omysql { see info() + nl connect("localhost", "root", "root","mahdb") see "Execute Query" + nl query("SELECT * FROM Employee") see "Print Result" + nl see result2() see "Close database" + nl close() } Output: Test the MySQL Class Methods 5.5.30 43.16. MySQL Class 324