SlideShare a Scribd company logo
Ring Documentation, Release 1.8
1.8
35.21 Shutdown() Function
Close the application
Syntax:
shutdown(nStatus) ---> Close the application
35.21. Shutdown() Function 281
CHAPTER
THIRTYSIX
EVAL() AND DEBUGGING
In this chapter we are going to learn about
• Error Handling using Try/Catch/Done
• Eval() function
• Raise() function
• Assert() function
36.1 Try/Catch/Done
Syntax:
Try
Statements...
Catch
Statements...
Done
The statements in the Try block will be executed, if any error happens then the statements in the catch block will be
executed.
Inside the catch block we can use the variable cCatchError to get the error message
Example:
Try
see 5/0
Catch
see "Catch!" + nl + cCatchError
Done
Output:
Catch!
Error (R1) : Cann't divide by zero !
36.2 Eval() Function
We can execute code during the runtime from string using the Eval() function
Syntax:
282
Ring Documentation, Release 1.8
Eval(cCode)
Example:
Eval("nOutput = 5+2*5 " )
See "5+2*5 = " + nOutput + nl
Eval("for x = 1 to 10 see x + nl next")
Eval("func test see 'message from test!' ")
test()
Output:
5+2*5 = 15
1
2
3
4
5
6
7
8
9
10
message from test!
We can use the Return command to return a value
Example:
see Eval("return 5*5")
Output:
25
36.3 Raise() Function
We can raise an exception using the Raise() function
Syntax:
Raise(cErrorMessage)
The function will display the error message then end the execution of the program.
We can use Try/Catch/Done to avoid exceptions generated by raise() function.
Example:
nMode = 10
if nMode < 0 or nMode > 5
raise("Error : nMode not in the range 1:4")
ok
Output:
Line 4 Error : nMode not in the range 1:4
In raise in file testsraise.ring
36.3. Raise() Function 283
Ring Documentation, Release 1.8
Example:
try
testmode(6)
catch
see "avoid raise!"
done
testmode(-1)
func testmode nMode
if nMode < 0 or nMode > 5
raise("Error : nMode not in the range 1:4")
ok
Output:
avoid raise!
Line 12 Error : nMode not in the range 1:4
In raise In function testmode() in file testsraise2.ring
called from line 7 in file testsraise2.ring
36.4 Assert() Function
We can use the Assert() function to test conditions before executing the code
If the test fail the program will be terminated with an error message contains the assert condition.
Syntax:
Assert( condition )
Example:
x = 10
assert( x = 10)
assert( x = 100 )
Output:
Line 3 Assertion Failed!
In assert in file testsassert.ring
36.4. Assert() Function 284
CHAPTER
THIRTYSEVEN
DEMO PROGRAMS
In this chapter we will see simple demo programs
• Language Shell
• Main Menu
37.1 Language Shell
We can create simple interactive programming environment using the next program
while true
see nl + "code:> "
give cCode
try
eval(cCode)
catch
see cCatchError
done
end
Output:
code:> see "hello world"
hello world
code:> for x = 1 to 10 see x + nl next
1
2
3
4
5
6
7
8
9
10
code:> func test see "Hello from test" + nl
code:> test()
Hello from test
code:> bye
285
Ring Documentation, Release 1.8
37.2 Main Menu
Example:
# Demo Program
while true
see "
Main Menu
===========
[1] Say Hello
[2] Sum two numbers
[3] Stars
[4] Fact
[5] Exit
" give nMenu see nl
# we can use Switch-ON-Other-OFF instead of IF-BUT-ELSE-OK
Switch nMenu
On 1 sayhello()
On 2 Sum()
On 3 Stars()
On 4
see "Enter Number : " give x
see "Output : "
Try
see Fact(number(x))
Catch
see "Error in parameters!" + nl
Done
On "5" return
Other see "bad option" + nl
Off
end
func sayhello
see "Enter your name ? " give fname
see "Hello " + fname + nl
func sum
see "number 1 : " give num1 see "number 2 : " give num2
see "Sum : " see 0 + num1 + num2
func stars
for x = 1 to 10
see space(8)
for y = 1 to x see "*" next see nl
next
func fact x if x = 0 return 1 else return x * fact(x-1) ok
37.2. Main Menu 286
Ring Documentation, Release 1.8
func space x y = "" for t=1 to x y += " " next return y
Output:
Main Menu
===========
[1] Say Hello
[2] Sum two numbers
[3] Stars
[4] Fact
[5] Exit
1
Enter your name ? Mahmoud Fayed
Hello Mahmoud Fayed
Main Menu
===========
[1] Say Hello
[2] Sum two numbers
[3] Stars
[4] Fact
[5] Exit
2
number 1 : 3
number 2 : 4
Sum : 7
Main Menu
===========
[1] Say Hello
[2] Sum two numbers
[3] Stars
[4] Fact
[5] Exit
3
*
**
***
****
*****
******
*******
********
*********
**********
Main Menu
===========
[1] Say Hello
[2] Sum two numbers
37.2. Main Menu 287
Ring Documentation, Release 1.8
[3] Stars
[4] Fact
[5] Exit
4
Enter Number : 5
Output : 120
Main Menu
===========
[1] Say Hello
[2] Sum two numbers
[3] Stars
[4] Fact
[5] Exit
5
37.2. Main Menu 288
CHAPTER
THIRTYEIGHT
ODBC FUNCTIONS
This chapter contains the ODBC functions provided by the Ring programming language.
• odbc_init()
• odbc_drivers()
• odbc_datasources()
• odbc_close()
• odbc_connect()
• odbc_disconnect()
• odbc_execute()
• odbc_colcount()
• odbc_fetch()
• odbc_getdata()
• odbc_tables()
• odbc_columns()
• odbc_autocommit()
• odbc_commit()
• odbc_rollback()
Before using the next function load the odbclib.ring library
load "odbclib.ring"
# Use ODBC functions
38.1 odbc_init() Function
We can create ODBC Handle using the odbc_init() function
Syntax:
odbc_init() ---> ODBC Handle
289
Ring Documentation, Release 1.8
38.2 odbc_drivers() Function
We can get a list of ODBC drivers using the odbc_drivers() function
Syntax:
odbc_drivers(ODBC Handle) ---> List of Drivers
38.3 odbc_datasources() Function
We can get a list of ODBC data sources using the odbc_datasources() function
Syntax:
odbc_datasources(ODBC Handle) ---> List of Data sources
38.4 odbc_close() Function
After the end of using ODBC functions we can free resources using ODBC_Close() function
Syntax:
odbc_close(ODBC Handle)
38.5 Print List of ODBC Drivers
The next example print a list of ODBC drivers.
See "ODBC test 1" + nl
oODBC = odbc_init()
See "Drivers " + nl
see odbc_drivers(oODBC)
odbc_close(oODBC)
Output:
ODBC test 1
Drivers
Microsoft Access-Treiber (*.mdb) - SQLLevel=0
Driver do Microsoft Paradox (*.db ) - SQLLevel=0
Driver do Microsoft Excel(*.xls) - SQLLevel=0
Microsoft Text Driver (*.txt; *.csv) - SQLLevel=0
Driver da Microsoft para arquivos texto (*.txt; *.csv) - SQLLevel=0
Microsoft dBase-Treiber (*.dbf) - SQLLevel=0
SQL Server - CPTimeout=60
Microsoft Excel Driver (*.xls) - SQLLevel=0
Driver do Microsoft dBase (*.dbf) - SQLLevel=0
Microsoft Paradox-Treiber (*.db ) - SQLLevel=0
Microsoft ODBC for Oracle - CPTimeout=120
Microsoft Text-Treiber (*.txt; *.csv) - SQLLevel=0
Microsoft Excel-Treiber (*.xls) - SQLLevel=0
Microsoft Access Driver (*.mdb) - SQLLevel=0
Driver do Microsoft Access (*.mdb) - SQLLevel=0
38.2. odbc_drivers() Function 290

