CubicPower 3D Taipei Street VR Viewer has got to the Taiwan Open
Data competition final. This service combines the OpenStreetMap and
Taipei city marks data to produce a virtual 3D view on the browser.
Chao-Yih Hsia (Mark Hsia) Founder of the CubicPower.idv.tw site. Focuses on animation, streaming data, big data engine and applications development. Twitter: Mark Hsia @HsiaMark
2016-07-27
2016-06-28
Raise or Lower Terrain by the Unity Terrain Editor
Steps of building terrain by the Unity Terrain Editor:
1. Start
1. Start
GameObject> 3D Object> Terrain
Hierarchy> Terrain
Inspector> Terrain> Raise/Lower Terrain
Use the selected brush to raise terrain in the scene view.
Inspector> Terrain> Paint Height
Inspector> Terrain> Settings> Height> 20
Brush inner lower area.
Inspector > Terrain> Settings> Height> 50
Brush outer higher area.
2016-06-15
Debug the Odoo in Ubuntu with different user name
Once we've installed the Odoo as a service in Ubuntu, Odoo will be started up automatically. If we want to debug the Odoo, we should stop the Odoo service first. Also, we will encounter the "Peer authentication failed for user "odoo"" error if our login user name is not odoo. In order to conquer these problems we should do the following steps:
./odoo.py -r odoo
Reference:
Peer authentication failed for user "odoo"
1. Stop service:
sudo service odoo stop
2. set the user odoo as a trusted user to all databases from local:
sudo nano /etc/postgresql/9.3/main/pg_hba.conf
then add the following line into the file:
local all odoo trust
then restart the postgresql:
sudo service postgresql restart
3. Start odoo with the db user odoo:
cd /usr/bin./odoo.py -r odoo
Reference:
Peer authentication failed for user "odoo"
2016-05-30
Build our own Linux Web Server with XAMPP
If we want to set up our own web server on the Linux platform, installing an XAMPP (Apache+MariaDB+PHP+Perl on the different platforms) will be the easiest way. Here I show the basic installation procedures as follows:
1. Download a copy of an XAMPP Linux version from the site Download XAMPP . For example, we can download the file
2. Run cd command to go to your directory and execute the installation file:
We will see a newly generated pop-up window. Just click the Next button and uncheck the “Learn more about BitNami for XAMPP” checkbox. We'll install the XAMPP and run it.
To stop the XAMPP, we can:
sudo /opt/lampp/lampp start
References:
1. How to Install XAMPP 1.8.3 for Linux in Ubuntu Desktop
2. Setting Security for XAMPP
1. Download a copy of an XAMPP Linux version from the site Download XAMPP . For example, we can download the file
https://www.apachefriends.org/xampp-files/5.5.35/xampp-linux-x64-5.5.35-0-installer.run
2. Run cd command to go to your directory and execute the installation file:
sudo chmod +x xampp-linux-x64-5.5.35-0-installer.run
sudo ./xampp-linux-x64-5.5.35-0-installer.run
We will see a newly generated pop-up window. Just click the Next button and uncheck the “Learn more about BitNami for XAMPP” checkbox. We'll install the XAMPP and run it.
To stop the XAMPP, we can:
sudo /opt/lampp/lampp stop
To strat the XAMPP, we can:sudo /opt/lampp/lampp start
We can try the url http://localhost from our browser to see the page on our server.
And then one important thing to do- set the Security settings:
sudo /opt/lampp/lampp security
Always say yes by pressing Enter key and key in our password.References:
1. How to Install XAMPP 1.8.3 for Linux in Ubuntu Desktop
2. Setting Security for XAMPP
2016-05-21
the Muscular Robot-SkinSuitBotM shows the 180 degree Roundhouse Kick
Let's take a look at the Muscular Robot-SkinSuitBotM. It is capable to do lots of the physical fitness movements. He it shows 180 degree Roundhouse Kick:
We can swing the right leg only.
Or we can lift the left knee first,
and swing the right leg.
Also, we can swing the left leg
and followed by a right leg swing.
2016-05-18
SkinsuitBotQ on the Stage @HsiaMark
SkinsuitBotQ is now on the Stage with several postures. @HsiaMark
Check out the video!
And look at some screen captures:
2016-05-17
Install a Camera and a Realtime Stream Server on the Raspberry Pi
A Raspberry Pi with a camera can become a real time stream sever. We can select either
UV4L or mjpg-streamer to transmit its streaming data.
UV4L(User space Video4Linux collection) includes a full-featured Streaming Server component providing a set of solutions for live audio & video streaming, casting/mirroring and conferencing over the web.
On the other hand, the MJPG-streamer takes JPGs from Linux-UVC compatible webcams, file system or other input plugins and streams them as M-JPEG via HTTP to web browsers, VLC and other software.
We can install both on the Raspberry Pi.
First, we connect the Camera bus to the Raspberry Pi board, and the start the raspi-config:
sudo raspi-config
Select item 6 to enable the camera:
6 Enable Camera .......
Reboot and run tests:
raspistill -o cam.jpg
raspivid -o vid.h264
The image/video window will be shown on the console.
Install MJPEG Stream components:
sudo apt-get update
sudo apt-get install subversion
sudo apt-get install libjpeg8-dev
sudo apt-get install imagemagick
sudo apt-get install libv4l-dev
Get mjpg-streamer from svn:
svn co https://svn.code.sf.net/p/mjpg-streamer/code/
cd code/mjpg-streamer
make
sudo make install
wget http://www.linux-projects.org/listing/uv4l_repo/lrkey.asc && sudo apt-key add ./lrkey.asc
sudo nano /etc/apt/sources.list
Add this line to the file and exit:
deb http://www.linux-projects.org/listing/uv4l_repo/raspbian/ wheezy main
sudo apt-get update
sudo apt-get install uv4l uv4l-raspicam
For autostart service:
sudo apt-get install uv4l-raspicam-extras
sudo reboot
Install uv4l:
sudo pkill uv4l
sudo apt-get update
sudo apt-get install uv4l-uvc
sudo apt-get install uv4l-xscreen
sudo apt-get install uv4l-mjpegstream
sudo apt-get install uv4l-server
sudo reboot
The WebRTC extension for the Streaming Server is also available:
sudo apt-get install uv4l-webrtc
uv4l --auto-video_nr --driver raspicam --encoding mjpeg --server-option '--port=9000' or
uv4l --auto-video_nr --driver raspicam --encoding mjpeg --server-option '--port=9000' --driver raspicam --rotation 180 --width 352 --height 288
Use Browser to link to the uv4l server:
http://192.168.0.x:9000
sudo modprobe bcm2835-v4l2
cd code/mjpg-streamer
./mjpg_streamer -i "./input_uvc.so" -o "./output_http.so -w ./www"
Use Browser to link to the mjpg-streamer:
http://192.168.0.x:8080
Reference:
https://dotblogs.com.tw/bowwowxx/2015/06/08/151511
2016-05-12
SkinsuitBotQ-The animation robot actress Q with a leopard print skin suit
May I present you the SkinsuitBotQ ! @HsiaMark
The animation robot actress Q with Skin Suit.
Robot actress Q wears a leopard print skin suit.
The animation robot actress Q with Skin Suit.
Robot actress Q wears a leopard print skin suit.
Let's get closer.
She smiles to the audience.
And says thank you.
Also up there,
Looks around the other side.
Let's watch the video of the SkinsuitBotQ 1:
2016-05-05
Basic Tutorial Samples of Odoo Object Relational Mapping(ORM)
The traditional Odoo Object Relational Mapping(ORM) API passes the database cursor, user id,
context dictionary and record ids(usually denoted as
self.browse(cr, uid, sids, context=context)
These parameters have been removed from the new Record style API since Odoo 8. But the programs of Odoo are written in traditional style. So it is still very important to understand how it works.
The basic ORM method is search(). We can provide some searching criteria (domain) to the method like [('uuid', '=', uuid)] to screen out the records we want. And the browse() returns the records we need according the input ids parameter.
Here is the sample of search() and browse():
// Sample of Reading records of other class: use pool[] first
def users_infos(self, cr, uid, ids, context=None):
""" get the user infos for all the user in the session """
for session in self.pool["im_chat.session"].browse(cr, uid, ids, context=context):
users_infos = self.pool["res.users"].read(cr, uid, [u.id for u in session.user_ids], ['id','name', 'im_status'], context=context)
return users_infos
The last sample of this tutorial is write(). Just use it to write data back to the records.
def update_state(self, cr, uid, uuid, state=None, context=None):
""" modify the fold_state of the given session, and broadcast to himself (e.i. : to sync multiple tabs) """
domain = [('user_id','=',uid), ('session_id.uuid','=',uuid)]
ids = self.pool['im_chat.conversation_state'].search(cr, uid, domain, context=context)
for sr in self.pool['im_chat.conversation_state'].browse(cr, uid, ids, context=context):
if not state:
state = sr.state
if sr.state == 'open':
state = 'folded'
else:
state = 'open'
self.pool['im_chat.conversation_state'].write(cr, uid, ids, {'state': state}, context=context)
self.pool['bus.bus'].sendone(cr, uid, (cr.dbname, 'im_chat.session', uid), sr.session_id.session_info())
cr
, uid
,
context
, ids
) to all methods. For example:self.browse(cr, uid, sids, context=context)
These parameters have been removed from the new Record style API since Odoo 8. But the programs of Odoo are written in traditional style. So it is still very important to understand how it works.
The basic ORM method is search(). We can provide some searching criteria (domain) to the method like [('uuid', '=', uuid)] to screen out the records we want. And the browse() returns the records we need according the input ids parameter.
Here is the sample of search() and browse():
// Sample of reading own records: search(),browse() directly
def is_in_session(self, cr, uid, uuid, user_id, context=None):
""" return if the given user_id is in the session """
sids = self.search(cr, uid, [('uuid', '=', uuid)], context=context, limit=1)
for session in self.browse(cr, uid, sids, context=context):
return user_id and user_id in [u.id for u in session.user_ids]
return False
""" return if the given user_id is in the session """
sids = self.search(cr, uid, [('uuid', '=', uuid)], context=context, limit=1)
for session in self.browse(cr, uid, sids, context=context):
return user_id and user_id in [u.id for u in session.user_ids]
return False
If we need to access the data of another class, we should use the pool[] to access that class first.
def users_infos(self, cr, uid, ids, context=None):
""" get the user infos for all the user in the session """
for session in self.pool["im_chat.session"].browse(cr, uid, ids, context=context):
users_infos = self.pool["res.users"].read(cr, uid, [u.id for u in session.user_ids], ['id','name', 'im_status'], context=context)
return users_infos
Another useful method is search_read(). It is a combination of a search() and a read(). We need to prepare the domain for search() and the fields list for read(). Look at this example:
// Sample of Odoo ORM search_read(): Performs a search() followed by a read()
def session_info(self, cr, uid, ids, context=None):
""" get the session info/header of a given session """
for session in self.browse(cr, uid, ids, context=context):
info = {
'uuid': session.uuid,
'users': session.users_infos(),
'state': 'open',
}
# add uid_state if available
if uid:
domain = [('user_id','=',uid), ('session_id','=',session.id)]
uid_state = self.pool['im_chat.conversation_state'].search_read(cr, uid, domain, ['state'], context=context)
if uid_state:
info['state'] = uid_state[0]['state']
return info
""" get the session info/header of a given session """
for session in self.browse(cr, uid, ids, context=context):
info = {
'uuid': session.uuid,
'users': session.users_infos(),
'state': 'open',
}
# add uid_state if available
if uid:
domain = [('user_id','=',uid), ('session_id','=',session.id)]
uid_state = self.pool['im_chat.conversation_state'].search_read(cr, uid, domain, ['state'], context=context)
if uid_state:
info['state'] = uid_state[0]['state']
return info
The last sample of this tutorial is write(). Just use it to write data back to the records.
// Sample of Odoo ORM write:
""" modify the fold_state of the given session, and broadcast to himself (e.i. : to sync multiple tabs) """
domain = [('user_id','=',uid), ('session_id.uuid','=',uuid)]
ids = self.pool['im_chat.conversation_state'].search(cr, uid, domain, context=context)
for sr in self.pool['im_chat.conversation_state'].browse(cr, uid, ids, context=context):
if not state:
state = sr.state
if sr.state == 'open':
state = 'folded'
else:
state = 'open'
self.pool['im_chat.conversation_state'].write(cr, uid, ids, {'state': state}, context=context)
self.pool['bus.bus'].sendone(cr, uid, (cr.dbname, 'im_chat.session', uid), sr.session_id.session_info())
2016-05-02
Experience of Installing Odoo 8.0 on the Ubuntu Platform
I've tested he installation procedures many times by following Odoo document and google search referral, but there is no successful experience.
The first problem I met was Ubuntu version. I've installed Ubuntu 16.04. But its default Python is version 3. Odoo needs version 2.7. Many blogs have their own scripts to cope with this issue. But I decided to go back to Ubuntu 14.04 to make my life easier.
Then I downloaded the .Deb files from Odoo and install by double clicking the Deb file and clicking the Install button. But still,it was not working.
Finally, go back to "apt-get install" follow some steps in the Odoo installation document with some changes. It works eventually!
The first problem I met was Ubuntu version. I've installed Ubuntu 16.04. But its default Python is version 3. Odoo needs version 2.7. Many blogs have their own scripts to cope with this issue. But I decided to go back to Ubuntu 14.04 to make my life easier.
Then I downloaded the .Deb files from Odoo and install by double clicking the Deb file and clicking the Install button. But still,it was not working.
Finally, go back to "apt-get install" follow some steps in the Odoo installation document with some changes. It works eventually!
The steps are:
Install postgresql:
sudo apt-get install postgresql-9.3
Install pgadmin3:
sudo apt-get install pgadmin3
Install Odoo on Ububtu 14.04.4
sudo wget -O - https://nightly.odoo.com/odoo.key | sudo apt-key add -
cd /etc/apt
sudo vi sources.list
Insert "deb http://nightly.odoo.com/8.0/nightly/deb/ ./" into the file
sudo apt-get update
sudo apt-get install odoo
In this document, there is a section teaching us how to install in the Deb style Linux:
Deb
To install Odoo 8.0 on Debian-based distribution, execute the following
commands as root:
# wget -O - https://nightly.odoo.com/odoo.key | apt-key add - # echo "deb http://nightly.odoo.com/8.0/nightly/deb/ ./" >> /etc/apt/sources.list # apt-get update && apt-get install odoo
This will automatically install all dependencies, install Odoo itself as a
daemon and automatically start it.
Danger
to print PDF reports, you must install wkhtmltopdf yourself:
the version of wkhtmltopdf available in debian repositories does
not support headers and footers so it can not be installed
automatically. The recommended version is 0.12.1 and is available on
the wkhtmltopdf download page, in the archive section. As there
is no official release for Debian Jessie, you can find ours on
http://nightly.odoo.com/extra/.
Configuration
The configuration file can be found at
/etc/odoo/openerp-server.conf
When the configuration file is edited, Odoo must be restarted using
service
:$ sudo service odoo restart Restarting odoo: ok
2016-04-28
How To Create a New Module on the Odoo
If we are trying to build a new module of the Odoo, we should type the command like:
python odoo.py scaffold Academy openerp/my-modules
This command generates the Odoo module scaffold named Academy to the directory openerp/my-modules. But when we try to install this new Academy module under the Setting page, we cannot find an Academy module for us to install.
In order to find this new module, we need to use the "Update Module List" option.
If we can't find the option "Update Module List" either, we need to enable the "Technical Features" checkbox in our current user's settings.
Need to do some steps:
First, select side menu Users-Users and click the Administration user. Then we can see the form view of the User/Administrator. Click the "Technical Features" checkbox and save the settings.
Then, select side menu of Modules-"Update Module List", and click the Update button.
We should restart Odoo and update the module's data (to install the template)
by going to Settings-Modules-Local Modules-Academy and clicking the Upgrade button.
Going to http://localhost:8069/academy/academy/ should show new updated results.
python odoo.py scaffold Academy openerp/my-modules
This command generates the Odoo module scaffold named Academy to the directory openerp/my-modules. But when we try to install this new Academy module under the Setting page, we cannot find an Academy module for us to install.
In order to find this new module, we need to use the "Update Module List" option.
If we can't find the option "Update Module List" either, we need to enable the "Technical Features" checkbox in our current user's settings.
Need to do some steps:
First, select side menu Users-Users and click the Administration user. Then we can see the form view of the User/Administrator. Click the "Technical Features" checkbox and save the settings.
Then, select side menu of Modules-"Update Module List", and click the Update button.
Finally, select side menu Modules-Local Modules,remove all filters and sort the module list. We will see the Academy module in the first position.
Going to http://localhost:8069/academy/academy/ will see the new module.
If we've added some templates or have modified codes of the module Academy , we will need to upgrade the module again.
Reference:
Building a Website — odoo 8.0 documentation
2016-04-23
Coding 5 Languages at once: If Statement
If we want computer do something based on different conditions, we can use the "IF" statement.
If the "If condition Then" statement finds the result is True then if will continue the next statement. Otherwise, it will find the next "ElseIf condition Then" statement to test another condition. If no condition is matched, it will find the "Else" statement to go. Or the "End If" statement, if there is no "Else" found.
Other languages use the "{...}" to define a black of statements. If the condition is True, it will perform all statements within the block.
BASIC:
' *******************************************
' Condition statement (If..ElseIf..Else..End If)
' *******************************************
Sub IfStatement()
Dim dPara1 as Double
Dim dPara2 as Double
dPara1 = 1.0
dPara2 = 2.0
' Condition statement (If..ElseIf..Else..End If)
If dPara1 > dPara2 Then
' Is Greater Than
Debug.Print " ";"dPara1 > dPara2";
Debug.Print
ElseIf dPara1 = dPara2 Then
' Equals to
Debug.Print " ";"dPara1 ==dPara2";
Debug.Print
ElseIf dPara1 < dPara2 Then
' Is Less Than
Debug.Print " ";"dPara1 < dPara2";
Debug.Print
End If
If dPara1 <> dPara2 Then
' not equal to
Debug.Print " ";"dPara1 <> dPara2";
Debug.Print
End If
' And Logic
If dPara1 > dPara2 AND dPara1 = dPara2 Then
Debug.Print " ";"dPara1 >=dPara2";
Debug.Print
' Or Logic
ElseIf dPara1 > dPara2 OR dPara1 < dPara2 Then
Debug.Print " ";"dPara1 <> dPara2";
Debug.Print
End If
End Sub
C++:
/* ******************************************* */
/* Condition statement (If..ElseIf..Else..End If) */
/* ******************************************* */
void IfStatement() {
double dPara1;
double dPara2;
dPara1 = 1.0;
dPara2 = 2.0;
/* Condition statement (If..ElseIf..Else..End If) */
if (dPara1 > dPara2) {
/* Is Greater Than */
printf(" %s" , "dPara1 > dPara2");
printf("\n" );
} else if (dPara1 ==dPara2) {
/* Equals to */
printf(" %s" , "dPara1 ==dPara2");
printf("\n" );
} else if (dPara1 < dPara2) {
/* Is Less Than */
printf(" %s" , "dPara1 < dPara2");
printf("\n" );
}
if (dPara1 != dPara2) {
/* not equal to */
printf(" %s" , "dPara1 <> dPara2");
printf("\n" );
}
/* And Logic */
if (dPara1 > dPara2 && dPara1 ==dPara2) {
printf(" %s" , "dPara1 >=dPara2");
printf("\n" );
/* Or Logic */
} else if (dPara1 > dPara2 || dPara1 < dPara2) {
printf(" %s" , "dPara1 <> dPara2");
printf("\n" );
}
}
JAVA:
// *******************************************
// Condition statement (If..ElseIf..Else..End If)
// *******************************************
public void IfStatement() {
double dPara1;
double dPara2;
dPara1 = 1.0;
dPara2 = 2.0;
// Condition statement (If..ElseIf..Else..End If)
if (dPara1 > dPara2) {
// Is Greater Than
System.out.print(" "+"dPara1 > dPara2" );
System.out.println("");
} else if (dPara1 ==dPara2) {
// Equals to
System.out.print(" "+"dPara1 ==dPara2" );
System.out.println("");
} else if (dPara1 < dPara2) {
// Is Less Than
System.out.print(" "+"dPara1 < dPara2" );
System.out.println("");
}
if (dPara1 != dPara2) {
// not equal to
System.out.print(" "+"dPara1 <> dPara2" );
System.out.println("");
}
// And Logic
if (dPara1 > dPara2 && dPara1 ==dPara2) {
System.out.print(" "+"dPara1 >=dPara2" );
System.out.println("");
// Or Logic
} else if (dPara1 > dPara2 || dPara1 < dPara2) {
System.out.print(" "+"dPara1 <> dPara2" );
System.out.println("");
}
}
C#:
/* ******************************************* */
/* Condition statement (If..ElseIf..Else..End If) */
/* ******************************************* */
public void IfStatement() {
double dPara1;
double dPara2;
dPara1 = 1.0;
dPara2 = 2.0;
/* Condition statement (If..ElseIf..Else..End If) */
if (dPara1 > dPara2) {
/* Is Greater Than */
Console.Write(" "+"dPara1 > dPara2");
Console.WriteLine("");
} else if (dPara1 ==dPara2) {
/* Equals to */
Console.Write(" "+"dPara1 ==dPara2");
Console.WriteLine("");
} else if (dPara1 < dPara2) {
/* Is Less Than */
Console.Write(" "+"dPara1 < dPara2");
Console.WriteLine("");
}
if (dPara1 != dPara2) {
/* not equal to */
Console.Write(" "+"dPara1 <> dPara2");
Console.WriteLine("");
}
/* And Logic */
if (dPara1 > dPara2 && dPara1 ==dPara2) {
Console.Write(" "+"dPara1 >=dPara2");
Console.WriteLine("");
/* Or Logic */
} else if (dPara1 > dPara2 || dPara1 < dPara2) {
Console.Write(" "+"dPara1 <> dPara2");
Console.WriteLine("");
}
}
PHP:
/* ******************************************* */
/* Condition statement (If..ElseIf..Else..End If) */
/* ******************************************* */
function IfStatement() {
$dPara1 = 1.0;
$dPara2 = 2.0;
/* Condition statement (If..ElseIf..Else..End If) */
if ($dPara1 > $dPara2) {
/* Is Greater Than */
echo " "."dPara1 > dPara2";
echo "";
} elseif ($dPara1 ==$dPara2) {
/* Equals to */
echo " "."dPara1 ==dPara2";
echo "";
} elseif ($dPara1 < $dPara2) {
/* Is Less Than */
echo " "."dPara1 < dPara2";
echo "";
}
if ($dPara1 != $dPara2) {
/* not equal to */
echo " "."dPara1 <> dPara2";
echo "";
}
/* And Logic */
if ($dPara1 > $dPara2 && $dPara1 ==$dPara2) {
echo " "."dPara1 >=dPara2";
echo "";
/* Or Logic */
} elseif ($dPara1 > $dPara2 || $dPara1 < $dPara2) {
echo " "."dPara1 <> dPara2";
echo "";
}
}
If the "If condition Then" statement finds the result is True then if will continue the next statement. Otherwise, it will find the next "ElseIf condition Then" statement to test another condition. If no condition is matched, it will find the "Else" statement to go. Or the "End If" statement, if there is no "Else" found.
Other languages use the "{...}" to define a black of statements. If the condition is True, it will perform all statements within the block.
BASIC:
' *******************************************
' Condition statement (If..ElseIf..Else..End If)
' *******************************************
Sub IfStatement()
Dim dPara1 as Double
Dim dPara2 as Double
dPara1 = 1.0
dPara2 = 2.0
' Condition statement (If..ElseIf..Else..End If)
If dPara1 > dPara2 Then
' Is Greater Than
Debug.Print " ";"dPara1 > dPara2";
Debug.Print
ElseIf dPara1 = dPara2 Then
' Equals to
Debug.Print " ";"dPara1 ==dPara2";
Debug.Print
ElseIf dPara1 < dPara2 Then
' Is Less Than
Debug.Print " ";"dPara1 < dPara2";
Debug.Print
End If
If dPara1 <> dPara2 Then
' not equal to
Debug.Print " ";"dPara1 <> dPara2";
Debug.Print
End If
' And Logic
If dPara1 > dPara2 AND dPara1 = dPara2 Then
Debug.Print " ";"dPara1 >=dPara2";
Debug.Print
' Or Logic
ElseIf dPara1 > dPara2 OR dPara1 < dPara2 Then
Debug.Print " ";"dPara1 <> dPara2";
Debug.Print
End If
End Sub
C++:
/* ******************************************* */
/* Condition statement (If..ElseIf..Else..End If) */
/* ******************************************* */
void IfStatement() {
double dPara1;
double dPara2;
dPara1 = 1.0;
dPara2 = 2.0;
/* Condition statement (If..ElseIf..Else..End If) */
if (dPara1 > dPara2) {
/* Is Greater Than */
printf(" %s" , "dPara1 > dPara2");
printf("\n" );
} else if (dPara1 ==dPara2) {
/* Equals to */
printf(" %s" , "dPara1 ==dPara2");
printf("\n" );
} else if (dPara1 < dPara2) {
/* Is Less Than */
printf(" %s" , "dPara1 < dPara2");
printf("\n" );
}
if (dPara1 != dPara2) {
/* not equal to */
printf(" %s" , "dPara1 <> dPara2");
printf("\n" );
}
/* And Logic */
if (dPara1 > dPara2 && dPara1 ==dPara2) {
printf(" %s" , "dPara1 >=dPara2");
printf("\n" );
/* Or Logic */
} else if (dPara1 > dPara2 || dPara1 < dPara2) {
printf(" %s" , "dPara1 <> dPara2");
printf("\n" );
}
}
JAVA:
// *******************************************
// Condition statement (If..ElseIf..Else..End If)
// *******************************************
public void IfStatement() {
double dPara1;
double dPara2;
dPara1 = 1.0;
dPara2 = 2.0;
// Condition statement (If..ElseIf..Else..End If)
if (dPara1 > dPara2) {
// Is Greater Than
System.out.print(" "+"dPara1 > dPara2" );
System.out.println("");
} else if (dPara1 ==dPara2) {
// Equals to
System.out.print(" "+"dPara1 ==dPara2" );
System.out.println("");
} else if (dPara1 < dPara2) {
// Is Less Than
System.out.print(" "+"dPara1 < dPara2" );
System.out.println("");
}
if (dPara1 != dPara2) {
// not equal to
System.out.print(" "+"dPara1 <> dPara2" );
System.out.println("");
}
// And Logic
if (dPara1 > dPara2 && dPara1 ==dPara2) {
System.out.print(" "+"dPara1 >=dPara2" );
System.out.println("");
// Or Logic
} else if (dPara1 > dPara2 || dPara1 < dPara2) {
System.out.print(" "+"dPara1 <> dPara2" );
System.out.println("");
}
}
C#:
/* ******************************************* */
/* Condition statement (If..ElseIf..Else..End If) */
/* ******************************************* */
public void IfStatement() {
double dPara1;
double dPara2;
dPara1 = 1.0;
dPara2 = 2.0;
/* Condition statement (If..ElseIf..Else..End If) */
if (dPara1 > dPara2) {
/* Is Greater Than */
Console.Write(" "+"dPara1 > dPara2");
Console.WriteLine("");
} else if (dPara1 ==dPara2) {
/* Equals to */
Console.Write(" "+"dPara1 ==dPara2");
Console.WriteLine("");
} else if (dPara1 < dPara2) {
/* Is Less Than */
Console.Write(" "+"dPara1 < dPara2");
Console.WriteLine("");
}
if (dPara1 != dPara2) {
/* not equal to */
Console.Write(" "+"dPara1 <> dPara2");
Console.WriteLine("");
}
/* And Logic */
if (dPara1 > dPara2 && dPara1 ==dPara2) {
Console.Write(" "+"dPara1 >=dPara2");
Console.WriteLine("");
/* Or Logic */
} else if (dPara1 > dPara2 || dPara1 < dPara2) {
Console.Write(" "+"dPara1 <> dPara2");
Console.WriteLine("");
}
}
PHP:
/* ******************************************* */
/* Condition statement (If..ElseIf..Else..End If) */
/* ******************************************* */
function IfStatement() {
$dPara1 = 1.0;
$dPara2 = 2.0;
/* Condition statement (If..ElseIf..Else..End If) */
if ($dPara1 > $dPara2) {
/* Is Greater Than */
echo " "."dPara1 > dPara2";
echo "";
} elseif ($dPara1 ==$dPara2) {
/* Equals to */
echo " "."dPara1 ==dPara2";
echo "";
} elseif ($dPara1 < $dPara2) {
/* Is Less Than */
echo " "."dPara1 < dPara2";
echo "";
}
if ($dPara1 != $dPara2) {
/* not equal to */
echo " "."dPara1 <> dPara2";
echo "";
}
/* And Logic */
if ($dPara1 > $dPara2 && $dPara1 ==$dPara2) {
echo " "."dPara1 >=dPara2";
echo "";
/* Or Logic */
} elseif ($dPara1 > $dPara2 || $dPara1 < $dPara2) {
echo " "."dPara1 <> dPara2";
echo "";
}
}
2016-04-19
Learn Coding Five Languages at once: For Statement
If we want to perform an instruction many times, we can copy this instruction many times or use a "For...Next" block. This "For" statement assigns an initial value to a variable and change it up to the end value stepping with +1 or -1.
For example, "For i=1 to 5 " statement assign value 1 to the variable i and loop it up to the end value 5 with stepping value 1 each time. When program meets the "Next" statement, it will jump back to the "For" statement. But if the variable exceeds the end value, the program will jump to the statement next to "Next".
Here we show the example of looping five times and print the value of the variable i in five different programming languages:
BASIC:
' *******************************************
' for loop statement (For..Next)
' *******************************************
Sub ForLoop()
' Declare local variable
Dim i as Integer
Debug.Print " ";"**** For statement ***";
Debug.Print
For i=1 to 5
Debug.Print " ";"i=";
Debug.Print " ";i;
Debug.Print
Next
End Sub
C++:
/* ******************************************* */
/* for loop statement (For..Next) */
/* ******************************************* */
void ForLoop() {
/* Declare local variable */
int i;
printf(" %s" , "**** For statement ***");
printf("\n" );
for (i=1; i<= 5; i++) {
printf(" %s" , "i=");
printf(" %d" , i);
printf("\n" );
}
}
JAVA:
// *******************************************
// for loop statement (For..Next)
// *******************************************
public void ForLoop() {
// Declare local variable
int i;
System.out.print(" "+"**** For statement ***" );
System.out.println("");
for (i=1; i<= 5; i++) {
System.out.print(" "+"i=" );
System.out.print(" "+i );
System.out.println("");
}
}
C#:
/* ******************************************* */
/* for loop statement (For..Next) */
/* ******************************************* */
public void ForLoop() {
/* Declare local variable */
int i;
Console.Write(" "+"**** For statement ***");
Console.WriteLine("");
for (i=1; i<= 5; i++) {
Console.Write(" "+"i=");
Console.Write(" "+i);
Console.WriteLine("");
}
}
PHP:
/* ******************************************* */
/* for loop statement (For..Next) */
/* ******************************************* */
function ForLoop() {
/* Declare local variable */
echo " "."**** For statement ***";
echo "";
for ($i=1; $i<= 5; $i++) {
echo " "."i=";
echo " ".$i;
echo "";
}
}
For example, "For i=1 to 5 " statement assign value 1 to the variable i and loop it up to the end value 5 with stepping value 1 each time. When program meets the "Next" statement, it will jump back to the "For" statement. But if the variable exceeds the end value, the program will jump to the statement next to "Next".
Here we show the example of looping five times and print the value of the variable i in five different programming languages:
BASIC:
' *******************************************
' for loop statement (For..Next)
' *******************************************
Sub ForLoop()
' Declare local variable
Dim i as Integer
Debug.Print " ";"**** For statement ***";
Debug.Print
For i=1 to 5
Debug.Print " ";"i=";
Debug.Print " ";i;
Debug.Print
Next
End Sub
C++:
/* ******************************************* */
/* for loop statement (For..Next) */
/* ******************************************* */
void ForLoop() {
/* Declare local variable */
int i;
printf(" %s" , "**** For statement ***");
printf("\n" );
for (i=1; i<= 5; i++) {
printf(" %s" , "i=");
printf(" %d" , i);
printf("\n" );
}
}
JAVA:
// *******************************************
// for loop statement (For..Next)
// *******************************************
public void ForLoop() {
// Declare local variable
int i;
System.out.print(" "+"**** For statement ***" );
System.out.println("");
for (i=1; i<= 5; i++) {
System.out.print(" "+"i=" );
System.out.print(" "+i );
System.out.println("");
}
}
C#:
/* ******************************************* */
/* for loop statement (For..Next) */
/* ******************************************* */
public void ForLoop() {
/* Declare local variable */
int i;
Console.Write(" "+"**** For statement ***");
Console.WriteLine("");
for (i=1; i<= 5; i++) {
Console.Write(" "+"i=");
Console.Write(" "+i);
Console.WriteLine("");
}
}
PHP:
/* ******************************************* */
/* for loop statement (For..Next) */
/* ******************************************* */
function ForLoop() {
/* Declare local variable */
echo " "."**** For statement ***";
echo "";
for ($i=1; $i<= 5; $i++) {
echo " "."i=";
echo " ".$i;
echo "";
}
}
2016-04-16
Learn Computer Languages from BASIC,C++, JAVA, C# to PHP at once
Computer programming languages from BASIC,C++, JAVA, C# to PHP seem different, but actually they can do the same task. We can study them all together under some basic topics.
The first lesson of coding to understand assignment like a=a+1. This is not an equation. It simply means compute a+1 and put the result back to a.
Here we list some statements of assignment in five different programming languages: BASIC,C++, JAVA, C# and PHP.
' Value Assignment
iA = 1*2+3/4-5
iB = 1*(2+3)/4-5
iC =iA Mod 2
' Print iA,iB,iC
' String Assignment
sS="abc"
' String Catenation
sS=sS+"<>"
sS=sS+"def"
' Print sS
BASIC:
' *******************************************
' Assignment Statement BASIC
' *******************************************
Sub AssignmentStatement()
Dim iA as Integer
Dim iB as Integer
Dim iC as Integer
Dim sS as String
' Value Assignment
iA = 1*2+3/4-5
iB = 1*(2+3)/4-5
iC =iA Mod 2
Debug.Print " ";iA;
Debug.Print " ";iB;
Debug.Print " ";iC;
Debug.Print
' String Assignment
sS="abc"
' String Catenation
sS=sS+"<>"
sS=sS+"def"
Debug.Print " ";"sS=";
Debug.Print " ";sS;
Debug.Print
End Sub
C++:
/* ******************************************* */
/* Assignment Statement C++ */
/* ******************************************* */
void AssignmentStatement() {
int iA;
int iB;
int iC;
char* sS;
/* Value Assignment */
iA = 1*2+3/4-5;
iB = 1*(2+3)/4-5;
iC =iA % 2;
printf(" %d" , iA);
printf(" %d" , iB);
printf(" %d" , iC);
printf("\n" );
/* char* Assignment */
vstrcpy((char**)&sS, "abc");
/* char* Catenation */
vstrcat((char**)&sS, "<>");
vstrcat((char**)&sS, "def");
printf(" %s" , "sS=");
printf(" %s" , sS);
printf("\n" );
vfree((char*)sS);
}
JAVA:
// *******************************************
// Assignment Statement JAVA
// *******************************************
public void AssignmentStatement() {
int iA;
int iB;
int iC;
String sS = null;
// Value Assignment
iA = 1*2+3/4-5;
iB = 1*(2+3)/4-5;
iC =iA % 2;
System.out.print(" "+iA );
System.out.print(" "+iB );
System.out.print(" "+iC );
System.out.println("");
// String Assignment
sS="abc";
// String Catenation
sS=sS+"<>";
sS=sS+"def";
System.out.print(" "+"sS=" );
System.out.print(" "+sS );
System.out.println("");
}
C#:
/* ******************************************* */
/* Assignment Statement C# */
/* ******************************************* */
public void AssignmentStatement() {
int iA;
int iB;
int iC;
String sS = null;
/* Value Assignment */
iA = 1*2+3/4-5;
iB = 1*(2+3)/4-5;
iC =iA % 2;
Console.Write(" "+iA);
Console.Write(" "+iB);
Console.Write(" "+iC);
Console.WriteLine("");
/* String Assignment */
sS="abc";
/* String Catenation */
sS=sS+"<>";
sS=sS+"def";
Console.Write(" "+"sS=");
Console.Write(" "+sS);
Console.WriteLine("");
}
PHP:
/* ******************************************* */
/* Assignment Statement PHP */
/* ******************************************* */
function AssignmentStatement() {
/* Value Assignment */
$iA = 1*2+3/4-5;
$iB = 1*(2+3)/4-5;
$iC =$iA % 2;
echo " ".$iA;
echo " ".$iB;
echo " ".$iC;
echo "";
/* String Assignment */
$sS="abc";
/* String Catenation */
$sS.="<>";
$sS.="def";
echo " "."sS=";
echo " ".$sS;
echo "";
}
The first lesson of coding to understand assignment like a=a+1. This is not an equation. It simply means compute a+1 and put the result back to a.
Here we list some statements of assignment in five different programming languages: BASIC,C++, JAVA, C# and PHP.
' Value Assignment
iA = 1*2+3/4-5
iB = 1*(2+3)/4-5
iC =iA Mod 2
' Print iA,iB,iC
' String Assignment
sS="abc"
' String Catenation
sS=sS+"<>"
sS=sS+"def"
' Print sS
BASIC:
' *******************************************
' Assignment Statement BASIC
' *******************************************
Sub AssignmentStatement()
Dim iA as Integer
Dim iB as Integer
Dim iC as Integer
Dim sS as String
' Value Assignment
iA = 1*2+3/4-5
iB = 1*(2+3)/4-5
iC =iA Mod 2
Debug.Print " ";iA;
Debug.Print " ";iB;
Debug.Print " ";iC;
Debug.Print
' String Assignment
sS="abc"
' String Catenation
sS=sS+"<>"
sS=sS+"def"
Debug.Print " ";"sS=";
Debug.Print " ";sS;
Debug.Print
End Sub
C++:
/* ******************************************* */
/* Assignment Statement C++ */
/* ******************************************* */
void AssignmentStatement() {
int iA;
int iB;
int iC;
char* sS;
/* Value Assignment */
iA = 1*2+3/4-5;
iB = 1*(2+3)/4-5;
iC =iA % 2;
printf(" %d" , iA);
printf(" %d" , iB);
printf(" %d" , iC);
printf("\n" );
/* char* Assignment */
vstrcpy((char**)&sS, "abc");
/* char* Catenation */
vstrcat((char**)&sS, "<>");
vstrcat((char**)&sS, "def");
printf(" %s" , "sS=");
printf(" %s" , sS);
printf("\n" );
vfree((char*)sS);
}
JAVA:
// *******************************************
// Assignment Statement JAVA
// *******************************************
public void AssignmentStatement() {
int iA;
int iB;
int iC;
String sS = null;
// Value Assignment
iA = 1*2+3/4-5;
iB = 1*(2+3)/4-5;
iC =iA % 2;
System.out.print(" "+iA );
System.out.print(" "+iB );
System.out.print(" "+iC );
System.out.println("");
// String Assignment
sS="abc";
// String Catenation
sS=sS+"<>";
sS=sS+"def";
System.out.print(" "+"sS=" );
System.out.print(" "+sS );
System.out.println("");
}
C#:
/* ******************************************* */
/* Assignment Statement C# */
/* ******************************************* */
public void AssignmentStatement() {
int iA;
int iB;
int iC;
String sS = null;
/* Value Assignment */
iA = 1*2+3/4-5;
iB = 1*(2+3)/4-5;
iC =iA % 2;
Console.Write(" "+iA);
Console.Write(" "+iB);
Console.Write(" "+iC);
Console.WriteLine("");
/* String Assignment */
sS="abc";
/* String Catenation */
sS=sS+"<>";
sS=sS+"def";
Console.Write(" "+"sS=");
Console.Write(" "+sS);
Console.WriteLine("");
}
PHP:
/* ******************************************* */
/* Assignment Statement PHP */
/* ******************************************* */
function AssignmentStatement() {
/* Value Assignment */
$iA = 1*2+3/4-5;
$iB = 1*(2+3)/4-5;
$iC =$iA % 2;
echo " ".$iA;
echo " ".$iB;
echo " ".$iC;
echo "";
/* String Assignment */
$sS="abc";
/* String Catenation */
$sS.="<>";
$sS.="def";
echo " "."sS=";
echo " ".$sS;
echo "";
}
訂閱:
文章 (Atom)