More Related Content

What's hot (20)

PDF
The Ring programming language version 1.7 book - Part 91 of 196
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.3 book - Part 18 of 88
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.7 book - Part 30 of 196
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 101 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.4 book - Part 7 of 30
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.6 book - Part 184 of 189
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 35 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.1 book - Part 9 of 180
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.1 book - Part 175 of 180
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.8 book - Part 31 of 202
Mahmoud Samir Fayed
 
PPTX
Unit Testing with Foq
Phillip Trelford
 
PDF
The Ring programming language version 1.2 book - Part 21 of 84
Mahmoud Samir Fayed
 
PPTX
The secret unit testing tools no one ever told you about
Dror Helper
 
PDF
The Ring programming language version 1.9 book - Part 33 of 210
Mahmoud Samir Fayed
 
PPTX
Unit testing patterns for concurrent code
Dror Helper
 
PDF
The Ring programming language version 1.3 book - Part 23 of 88
Mahmoud Samir Fayed
 
PDF
Java VS Python
Simone Federici
 
PPTX
From clever code to better code
Dror Helper
 
PDF
The Ring programming language version 1.5.2 book - Part 31 of 181
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.9 book - Part 99 of 210
Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 91 of 196
Mahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 18 of 88
Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 30 of 196
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 101 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.4 book - Part 7 of 30
Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 184 of 189
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 35 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 9 of 180
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 175 of 180
Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 31 of 202
Mahmoud Samir Fayed
 
Unit Testing with Foq
Phillip Trelford
 
The Ring programming language version 1.2 book - Part 21 of 84
Mahmoud Samir Fayed
 
The secret unit testing tools no one ever told you about
Dror Helper
 
The Ring programming language version 1.9 book - Part 33 of 210
Mahmoud Samir Fayed
 
Unit testing patterns for concurrent code
Dror Helper
 
The Ring programming language version 1.3 book - Part 23 of 88
Mahmoud Samir Fayed
 
Java VS Python
Simone Federici
 
From clever code to better code
Dror Helper
 
The Ring programming language version 1.5.2 book - Part 31 of 181
Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 99 of 210
Mahmoud Samir Fayed
 

Similar to The Ring programming language version 1.8 book - Part 32 of 202 (20)

PDF
The Ring programming language version 1.3 book - Part 83 of 88
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.3 book - Part 89 of 184
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.3 book - Part 188 of 194
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.3 book - Part 25 of 184
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.6 book - Part 183 of 189
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.4 book - Part 29 of 30
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.8 book - Part 94 of 202
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 14 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.2 book - Part 175 of 181
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.7 book - Part 7 of 196
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.8 book - Part 95 of 202
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.7 book - Part 85 of 196
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.2 book - Part 7 of 181
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.8 book - Part 88 of 202
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.2 book - Part 29 of 181
Mahmoud Samir Fayed
 
PPTX
Python for Beginners(v2)
Panimalar Engineering College
 
PDF
The Ring programming language version 1.9 book - Part 32 of 210
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.9 book - Part 92 of 210
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.4 book - Part 179 of 185
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.3 book - Part 189 of 194
Mahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 83 of 88
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 89 of 184
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 188 of 194
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 25 of 184
Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 183 of 189
Mahmoud Samir Fayed
 
The Ring programming language version 1.4 book - Part 29 of 30
Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 94 of 202
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 14 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 175 of 181
Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 7 of 196
Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 95 of 202
Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 85 of 196
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 7 of 181
Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 88 of 202
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 29 of 181
Mahmoud Samir Fayed
 
Python for Beginners(v2)
Panimalar Engineering College
 
The Ring programming language version 1.9 book - Part 32 of 210
Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 92 of 210
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 179 of 185
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 189 of 194
Mahmoud Samir Fayed
 
Ad

More from Mahmoud Samir Fayed (20)

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

Recently uploaded (20)

PDF
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
PPTX
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
PPTX
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
PPTX
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
PDF
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
Human Resources Information System (HRIS)
Amity University, Patna
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 

The Ring programming language version 1.8 book - Part 32 of 202

  • 1. Ring Documentation, Release 1.8 1.8 35.21 Shutdown() Function Close the application Syntax: shutdown(nStatus) ---> Close the application 35.21. Shutdown() Function 281
  • 2. CHAPTER THIRTYSIX EVAL() AND DEBUGGING In this chapter we are going to learn about • Error Handling using Try/Catch/Done • Eval() function • Raise() function • Assert() function 36.1 Try/Catch/Done Syntax: Try Statements... Catch Statements... Done The statements in the Try block will be executed, if any error happens then the statements in the catch block will be executed. Inside the catch block we can use the variable cCatchError to get the error message Example: Try see 5/0 Catch see "Catch!" + nl + cCatchError Done Output: Catch! Error (R1) : Cann't divide by zero ! 36.2 Eval() Function We can execute code during the runtime from string using the Eval() function Syntax: 282
  • 3. Ring Documentation, Release 1.8 Eval(cCode) Example: Eval("nOutput = 5+2*5 " ) See "5+2*5 = " + nOutput + nl Eval("for x = 1 to 10 see x + nl next") Eval("func test see 'message from test!' ") test() Output: 5+2*5 = 15 1 2 3 4 5 6 7 8 9 10 message from test! We can use the Return command to return a value Example: see Eval("return 5*5") Output: 25 36.3 Raise() Function We can raise an exception using the Raise() function Syntax: Raise(cErrorMessage) The function will display the error message then end the execution of the program. We can use Try/Catch/Done to avoid exceptions generated by raise() function. Example: nMode = 10 if nMode < 0 or nMode > 5 raise("Error : nMode not in the range 1:4") ok Output: Line 4 Error : nMode not in the range 1:4 In raise in file testsraise.ring 36.3. Raise() Function 283
  • 4. Ring Documentation, Release 1.8 Example: try testmode(6) catch see "avoid raise!" done testmode(-1) func testmode nMode if nMode < 0 or nMode > 5 raise("Error : nMode not in the range 1:4") ok Output: avoid raise! Line 12 Error : nMode not in the range 1:4 In raise In function testmode() in file testsraise2.ring called from line 7 in file testsraise2.ring 36.4 Assert() Function We can use the Assert() function to test conditions before executing the code If the test fail the program will be terminated with an error message contains the assert condition. Syntax: Assert( condition ) Example: x = 10 assert( x = 10) assert( x = 100 ) Output: Line 3 Assertion Failed! In assert in file testsassert.ring 36.4. Assert() Function 284
  • 5. CHAPTER THIRTYSEVEN DEMO PROGRAMS In this chapter we will see simple demo programs • Language Shell • Main Menu 37.1 Language Shell We can create simple interactive programming environment using the next program while true see nl + "code:> " give cCode try eval(cCode) catch see cCatchError done end Output: code:> see "hello world" hello world code:> for x = 1 to 10 see x + nl next 1 2 3 4 5 6 7 8 9 10 code:> func test see "Hello from test" + nl code:> test() Hello from test code:> bye 285
  • 6. Ring Documentation, Release 1.8 37.2 Main Menu Example: # Demo Program while true see " Main Menu =========== [1] Say Hello [2] Sum two numbers [3] Stars [4] Fact [5] Exit " give nMenu see nl # we can use Switch-ON-Other-OFF instead of IF-BUT-ELSE-OK Switch nMenu On 1 sayhello() On 2 Sum() On 3 Stars() On 4 see "Enter Number : " give x see "Output : " Try see Fact(number(x)) Catch see "Error in parameters!" + nl Done On "5" return Other see "bad option" + nl Off end func sayhello see "Enter your name ? " give fname see "Hello " + fname + nl func sum see "number 1 : " give num1 see "number 2 : " give num2 see "Sum : " see 0 + num1 + num2 func stars for x = 1 to 10 see space(8) for y = 1 to x see "*" next see nl next func fact x if x = 0 return 1 else return x * fact(x-1) ok 37.2. Main Menu 286
  • 7. Ring Documentation, Release 1.8 func space x y = "" for t=1 to x y += " " next return y Output: Main Menu =========== [1] Say Hello [2] Sum two numbers [3] Stars [4] Fact [5] Exit 1 Enter your name ? Mahmoud Fayed Hello Mahmoud Fayed Main Menu =========== [1] Say Hello [2] Sum two numbers [3] Stars [4] Fact [5] Exit 2 number 1 : 3 number 2 : 4 Sum : 7 Main Menu =========== [1] Say Hello [2] Sum two numbers [3] Stars [4] Fact [5] Exit 3 * ** *** **** ***** ****** ******* ******** ********* ********** Main Menu =========== [1] Say Hello [2] Sum two numbers 37.2. Main Menu 287
  • 8. Ring Documentation, Release 1.8 [3] Stars [4] Fact [5] Exit 4 Enter Number : 5 Output : 120 Main Menu =========== [1] Say Hello [2] Sum two numbers [3] Stars [4] Fact [5] Exit 5 37.2. Main Menu 288
  • 9. CHAPTER THIRTYEIGHT ODBC FUNCTIONS This chapter contains the ODBC functions provided by the Ring programming language. • odbc_init() • odbc_drivers() • odbc_datasources() • odbc_close() • odbc_connect() • odbc_disconnect() • odbc_execute() • odbc_colcount() • odbc_fetch() • odbc_getdata() • odbc_tables() • odbc_columns() • odbc_autocommit() • odbc_commit() • odbc_rollback() Before using the next function load the odbclib.ring library load "odbclib.ring" # Use ODBC functions 38.1 odbc_init() Function We can create ODBC Handle using the odbc_init() function Syntax: odbc_init() ---> ODBC Handle 289
  • 10. Ring Documentation, Release 1.8 38.2 odbc_drivers() Function We can get a list of ODBC drivers using the odbc_drivers() function Syntax: odbc_drivers(ODBC Handle) ---> List of Drivers 38.3 odbc_datasources() Function We can get a list of ODBC data sources using the odbc_datasources() function Syntax: odbc_datasources(ODBC Handle) ---> List of Data sources 38.4 odbc_close() Function After the end of using ODBC functions we can free resources using ODBC_Close() function Syntax: odbc_close(ODBC Handle) 38.5 Print List of ODBC Drivers The next example print a list of ODBC drivers. See "ODBC test 1" + nl oODBC = odbc_init() See "Drivers " + nl see odbc_drivers(oODBC) odbc_close(oODBC) Output: ODBC test 1 Drivers Microsoft Access-Treiber (*.mdb) - SQLLevel=0 Driver do Microsoft Paradox (*.db ) - SQLLevel=0 Driver do Microsoft Excel(*.xls) - SQLLevel=0 Microsoft Text Driver (*.txt; *.csv) - SQLLevel=0 Driver da Microsoft para arquivos texto (*.txt; *.csv) - SQLLevel=0 Microsoft dBase-Treiber (*.dbf) - SQLLevel=0 SQL Server - CPTimeout=60 Microsoft Excel Driver (*.xls) - SQLLevel=0 Driver do Microsoft dBase (*.dbf) - SQLLevel=0 Microsoft Paradox-Treiber (*.db ) - SQLLevel=0 Microsoft ODBC for Oracle - CPTimeout=120 Microsoft Text-Treiber (*.txt; *.csv) - SQLLevel=0 Microsoft Excel-Treiber (*.xls) - SQLLevel=0 Microsoft Access Driver (*.mdb) - SQLLevel=0 Driver do Microsoft Access (*.mdb) - SQLLevel=0 38.2. odbc_drivers() Function 290