Wednesday, October 12, 2011

Function AccessShowReport

The function below can be used to preview a report created in MS Access.

'Purpose : Preview an Access Report from VB
'Inputs : sAccessDBPath The path and filename of the access database containing the report to show
' sReportName The name of the report to show
'Outputs : Returns an empty string on success, else returns an error message.


Function AccessShowReport(sAccessDBPath As String, sReportName As String) As String
Dim oAccess As Object 'Access.Application

On Error GoTo ErrFailed
AccessShowReport = ""
'Create Access
Set oAccess = CreateObject("Access.Application")
'Open Database
oAccess.OpenCurrentDatabase sAccessDBPath
'Open report
oAccess.DoCmd.OpenReport sReportName, 0 'acViewNormal
'Show Access Report
oAccess.Visible = True
oAccess.CloseCurrentDatabase
Set oAccess = Nothing
Exit Function

ErrFailed:
Debug.Print Err.Description
Debug.Assert False
AccessShowReport = Err.Description
If oAccess Is Nothing = False Then
oAccess.CloseCurrentDatabase
Set oAccess = Nothing
End If
End Function
READ MORE - Function AccessShowReport

Monday, August 29, 2011

Connection Type

Microsoft Excel is a component of MS Office application, which is useful to create spreadsheet. This Office utility is fruitful to create and maintain huge lists easily and effortlessly. It is used for storing contacts, doing statistical analysis, performing financial calculations and much more. Excel is extensively used for storing hundreds and thousands of contacts.

MS Excel application is a boon for people in the marketing field, executives etc, as they prefer to use MS Excel for creating and preserving enormous contacts databases of various clients and prospective customers, along with their names, address, contact numbers, email identity etc, which can be stored in Excel XLS files. With the help of Excel spreadsheets, transactions can be easily conducted.


If you selected "Excel" for the Connection Type.

Optionally, click Create Database to create a new and empty spreadsheet file.

Otherwise:

Click to navigate to and select a .XLS file, then click Open.

If necessary, enter your login name in the User field.

If necessary, enter your password.

Enter any additional parameters required by your spreadsheet.

Click Test Connection.

If the connection was successful, click OK to conclude.

DAverage
In Excel, the DAverage function averages all numbers in a column in a list or database, based on a given criteria. The syntax for the DAverage function is: DAverage( range, field, criteria ) range is the range of cells that you want to apply the criteria against. field is the column to average the values. You can either specify the numerical position of the column in the list or the column label in double quotation marks. criteria is the range of cells that contains your criteria.

DCount
In Excel, the DCount function returns the number of cells in a column or database that contains numbers and meets a given criteria. The syntax for the DCount function is: DCount( range, field, criteria ) range is the range of cells that you want to apply the criteria against. field is the column to count the values. You can either specify the numerical position of the column in the list or the column label in double quotation marks. criteria is the range of cells that contains your criteria.

DCountA
In Excel, the DCountA function returns the number of cells in a column or database that contains nonblank values and meets a given criteria. The syntax for the DCountA function is: DCountA( range, field, criteria ) range is the range of cells that you want to apply the criteria against. field is the column to count the values. You can either specify the numerical position of the column in the list or the column label in double quotation marks. criteria is the range of cells that contains your criteria.

DGet
In Excel, the DGet function retrieves from a database a single record that matches a given criteria. The syntax for the DGet function is: DGet( database, field, criteria ) database is the range of cells that you want to apply the criteria against. field is the column to retrieve. You can either specify the numerical position of the column in the list or the column label in double quotation marks. criteria is the range of cells that contains your criteria. Note: If no record matches the criteria, the DGet function returns #VALUE! error. If more than one record matches the criteria, the DGet function returns #NUM! error.

DMax
In Excel, the DMax function returns the largest number in a column in a list or database, based on a given criteria. The syntax for the DMax function is: DMax( database, field, criteria ) database is the range of cells that you want to apply the criteria against. field is the column to find the largest number in. You can either specify the numerical position of the column in the list or the column label in double quotation marks. criteria is the range of cells that contains your criteria.

DProduct
In Excel, the DProduct function returns the product of the numbers in a column in a list or database, based on a given criteria. The syntax for the DProduct function is: DProduct( database, field, criteria ) database is the range of cells that you want to apply the criteria against. field is the column to multiply the numbers in. You can either specify the numerical position of the column in the list or the column label in double quotation marks. criteria is the range of cells that contains your criteria.

DVarP
In Excel, the DVarP function returns the variance of a population based on the entire population of numbers in a column in a list or database, based on a given criteria. The syntax for the DVarP function is: DVarP( database, field, criteria ) database is the range of cells that you want to apply the criteria against. field is the column to be used by the DVarP function. You can either specify the numerical position of the column in the list or the column label in double quotation marks. criteria is the range of cells that contains your criteria.

DMin
In Excel, the DMin function returns the smallest number in a column in a list or database, based on a given criteria. The syntax for the DMin function is: DMin( database, field, criteria ) database is the range of cells that you want to apply the criteria against. field is the column to find the smallest number in. You can either specify the numerical position of the column in the list or the column label in double quotation marks. criteria is the range of cells that contains your criteria.

DStDevP
In Excel, the DStDevP function returns the standard deviation of a population based on the entire population of numbers in a column in a list or database, based on a given criteria. The syntax for the DStDevP function is: DStDevP( database, field, criteria ) database is the range of cells that you want to apply the criteria against. field is the column to be used by the DStDevP function. You can either specify the numerical position of the column in the list or the column label in double quotation marks. criteria is the range of cells that contains your criteria.

DStDev
In Excel, the DStDev function returns the standard deviation of a population based on a sample of numbers in a column in a list or database, based on a given criteria. The syntax for the DStDev function is: DStDev( database, field, criteria ) database is the range of cells that you want to apply the criteria against. field is the column to be used by the DStDev function. You can either specify the numerical position of the column in the list or the column label in double quotation marks. criteria is the range of cells that contains your criteria.

DSum
In Excel, the DSum function sums the numbers in a column or database that meets a given criteria. The syntax for the DSum function is: DSum( range, field, criteria ) range is the range of cells that you want to apply the criteria against. field is the column to sum the values. You can either specify the numerical position of the column in the list or the column label in double quotation marks. criteria is the range of cells that contains your criteria.

DVar
In Excel, the DVar function returns the variance of a population based on a sample of numbers in a column in a list or database, based on a given criteria. The syntax for the DVar function is: DVar( database, field, criteria ) database is the range of cells that you want to apply the criteria against. field is the column to be used by the DVar function. You can either specify the numerical position of the column in the list or the column label in double quotation marks. criteria is the range of cells that contains your criteria.
READ MORE - Connection Type

SQL ODBC connection

SQL ODBC connection strings
Standard Security:< br> "Driver={SQLServer};Server=Your_Server_Name;Database=Your_Database_Name;Uid=Your_Username;Pwd=Your_Password;"

Trusted connection:< br> "Driver={SQLServer};Server=Your_Server_Name;Database=Your_Database_Name;Trusted_Connection=yes;"
SQL OLE DB connection strings
Standard Security:
"Provider=SQLOLEDB;Data Source=Your_Server_Name;Initial Catalog= Your_Database_Name;UserId=Your_Username;Password=Your_Password;"

Trusted connection:
"Provider=SQLOLEDB;Data Source=Your_Server_Name;Initial Catalog=Your_Database_Name;Integrated Security=SSPI;"
SQL OleDbConnection .NET strings
Standard Security:
"Provider=SQLOLEDB;Data Source=Your_Server_Name;Initial Catalog= Your_Database_Name;UserId=Your_Username;Password=Your_Password;"

Trusted connection:
"Provider=SQLOLEDB;Data Source=Your_Server_Name;Initial Catalog=Your_Database_Name;Integrated Security=SSPI;"
READ MORE - SQL ODBC connection

Sunday, August 28, 2011

SQL Functions

SQL Functions

Keyword Description
Create Function Ext_Orders
(parmWhere CHAR(5)) CREATE FUNCTION names the UDTF and registers it with SQL. This function is called Ext_Orders (external orders). This name will be referenced by SQL statements using the function.

You may define an optional comma-delimited parameter list. For table functions, parameter lists are usually passed to a) limit the number of rows returned or b) assist in the calculation of column values.

Returns Table This keyword defines the column list (column names and attributes) that the table function will return.
External Name 'ExtDB.orders' This option is applicable only to functions written in a language other than SQL. The external name is a program name that will be called when the function is invoked. For Java programs, the external name is specified as Class.method. For non-Java programs, the name is specified as library/program.
Language Java This keyword specifies that the function is written in Java. Other options include SQL, COBOL, CL, RPGLE, C, etc.
Parameter Style DB2General The parameter style keyword determines how the database manager will pass parameters to an external program. Research these options thoroughly before writing programs.

For Java, the DB2General style is a DB2-specific option that specifies that the table function will extend the com.ibm.db2.app.UDF class.

Another parameter style called "Java" is used when writing routines conforming to the SQLJ Part 1: SQL Routines standard. However, this standard only supports scalar (not table) functions, so DB2General must be used.
Fenced The fenced option specifies that multiple invocations of the function (i.e., the function is used more than once in a single statement) will run in separate threads so as to avoid potential conflict with each other.
No SQL This parameter, which is mainly for optimization, specifies that there are no DB2 SQL statements to be run by the function.
Disallow Parallel This option is required for UDTFs that cannot be multi-threaded.
Scratchpad This option specifies that a static storage area will be allocated to the function. This storage area will be preserved between calls to the function. If a number isn't specified, 100 bytes will be allocated.

This keyword is special for Java UDTFs because if it is not specified, Java will instantiate a new instance of the class each time the function is invoked.
Final Call This option specifies that the FIRST and FINAL call types will be invoked.
Returns Null on Null Input If one or more input parameters passed to the table function are NULL, the function will return zero rows.
READ MORE - SQL Functions

C, C++ and Java Assignment Operators


C, C++ and Java Assignment Operators
= -- simple assignment
+= -- add rhs, then assign to lhs
-= -- subtract rhs, then assign to lhs
*= -- multiply by rhs, then assign to lhs
/= -- divide lhs by rhs, then assign to lhs
&= -- bitwise and, then assign to lhs
|= -- bitwise or, then assign to lhs
^= -- bitwise exclusive or, then assign to lhs
%= -- bitwise remainder, then assign to lhs
<<= -- left shift lhs by rhs, then assign to lhs >>= -- signed right shift, then assign to lhs
>>>= -- unsigned right shift, then assign to lhs

Infix Operators
|| -- logical or
&& -- logical and
| -- integer bitwise or
^ -- integer bitwise exclusive or
& -- integer bitwise and
== -- numerical equality
!= -- numerical inequality
< -- less than > -- greater than
<= -- less than or equal to >= -- greater than or equal to
<< -- left shift >> -- signed right shift
>>> -- unsignd right shift
+ -- addition or string concatenation
- -- subtraction
* -- multiplication
/ -- division
% -- remainder

READ MORE - C, C++ and Java Assignment Operators

import java.sql


import java.sql.*;

public class DataTransfer {

private static String[] tableNames = new String[]{"SOME_TABLE_NAME"};
private static final int FETCH_SIZE = 100;
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Connection sourceConnection = ...;
Connection targetConnection = ...);

// records transfered counter
int c = 0;

for (String tableName : tableNames) {
final PreparedStatement ps = sourceConnection.prepareStatement("SELECT * FROM " + tableName);
ps.setFetchSize(FETCH_SIZE);
final ResultSet rs = ps.executeQuery();
final ResultSetMetaData metaData = rs.getMetaData();
final int columnCount = metaData.getColumnCount();
String insertSQL = "INSERT INTO " + tableName + " ";

while (rs.next()) {
StringBuffer columns = new StringBuffer("(");
StringBuffer params = new StringBuffer("(");

for (int i = 0; i < columnCount; i++) { columns.append(metaData.getColumnName(i+1)); params.append("?"); if ((i+1) != columnCount) { columns.append(","); params.append(","); } } columns.append(")"); params.append(")"); final String sql = insertSQL + columns.toString() + " VALUES " + params.toString(); c++; if (c > 0 && c % FETCH_SIZE == 0) {
System.out.println("Transfered " + c + " records.");
}

final PreparedStatement insertStatement = targetConnection.prepareStatement(sql);
for (int i = 0; i < columnCount; i++) {
insertStatement.setObject(i+1, rs.getObject(i+1));
}
insertStatement.execute();
targetConnection.commit();

insertStatement.close();
}
rs.close();
ps.close();
}
sourceConnection.close();
targetConnection.close();
System.out.println("Total transfered " + c + " records.");
}
}
READ MORE - import java.sql

Tuesday, August 23, 2011

Simple Database

A Simple Database Backup:

You can use mysqldump to create a simple backup of your database using the following syntax.

mysqldump -u [username] -p [password] [databasename] > [backupfile.sql]
[username] - this is your database username
[password] - this is the password for your database
[databasename] - the name of your database
[backupfile.sql] - the file to which the backup should be written.


The resultant dump file will contain all the SQL statements needed to create the table and populate the table in a new database server. To backup your database 'Customers' with the username 'sadmin' and password 'pass21' to a file custback.sql, you would issue the command:

mysqldump -u sadmin -p pass21 Customers > custback.sql

You can also ask mysqldump to add a drop table command before every create command by using the option --add-drop-table. This option is useful if you would like to create a backup file which can rewrite an existing database without having to delete the older database manually first.

mysqldump --add-drop-table -u sadmin -p pass21 Customers > custback.sql

Backing up only specified tables

If you'd like restrict the backup to only certain tables of your database, you can also specify the tables you want to backup. Let's say that you want to backup only customer_master & customer_details from the Customers database, you do that by issuing

mysqldump --add-drop-table -u sadmin -p pass21 Customers customer_master customer_details> custback.sql

So the syntax for the command to issue is:

mysqldump -u [username] -p [password] [databasename] [table1 table2 ....]
[tables] - This is a list of tables to backup. Each table is separated by a space.
READ MORE - Simple Database

Central Management Service

The CMS store is used by the Central Management Service to maintain a current Lync Server 2010 Topology for the entire Lync deployment (Topology, Policies, Voice Routes, etc…). Here is what you need to know about the CMS:
The database used for this purpose is called “Xds”; it maintains the Lync configuration as published by the Topology Builder.
There is only one master copy of CMS database which is automatically installed on the first instance of a Standard or Enterprise Edition Lync pool.
Every subsequent Lync server in the topology gets a read-only copy of it. A topology change on the master is replicated to each read-only copy on each Lync server. This is a key element to Lync Server’s survivability feature set – if the network connection between a Lync Edge server goes down for example, the Edge server still knows about the topology and can keep functioning.

Changes are replicated to all Lync server roles except the Lync Edge using the Windows file copy SMB protocol. Changes are replicated to the Edge role via HTTPS. The Windows service “Lync server replica replicator agent” is responsible for receiving the snapshot and uploading the local copies of the databases. It then sends a status update to the Master Replicator (also a windows service) running on the CMS.

In CCM, on the Dependancy tab for CMS I have added :

OracleServiceBW
OracleMTSRecoveryService
OracleOraHome92TNSListener
OracleOraHome92Agent
READ MORE - Central Management Service

Tuesday, August 16, 2011

Visual Basic

Visual Basic is an event-driven language. So, when you talk about events, we're talking about things that happen in the program which cause little events to occur (similar idea to IRQ stuff you learned hopefully in 455). An example of this could be clicking a button causing a button_click event to be generated. You write code to react to these events and guide a user through your program.

You design your form completely visually, using a set of widget tools and drawing on the form directly just like you would in a paint program or something like this. This stuff is so easy, you'll love it ... or maybe not ... but it's quick and relatively pain free.

Okay, these examples were developed by James Tam, and I've just reproduced them here. His website has all his full details on what exactly these things entail, but I'll get into them a little bit myself. If it seems that there's something missing here, be sure to check out over there for more info.

Okay, the first thing you need to do with visual basic is basically just start it up. No problem. Go:

Start --- Programs --- Microsoft Visual Basic --- You get the picture .... :)

When you load it up for the first time, Microsoft Office might churn away for a couple of minutes. This is an issue with Office 2000 and you don't need to worry about it too too much. It will only happen the once. In any case, when VB is finally loaded up, and you pick Standard Exe from the new project dialog, here's what you'll be confronted with:
READ MORE - Visual Basic

Tuesday, August 9, 2011

SQL (Structured Query Language)


SQL (Structured Query Language) is a computer language aimed to store, manipulate, and query data stored in relational databases. The first incarnation of SQL appeared in 1974, when a group in IBM developed the first prototype of a relational database. The first commercial relational database was released by Relational Software (later becoming Oracle).

Standards for SQL exist. However, the SQL that can be used on each one of the major RDBMS today is in different flavors. This is due to two reasons: 1) the SQL command standard is fairly complex, and it is not practical to implement the entire standard, and 2) each database vendor needs a way to differentiate its product from others. In this tutorial, such differences are noted where appropriate.
READ MORE - SQL (Structured Query Language)

Friday, July 29, 2011

Java database applications


This tutorial only shows briefly the steps the construction of Java database applications that connect to the MySQL server. To be able to connect to MySQL from Java is necessary JDBC driver for MySQL. Please download at the website mysql.com, obtained the file mysql-connector-java-5.1.8.tar (latest date). Then extract the file. One result of extraction is the file mysql-connector-java-5.1.8-bin.jar and this is the MySQL JDBC driver in question. Copy this file to the directory C: Program FilesJavajre6libext or to another folder according to the location of the JRE installation.

As the use of other languages, an important step in making a database application is to create a database and then access it from the language used.

How to create a database in MySQL? The easiest way is to use web tools such as PHPMyAdmin. If no, we can directly into the console and run the mysql client program. The steps below are easy to follow:

1. Go to the console (Command Prompt).

2. Change to the directory where the mysql program is located. If using XAMPP then mysql are in C: xamppmysqlbin (adjust to conditions in your computer).

3. Run the mysql command, for example: mysql-u root

4. At the mysql> prompt, type create database feedback; (end with Enter). This will generate a new database called feedback.

5. Give commands use the feedback; for feedback database becomes the active database

6. Add new users into the system, for example sqluser. Give permission to users to access the feedback database earlier.



Sqluser CREATE USER IDENTIFIED BY 'sqluserpw';

grant usage on *.* to sqluser @ localhost IDENTIFIED BY 'sqluserpw';

grant all privileges on feedback .* to sqluser @ localhost;

7. Create a table called comments by some fiels in it as shown below:

CREATE TABLE COMMENTS (id INT NOT NULL AUTO_INCREMENT,

Myuser VARCHAR (30) NOT NULL,

EMAIL VARCHAR (30),

WebPage VARCHAR (100) NOT NULL,

Datum DATE NOT NULL,

SUMMERY VARCHAR (40) NOT NULL,

VARCHAR COMMENTS (400) NOT NULL,

PRIMARY KEY (ID)

);

8. Enter a line of records into the table.

INSERT INTO COMMENTS values ​​(default, 'boots', 'myemail@gmail.com', 'http://www.vogella.de',

'2004-06-22 10:33:11 ',' Summery ',' Na das war wohl nicths');

Making a database, tables and initial data mengisian been done. Now it's time to write Java programs to access the MySQL database.

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.Statement;

import java.util.Date;



public class DaoMySQL {

private Connection connect = null;

private Statement statement = null;

private ResultSet resultset = null;



public DaoMySQL () throws Exception {

try {

Class.forName ("com.mysql.jdbc.Driver"). NewInstance ();

connect = DriverManager.getConnection (

"Jdbc: mysql: / / localhost / feedback?" +

"User = & password = sqluser sqluserpw");



PreparedStatement statement = connect.prepareStatement ("SELECT myuser," +

"Webpage, datum, summery, COMMENTS from FEEDBACK.COMMENTS");



ResultSet = statement.executeQuery ();

while (resultSet.next ()) {

String user = resultSet.getString ("myuser");

String website = resultSet.getString ("webpages");

String resultSet.getString summery = ("summery");

Date date = resultSet.getDate ("datum");

String comment = resultSet.getString ("comments");

System.out.println ("User:" + user);

System.out.println ("Website:" + website);

System.out.println ("Summery:" + summery);

System.out.println ("Date:" + date);

System.out.println ("Comment:" + comment);

}

} Catch (Exception e) {

throw e;

} Finally {

close ();

}



}



private void close () {

try {

if (resultset! = null) {

resultSet.close ();

}



if (statement! = null) {

statement.close ();

}

if (connect! = null) {

connect.close ();

}

} Catch (Exception e) {}

}



public static void main (String [] args) throws Exception {

DaoMySQL DaoMySQL dao = new ();

}

}

Java programs on top of just taking the contents daritabel Comments and displays it to the console.
READ MORE - Java database applications

Monday, July 11, 2011

Microsoft Visual C++

Steps to create DLL
 The following steps illustrate how to create a Microsoft Visual C++ DLL project and then add and export the talkToObject() routine.

Create a new Microsoft Visual C++ 5.0 "MFC AppWizard (dll)" project named "vcvbdll" and accept all of the default options.
Add the following code to the end of the vcvbdll.cpp file.
 // Helper message function...
      void ShowMsg(char *msg, HRESULT hr) {
            char buf[1024];
            if((long)hr) {
               sprintf(buf, "%s, HRESULT = %08lx", msg, (long)hr);
            }
            else {
               sprintf(buf, "%s", msg);
            }
            ::MessageBox(NULL, buf, "C/C++ DLL message",
                         MB_SETFOREGROUND | MB_OK);
      }

      // The exported function, called from Microsoft Visual Basic...
      void _stdcall talkToObject(IUnknown *pUnk) {
            // QueryInterface for a IDispatch pointer...
            IDispatch *pDisp;
            HRESULT hr = pUnk->QueryInterface(IID_IDispatch,
                                             (void **)&pDisp);
            if(FAILED(hr)) {
               ShowMsg("QueryInterface() failed", hr);
            }
            else {
               ShowMsg("We got the dispatch pointer!!!", hr);

               // Attach dispatch to a COleDispatchDriver class.
               COleDispatchDriver disp(pDisp); // Uses constructor

               // Set visible to FALSE...
               static BYTE parms[] = VTS_BOOL;
               disp.InvokeHelper(0x17, DISPATCH_PROPERTYPUT, VT_EMPTY,
                                 NULL, parms, FALSE);


               ShowMsg("Microsoft Word 97 shouldn't be visible now.", 0);

               // Set visible to TRUE...
               disp.InvokeHelper(0x17, DISPATCH_PROPERTYPUT, VT_EMPTY,
                                 NULL, parms, TRUE);
               ShowMsg("Microsoft Word 97 should now be visible again!",
                       0);
         }
      }

Add the following line tothe end of the vcvbdll.def file so that the talkToObject function is exported:      talkToObject
                   
Compile and then copy the .dll to the \Windows\System directory for testing.
READ MORE - Microsoft Visual C++

void

Visual Basic is a programming language. It started out as a very simple one (called BASIC) in the days of dos and early windows/macs. As it evolved, and other languages were developed, it was usually relegated to first-time programmers. It is still recommended as a Beginners first language, but it has come on a lot since it was first released, and is often chosen over C++ because of the speed at which professional applications can be created using it. The major jump was from 16 bit to 32 bit in VB5 (you could also buy a 32 bit version of VB4). Visual Basic 6 was released late in 1998. Below is some sample code, one in C++ (the language windows is written in) and one in VB. As you can see, VB is plain language. Both examples do the same thing:

Visual Basic

Sub Command1_Click()
If Text1.Text = "" Then
Msgbox "You did not enter anything"
Else
Msgbox "You entered " & Text1.Text
End If
End Sub

VC++

void CTestDlg::OnBtnTest()
{
CString szMessage;
CString szEdit;
m_editText.GetWindowText (szEdit);
if ( szEdit == "" )
{
AfxMessageBox( "You entered nothing!" );
}
else
{
szMessage.Format( "You entered the text '%s'", szEdit);
AfxMessageBox( szMessage , MB_ICONINFORMATION);
}
}
READ MORE - void

Visual C++

Instructions

Now, let's go to work. Please follow the following steps: (Please skip the steps 1 to 8 if you don't have Visual C++ installed on your computer)

Click Start, if you have Windows 9x, click Programs, and if you have Windows XP, click All Programs, and then Microsoft Visual Studio 6.0 -- Or Microsoft Visual C++ 6.0 --, and then Microsoft Visual C++ 6.0.

In Microsoft Visual C++ 6.0, click File, and then New.... (Or press Ctrl+N)

In New dialog, click Projects tab, select MFC AppWizad (dll) in the Projects list. Set the Project name to MessageDLL, make sure Create New Workspace is selected, and then click OK button.

In the MFC AppWizard - Step 1 of 1 dialog, select Regular DLL using shared MFC DLL, select Yes, please in the bottom, and then click Finish button. Click OK button in the next dialog box.

In the Workspace window, expand the MessageDLL classes item, expand the Globals item, and then double click theApp item.

Please add the highlighted code by gray to theApp window:
// MessageDLL.cpp : Defines the initialization routines for the DLL.
//

#include "stdafx.h"
#include "MessageDLL.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

//
// Note!
//
// If this DLL is dynamically linked against the MFC
// DLLs, any functions exported from this DLL which
// call into MFC must have the AFX_MANAGE_STATE macro
// added at the very beginning of the function.
//
// For example:
//
// extern "C" BOOL PASCAL EXPORT ExportedFunction()
// {
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
// // normal function body here
// }
//
// It is very important that this macro appear in each
// function, prior to any calls into MFC. This means that
// it must appear as the first statement within the
// function, even before any object variable declarations
// as their constructors may generate calls into the MFC
// DLL.
//
// Please see MFC Technical Notes 33 and 58 for additional
// details.
//

/////////////////////////////////////////////////////////////////////////////
// CMessageDLLApp

BEGIN_MESSAGE_MAP(CMessageDLLApp, CWinApp)
//{{AFX_MSG_MAP(CMyWebTestApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMessageDLLApp construction

CMessageDLLApp::CMessageDLLApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// Message function

int _stdcall Message(HWND hHWND)
{
MessageBox(hHWND, "Hello World", "Message Box Title -- Hello World", MB_OK);
return 0;
}


/////////////////////////////////////////////////////////////////////////////
// The one and only CMessageDLLApp object

CMessageDLLApp theApp;



This is an explanation of Message function. First of all, we write an int word, this word mean that the function is an integer (like VB Function Func1() As Integer). The _stdcall is used to allow the users to use the Message function. The Message is the function name. The Message(HWND hHWND) is the function parameters, the HWND hHWND parameter is used to determine the form handler.

The MessageBox is the name of a function in Visual C++, this function is used to show a message box. The MessageBox syntax is int MessageBox(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType). As I explained, the hHwnd is used to determine the form handler. the lpText is used for the Message Box prompt/message. lpCaption is used for the Message Box title. And finally, you can use the uType to add pictures and to show/hide buttons from the Message Box.

The last thing is the return 0, the function will return what is typed after return statement.


Now, to let the developers use the functions in your DLL. You must add the function name to a file called MessageDLL.def. In the bottom of the Workspace window, click FileView tab, in the Workspace list, expand MessageDLL files item, expand Source Files item, and then double click on MessageDLL.def. Modify the file by replacing all the text with the following text:

; MessageDLL.def : Declares the module parameters for the DLL.

LIBRARY "MessageDLL"
DESCRIPTION 'MessageDLL Windows Dynamic Link Library'

EXPORTS
; Explicit exports can go here
Message





Under the Exports section, you must add all the functions you want to allow the developers to use.



Now we're done with the DLL. Go to Build menu, and click Compile MessageDLL menu item. If an error occur, please check the code, or download the tutorial. Now, go to File, Open.... In the Open dialog box, open your MessageDLL Project folder, go to Debug, make sure that you're showing all the file types, right-click on MessageDLL.dll file and click Copy. Now open your system folder, located at /windows/system/ in Windows 9x, and located in /windows/system32/ in Windows XP. Paste the DLL file to the system folder.

Now, let's go to Visual Basic. Start Visual Basic, create a New Project. In Form1, right-click on the form and click View Code/or double-click the form.

Replace all the code with the following code:

Option Explicit

Private Declare Function Message Lib "MessageDLL.dll" (ByVal hWnd As Long) As Long

Private Sub Form_Load()
Dim i As Integer

i = Message(Me.hWnd)
End Sub



Now, we are done. Visual Basic will locate the MessageDLL.dll without specifying the DLL file path, because Visual Basic always looks for the DLLs in the system folder, application folder, and many other folders.

Now, run the application by clicking the Start button, or by clicking F5 on your keyboard. When the program starts, a message box will appear with a "Hello World" message.
READ MORE - Visual C++

Sunday, July 10, 2011

CGI programming

CGI or Common Gateway Interface is a means for providing server-side services over the web by dynamically producing HTML documents, other kinds of documents, or performing other computations in response to communication from the user. In this assignment, students who want to interface with the Oracle database using Oracle's Pro*C precompiled language will be using CGI.

Java Servlets are the Java solution for providing web-based services. They provide a very similar interface for interacting with client queries and providing server responses. As such, discussion of much of the input and output in terms of HTML will overlap. Students who plan to interface with Oracle using JDBC will be working with Java Servlets.

Both CGI and Java Servlets interact with the user through HTML forms. CGI programming reside in a special directory, or in our case, a special computer on the network (cgi-courses.stanford.edu), and provide service through a regular web server. Java Servlets are separate network object altogether, and you'll have to run a special Servlet program on a specific port on a Unix machine.

The often-mystified abbreviation CGI, for Common Gateway Interface, refers just to a convention on how the invocation and parameter passing takes place in detail.

Invocation means different things in different cases. For a Perl script, the server would invoke a Perl interpreter and make it execute the script in an interpretive manner. For an executable program, which has typically been produced by a compiler and a loader from a source program in a language like C, it would just be started as a separate process.

In order to set up a C program as a CGI script, it needs to be turned into a binary executable program. This is often problematic, since people largely work on Windows whereas servers often run some version of UNIX or Linux. The system where you develop your program and the server where it should be installed as a CGI script may have quite different architectures, so that the same executable does not run on both of them.

This may create an unsolvable problem. If you are not allowed to log on the server and you cannot use a binary-compatible system (or a cross-compiler) either, you are out of luck. Many servers, however, allow you log on and use the server in interactive mode, as a “shell user,” and contain a C compiler.

You need to compile and load your C program on the server (or, in principle, on a system with the same architecture, so that binaries produced for it are executable on the server too).

Normally, you would proceed as follows:
Compile and test the C program in normal interactive use.
Make any changes that might be needed for use as a CGI script. The program should read its input according to the intended form submission method. Using the default GET method, the input is to be read from the environment variable. QUERY_STRING. (The program may also read data from files—but these must then reside on the server.) It should generate output on the standard output stream (stdout) so that it starts with suitable HTTP headers. Often, the output is in HTML format.
Compile and test again. In this testing phase, you might set the environment variable QUERY_STRING so that it contains the test data as it will be sent as form data. E.g., if you intend to use a form where a field named foo contains the input data, you can give the command
setenv QUERY_STRING "foo=42" (when using the tcsh shell)
or
QUERY_STRING="foo=42" (when using the bash shell).
Check that the compiled version is in a format that works on the server. This may require a recompilation. You may need to log on into the server computer (using Telnet, SSH, or some other terminal emulator) so that you can use a compiler there.
Upload the compiled and loaded program, i.e. the executable binary program (and any data files needed) on the server.
Set up a simple HTML document that contains a form for testing the script, etc.

You need to put the executable into a suitable directory and name it according to server-specific conventions. Even the compilation commands needed here might differ from what you are used to on your workstation. For example, if the server runs some flavor of Unix and has the Gnu C compiler available, you would typically use a compilation command like gcc -o mult.cgi mult.c and then move (mv) mult.cgi to a directory with a name like cgi-bin. Instead of gcc, you might need to use cc. You really need to check local instructions for such issues.

The filename extension .cgi has no fixed meaning in general. However, there can be server-dependent (and operating system dependent) rules for naming executable files. Typical extensions for executables are .cgi and .exe.

Perl Programming and CGI Scripting Course Overview:
Introduction to Perl
Origin and Design Goals of Perl
Overview of Perl Features
Getting and Installing Perl
Accessing Documentation via perldoc
HTML-Format Reference Documentation
Perl Strengths and Limitations Getting Started With Perl
Explicit Invocation of the Perl Interpreter
Running Perl on UNIX vs. Windows
Running Perl from the Command Line
Using Command Line Options
Using Debug Mode
Implicit Invocation of the Perl Interpreter
Running and Debugging Perl Scripts
Simple and Compound Statements
Fundamental Input Techniques
Using the print Function to Generate Standard Output
Using Variables
Scalar Variables
Introduction to Standard Data Types
Retrieving Standard Input Using the Default Variable $_
Reserved Scalar Variables
Assigning Strings and Numbers to Scalar Variables
Declaring Constants for Persistent Values
Using strict to Declare Variables Pattern Matching in Perl
Regular Expressions in Perl
Using Pattern Matching Operators
Altering Data with Substitutions in Regular Expressions
Using Backreferences to Capture Data from Regular Expression Matching
Global and Case-Insensitive Matches
Altering Data with Character Translation
Using Variables in Patterns
Operators
Introduction to Fundamental Operators
Operator Precedence and Associativity
Using the Ternary Operator ?: as a Shortcut for the if Statement
Using and <> File I/O Operators for Standard Input/Output
Using the Shortcut Operators +=, -=, *=, /= String Manipulation
String Comparison
String Relations
Concatenation
Substring Manipulation
Using chomp and chop to Eliminate EOL Characters
Escape Characters for Formatting
String Manipulation Functions
Flow Control: Conditional Statements and Looping
Conditional Expressions and Logical Operators
if/else/elsif and unless
Constructing switch/case Equivalent Expressions
while Loops and do Loops
for and foreach Loops
Labels
Altering Program Flow with next, last, and redo
Trapping Errors with the eval Function
Terminating a Script with exit Subroutines and Parameters
Simplifying Scripts with Subroutines
Defining and Calling a Subroutine
Passing Arguments by Value
Passing Arguments by Reference
Using return to Return a Value
Controlling Variable Scope using my and local Keywords
Arrays and Hashes
Defining Numeric Index Arrays
Defining Associative Arrays
Sorting Arrays with the sort Function
Adding and Deleting Items Using push, pop, shift, and unshift
Using slice, splice, and reverse
Other Array Manipulation Techniques
Looping through an Array
Merging Arrays
Associative Array Manipulation Functions
Introduction to Hashes
Preallocating Memory to Optimize Hash Performance Packages and Modules
The Power of Packages and Modules
Introduction to Standard Modules
Where to Find Modules on the Internet
Installing a Module on UNIX or Windows
Creating Packages for Portability
Using Packages to Create Isolated Namespaces and to Separate Code
Creating Modules
Creating and Using Symbols in a Module
Using the Exporter to Export Symbols from a Perl Module
File and Directory I/O
Using open and close
File Open Modes
Reading Files into Arrays
Retrieving File Metadata
Built-in File Management Functions
Using print and write
File Test Operators
Directory Manipulation Using opendir, closedir, readdir, chdir, mkdir and rmdir Input/Output Processing
Parsing Input
Using Standard Input, Standard Output, and Standard Error
String and Field Processing
Using Streams and Pipes
Using die to Quit with an Error
Redirecting Standard Output and Standard Error to a File
Getting Standard Input from a File
Implementing Command Line Arguments
Reading Command Line Arguments from @ARGV
Read Files Explicitly with and Implicitly with <>
Manipulating Positional Parameters with push, pop, shift
Process Lists of Files
Processing Command Line Options with getopt or getopts
Analyzing Command Line Argument Values with the Getopt::Std and Getopt::Long Modules
Reserved Variables
Manipulating Identifiable Options Using GetOptions Perl Report Formatting
Defining Report Formats
Justifying Text (Left, Right, Center)
Using write to Generate Reports
Defining here Documents for Report Customization
Creating Report Headers
Using Built-in Variables to Control Report Appearance
Printing Line Numbers on a Report
Formatting Multi-Line Output
Writing Formatted Text to a File
Debugging In Perl
Using the Built-in Perl Debugger
Starting the Debugger
Debugger Command Syntax
Checking for Script Syntax Errors
Solving Compile-Time Errors
Single-Stepping through a Script
Executing to Breakpoints
Setting Global Watches
Printing Values of Variables
Listing All Variables Used in the Script
Using Strict Error Checking
Quitting the Debugger References
Life Cycle of a Reference
Hard References and Anonymous References
Use of References to Create Complex Data Structures
Creating Hard and Anonymous References
Modifying References
Dereferencing a Reference
The Arrow Operator ->
Building Complex Data Structures with Multi-Dimensional Arrays and Hashes
Accessing a Database Using Perl DBI
Database Access Life Cycle
Using DBI and DBD to Connect to a Database
Fundamental Data Storage and Retrieval Strategies
DBI Query Syntax
Using DBI Methods to Retrieve Database Information
Preparing Queries to be Executed
Creating Parameterized Queries
Executing Queries Using execute and do
Fetching the Result Set to Achieve Workable Data in the Perl Script
Extracting Data Using an Array
Extracting Data Using a Hash
Useful Utilities to Aid in Database Development
Using Other Modules to Access Databases on the Web
Extracting Data Using a Hash
Displaying Results from Queries in a Report
Releasing Database Resources Perl Object Oriented Programming
Object Oriented Programming Concepts
Object Oriented Programming Terminology
How Perl Implements Object Oriented Programming
Modeling Software Objects Using Classes and Base Classes
Creating Classes, Objects, Methods and Attributes
Writing Constructors to Initialize of Objects
Using bless to Turn References into Objects
Creating Class Hierarchies through Inheritance
Web Architecture and CGI Scripting Overview
Static vs. Dynamic Web Pages
Serving a Static HTML Web Page
Serving a Dynamic HTML Web Page
Dynamic Web Page Capabilities
The Common Gateway Interface
How Server-Side CGI Scripts Work
Differences between Client-Side and Server-Side Script Environment
Strengths and Weaknesses of Web Programming Languages CGI Scripting with Perl
Perl's Role in Distributed Web Applications
Using Environment Variables to Control CGI Scripts
Communicating with the Web Server
Perl CGI Script Instantiation and Invocation
Generating Output for the Browser
CGI Security Mechanisms
Configuring a Web Server for CGI
Servers and CGI
The Apache httpd.conf File
Aliasing Standard Directories in Apache
Using Standard Apache-Aliased Directories
The Default Apache cgi-bin Directory
Aliasing CGI-Enabled Directories in Apache Fundamentals of CGI Scripting with Perl
Perl's Role in Distributed Web Applications
Using Environment Variables to Control CGI Scripts
Communicating with the Web Server
Perl CGI Script Instantiation and Invocation
Generating Output for the Browser
CGI Security Mechanisms
The Importance of the "Shebang" Line
"Shebang" Line CGI Errors
Debugging CGI Errors
Linux vs. Windows File Format Errors
Setting Linux File Protections
Specifying the Page MIME Type
Generating Standards-Compliant HTML
Generating Dynamic Web Pages Using Perl/CGI
Generating Dynamic Web Pages and Dynamic Content
The Role of JavaScript
Generating JavaScript Using CGI
Displaying Data in Tables
Using Environment Variables to Control CGI Scripts
Displaying Data from Files
CGI Output Stream Buffering Dynamic Behavior Based on Query Strings
The Query String Part of a URL
Parsing the Query String
Using Query Strings to Maintain Session State
User-Defined Modules and CGI
Processing HTML Forms with Perl CGI
Creating and Submitting HTML Forms
HTML Input Elements
Submitting a Form
Form Interaction Summary
Populating Form Elements Using CGI
Processing HTML Forms
Characteristics of the GET Method
GET Method Environment Variables
Characteristics of the POST Method
POST Method Environment Variables
Using Form Data Validation to Check Data Values Using the Perl CGI.pm Module - Introduction
Orientation to CGI.pm
The Power of Perl-Supplied Routines
Simplifying Debugging
Using CGI.pm in Object-Oriented Style
Named Parameter Syntax
Using CGI.pm in Procedural Style
Importing Groups of CGI.pm Methods
CGI.pm Output and XHTML
Mixing CGI.pm Methods with Standard Perl
Custom Tag Generation
Form Processing with CGI.pm
Classes of CGI.pm Methods
Specifying Arguments for HTML Tags
Differentiating Blank & Missing Parameters
Using Passed Parameters as Numbers Maintaining State with CGI.pm
State Information and the Web
Using Extra Path Information
Using Hidden Fields in Forms
Using Client-Side Cookies
Setting Cookies
Cookie Parameters
Setting Cookies from Form Data
Deleting Cookies
Form Validation and Cookie Storage
Cookie Deletion
Overcoming Cookie Limitations
Performance Optimization Using ModPerl
Overview of Apache Web Server Functionality
Comparing the Speed of CGI Scripting vs. ModPerl
Configuring Apache with Perl and ModPerl
Apache Strengths and Limitations
Using the Apache::Registry Module
Extending and Enhancing Apache Functionality Developing Multi-Tiered Web Applications
Review of Multi-Tiered Web Application Components
Putting It All Together
Using High-Level Packages to Assist with Scalability and Maintainability
READ MORE - CGI programming

Sunday, July 3, 2011

Visual Basic 6

Public Function getAgePhrase(ByVal age As Integer) As String
If age > 60 Then Return "Senior"
If age > 40 Then Return "Middle-aged"
If age > 20 Then Return "Adult"
If age > 12 Then Return "Teen-aged"
If age > 4 Then Return "School-aged"
If age > 1 Then Return "Toddler"
Return "Infant"
End Function


Visual Basic 6 adds two important features to arrays. First, you can perform assignments between arrays. Second, you can write procedures that return arrays. You can assign arrays only of the same type and only if the target is a dynamic array. (The latter condition is necessary because Visual Basic might need to resize the target array.)

ReDim a(10, 10) As Integer
Dim b() As Integer
' Fill the a array with data (omitted).
b() = a() ' This works!

It's no surprise that native assignment commands are always faster than the corresponding For…Next loops that copy one item at a time. The actual increment in speed heavily depends on the data type of the arrays and can vary from 20 percent to 10 times faster. A native assignment between arrays also works if the source array is held in a Variant. Under Visual Basic 4 and 5, you could store an array in a Variant, but you couldn't do the opposite—that is, retrieve an array stored in a Variant variable and store it back in an array of a specific type. This flaw has been fixed in Visual Basic 6:

Dim v As Variant, s(100) As String, t() As String
' Fill the s() array (omitted).
v = s() ' Assign to a Variant.
t() = v ' Assign from a Variant to a dynamic string array.

You often use the capacity to assign arrays to build functions that return arrays. Notice that pair of brackets at the end of the first line in the following procedure:

Function InitArray(first As Long, Last As Long) As Long()
ReDim result(first To Last) As Long
Dim i As Long
For i = first To Last
result(i) = i
Next
InitArray = result
End Function
READ MORE - Visual Basic 6

Monday, June 13, 2011

Visual Basic

HTML server controls are of two slightly different types. The HTML elements most commonly used in forms are available as individual HTML server controls, such as HtmlInputText, HtmlInputButton, HtmlTable, and so on. These HTML server controls expose their own, control-specific properties that map directly to HTML attributes. However, any HTML element can be converted to a control. In that case, the element becomes an HtmlGenericControl with base class properties such as TagName, Visible, and InnerHTML.

To set properties of HTML server controls
Get or set the property name as you would with any object. All properties are either strings or integers. The following examples illustrate this:
' Visual Basic
myAnchor.Href = "http://www.microsoft.com"
Text1.MaxLength = 20
Text1.Value = string.Format("{0:$###}", TotalCost)
Span1.InnerHTML = "You must enter a value for Email Address."

// C#
myAnchor.HRef = "http://www.microsoft.com";
Text1.MaxLength = 20;
Text1.Value = string.Format("{0:$####}", TotalCost);
Span1.InnerHtml = "You must enter a value for Email Address.";

All HTML server controls also support an Attributes collection, which gives you direct access to all the control's attributes. This is particularly useful for working with attributes that are not exposed as individual properties.

To work with control attributes directly
Use the properties and methods of a control's Attributes collection, such as Add, Remove, Clear, and Count. The Keys property returns a collection containing the names of all the attributes in the control. The following examples show various ways to use the Attributes collection:
' Visual Basic
' Adds new attribute.
Text1.Attributes.Add("bgcolor", "red")
' Removes one attribute.
Text1.Attributes.Remove("maxlength")
' Removes all attributes, clearing all properties.
Text1.Attributes.Clear()
' Creates comma-delimited list of defined attributes
Dim strTemp As String = ""
Dim key As String
For Each key In Text1.Attributes.Keys
strTemp &= Text1.Attributes(key) & ", "
Next

// C#
// Adds a new attribute.
Text1.Attributes.Add("bgcolor","red");
// Removes one attribute.
Text1.Attributes.Remove("maxlength");
// Removes all attributes, clearing all properties.
Text1.Attributes.Clear();
// Creates comma-delimited list of defined attributes
string strTemp = "";
foreach (string key in Text1.Attributes.Keys)
{
strTemp += Text1.Attributes[key] + ", ";
}
READ MORE - Visual Basic

Monday, June 6, 2011

procedure is a block of program code designed to solve common problems

procedure is a block of program code designed to solve common problems. Suppose the pascal programming language known as Writeln procedures, clrscr, textbackground, textcolor, readln, etc.. The invitation to these procedures vary from one procedure to another procedure. Suppose that function clrscr procedure to remove all the writing on the screen and position the cursor at X = 0 and Y = 0. Clrscr in the calling procedure does not require parameters; procedure Writeln / write function to print the output (output) to the screen. Procedure Writeln / write can be called with or without include parameters include parameters. For example, instructed the translator (compiler) Pascal to move the cursor down one line (Score Increase Y) and X remained in position 0 as shown in the following code:

begin
Writeln;
end.

In the above code was called Writeln procedures not followed by parameters. Pascal understand that if the Writeln procedure call without parameters then position the cursor on the monitor changes the cursor back to position X = 0 (Carriage Return) and the Y position plus One - Down The Line (Line Feed).

Another example we could send Writeln procedure to print a multiplication 10 * 10:

begin
Writeln (10 * 10);
end.

The code above can be explained that we call the Writeln procedure by sending a parameter multiplying 10 * 10. Because the Writeln procedure is a procedure that has been ready to use (built-in procedure) or have been defined by pascal eat the detail of the instructions in the Writeln procedure we do not know for sure.

We can also tell Writeln command to print a string of characters (string) "Respati Yogyakarta":

begin
Writeln ('Respati Yogyakarta');
end.

Or a combination of value and konstanta as follows:
begin
Writeln (10 * 10, 'Respati Yogyakarta');
end.

Flexibility Writeln procedure would be very helpful in giving commands to the computer.

User Defined Procedures
Pascal allows programmers to create their own procedures (user defined procedure). The procedure (syntax) the declaration made by the user procedure is:

namaprosedur procedure ([par1, par2, par3, ... parn]);
{Variables declarations}
{Declarations} procedure
{Functions declarations}
{Constants declarations}
{Declaration} label

begin

end;

Dikelarasikan procedures can then be called from the main program or from the procedure itself or other procedures.

The following will be a procedure to print the address Unriyo Yogyakarta:

CetakAlamat Program;
uses crt;
procedure Address ();
begin
Writeln ('University Respati Yogyakarta');
Writeln ('Jln.Laksda Adisucipto Km.6, 3 Depok, Sleman, Yogyakarta');
end;

Begin
clrscr;
Address} {Calling Procedure
Address ();
End.

Procedure Berparameter
Procedures are given specific tasks to take parameters as needed. Suppose there are desirable procedure to print numbers 1 to N. Here the N value is uncertain, can be 10, 20, 100. For this procedure call when we send the value of N and further process the printing procedure numbers 1 to N.


Print-Program;
Uses Crt;

Procedure CetakAngka1Sd (N: Byte);
Var
I: Byte;} {Declaration of Local
Begin
For I: = 1 To N Do
Writeln (I);
End;

{Main Program}
Begin
{Clear the screen}
clrscr;
Print a Procedure Call {20} s.d
CetakAngka1SD (20);
{Procedure Call Again Print Number 1 s.d 100}
CetakAngka1SD (100);
Readln; {Wait Pressing Enter key}
End.


Parameter Value and Reference Parameters
In general, the parameters passed to the procedure are the parameter value means the parameter value will not change after the procedure call. When the desired parameter value changes after calling the procedure, the parameter is called a reference parameter.

Create a procedure to calculate the number of runs the following:
1 / 1 +1 / 2 +1 / 3 + ... 1 / N
Desired number N is uncertain and at once the sum looks after the procedure call. Thus it takes 2 (two) parameters: N (parameter value) and amount (reference parameter).


Jumlah_Deret Program;
Uses Crt;

Procedure Number (N: Byte; Var Amount: Real);
Var
I: Byte;
Begin
Total: = 0;
For I: = 1 To N Do
Total: = Total + 1 / I
End;

Var
Cacah_Data: Byte;
Results: Real;
Begin
clrscr;
Cacah_Data: = 10;
{Procedure Call}
Total (Cacah_Data, Result);
Writeln ('Number of Series', Result: 8:2);
Readln;
End.

Variable Scope
The scope variables (variables scope) describes the accessibility of these variables. In Pascal there are 2 (two) types of scope that is global and local scope. Global scope indicates that the variable will be recognized throughout the program code. Local scope indicates that the variable is only known place declared.

Suppose there are programs such as the following:

Var
IGlobal: Byte;

Procedure LokalSatu;
Var
ILokal1: Byte;
Begin
ILokal1: = 10;
Writeln (ILokal1, IGlobal);
End;

Procedure LokalDua;
Var
ILokal2: Byte;
Begin
ILokal2: = 20;
Writeln (ILokal2, IGlobal);
End;

{Main Program}
Begin
IGlobal: = 10;
Local;
End.

In the above code IGlobal variable will be recognized throughout the source code (both in the Main Program, LokalSatu Procedure, Procedure LokalDua). While the variable will only be known in ILokal1 LokalSatu procedure. Likewise ILokal2 variables will only be known in LokalDua procedure.

We note again the following program code:

Lingkup_Lingkup Program;
Var
I: Byte;
Outlying Procedure;
Var
ITerluar: Byte;
Deepest Procedure;
Var
ITerdalam: Byte;
Begin
ITerdalam: = 20;
Writeln (I, ITerluar, ITerdalam);
End;
Begin
ITerluar: = 10;
Outlying} {Call Procedure
End;

{Main Program}
Begin
I: = 5;
Outlying;
End.

In the code above first global nature means it will be recognized in the main program, procedures for the outer and inner procedure. ITerluar variables will be global in that procedure so that the variable will be recognized procedures declared in the procedure. However ITerluar variables will not be recognized by the Main Program. ITerdalam variables will only be recognized by Deepest Procedure.

Recursive Procedure
The procedure that calls itself is called as recursive procedures. Suppose there is code like the following:

Procedure Print;
Begin
Writeln ('Respati');
{Procedure Call} Himself
Print;
End;

{Main Program}
Begin
{Procedure Call}
Print;
End.

The above source code can be explained as follows:
1. Start
2. Procedure Call Print
3. Print string 'Respati'
4. Procedure Call Print
5. Print string 'Respati'
6. Procedure Call Print
7. Print string 'Respati'
8. ff

Summons against itself will still be conducted Print procedure because there is no statement to stop calling. This calling will continue ongoing (continues call).
To overcome this problem it is necessary to make a statement that limits the procedure call. Suppose the above program code we change something like this:


Var
I: Byte;
Procedure Print;
Begin
IF (I <= 5) Then begin Writeln ('Respati'); {Procedure Call} Himself Print; I: = I +1; end; End; {Main Program} Begin I: = 1; {Procedure Call} Print; End. In the code above procedure will only be invoked Print 5x as much as stated in condition IF (I <= 5). If I> 5 then print the procedure will not be called again. Generally determined a condition that lay on the procedure call itself.

Parameter array
Array parameters can be passed to the procedure with little difference from the parameters of conventional type (byte, word, integer, real).

Jumlah_Data Program;
Const
N = 100;
Type
Data: Array [1 .. N] Of Single;
Var
Adata: Data;

Procedure Number (DataA: Data, Count: Byte) '
Begin
For I: = 1 To N Do
Jlh: = Jlh + DataA [I];
Writeln ('Number of Data Is', Jlh: 12:0);
End;

{Main Program}
Begin
{Enter data}
ADATA [1]: = 70;
ADATA [1]: = 65.5;
ADATA [1]: = 89;
ADATA [1]: = 77;
ADATA [1]: = 64;
ADATA [1]: = 78.5;
{Call Procedure Number of Data}
Total (Adata, 6);
Readln;
End.

Exercise Procedure
Known weight data Prodi student information system as below:
65,78,58,60,63,56,65,69,77
Make procedures for:
1.menginputkan N Fruit data
2.menghitung number, average weight and standard deviation
3.mengurutkan data in ascending (ascending)
4.mengurutkan data in descending order (descending)
5.melihat contents array

To resolve these cases will be made in the form pilihahan menu making it easier in the use of the program.
Menu Options
1. Input Data
2. Determine Total, Average and Standard Deviation
3. Sort Data In Ascending
4. Sort Data By Descending
5. Display Array Contents
Your choice [1 .. 5]:


Statistics Program;
Uses Crt;
Const
N = 100;

{Weight} Input Procedure Declaration
Procedure Input_Berat (Berat_Mhs: Weight: N: Byte);
Var
I: Byte;
Begin
For I: = 1 To N Do
Begin
write ('Enter The Weight', I ,':'); readln (Berat_Mhs [I]);
End;
End;

{Main Program}
Var
Repeat: Boolean;
Pills: ShortInt;
Begin
Repeat: = True;
While (Repeat) Do
Begin
clrscr;
gotoxy (25.1), write ('U U M E N T A M A');
gotoxy (25.2); write ('---------');
gotoxy (25.3), write ('1. Input Data ');
gotoxy (25.4), write ('2. Determine the Number of, Average, Standard Deviation ');
gotoxy (25.5), write ('3. Heavy Sort Descending ');
gotoxy (25.6), write ('4. Heavy Sort Ascending ');
gotoxy (25.7), write ('5. Show Array ");
gotoxy (25.8), write ('0. Done ');
pill: =- 1;
while (pills <0) or (pill> 5) do
begin
gotoxy (25.9), write ('Your Choice [0 .. 5]:'); readln (pills);
end;
Test {More}
Case (Pil) Of
1: Begin Weight} {Input Data

End;
2: Begin {Set Total, Average and Standard Deviation}

End;
3: Begin {} Ascending Sort By

End;
4: Begin {} Sort By Descending

End;
5: Begin Array} {Shown Contents

End;
0: Begin {End Program}

End;
End;} {End of Case
End; {End While}
End. {End Program}
READ MORE - procedure is a block of program code designed to solve common problems

Pascal triangle

Pascal triangle shape can be arranged as below:
1
121
1331
14641
15101051
................

To facilitate understanding of each element of the above can we put in the matrix as follows:
- Number 1 in row 1 column 1
- Number 1 in row 2 column 1, number 2 in row 2 column 2, number 1 row 2 column 3
- Number 1 in row 3 column 1, number 3 in row 3 column 2, number 3 in row 3 column 3, number 1 in row three column 4
and so on

We note that each line has a lot of counting elements such as the following:
First-line there is 1 element
The second-row there are 3 elements
The third-row there are 4 elements
Fourth-line there are 5 elements
-And so on
The second line, third, fourth and so on plus-plus element two.

Suppose there is a matrix A (N, M), then these values ​​can be entered as follows:
A (1,1) = 1
A (2,1) = 1
A (2,2) = 2
A (2,3) = 1
A (3,1) = 1
A (3,2) = 3
A (3.3) = 3
A (3,4) = 1
and so on

To facilitate workmanship we will initialize 2 pieces of array elements
About the way the process as follows:
0. Start
1. Specify many levels, say N, Determine matrix A (10.10)
Define A (1,1) = 1, A (1,2) = 1
2. Print row and first column
3. Starting first from 2 to N
4. Print 1
5. Ranging from 2 to I
Determine the next value
Value = A (I-1, J-1) + A (I-1, J)
Value = matrix current line minus one, minus one column current + current reduced matrix row one, column today.
Print Values
6. Repeat to 5
7. Print 1
8. Down Line
9. Repeat to 3
10. completed
Private Sub Form_Activate ()
Dim A (10.10) As Byte
A (1,1) = 1 'Initialize
A (1,2) = 1 'Initialize
print A (1,1) 'print the first line
For I = 2 To 10 Step 1 'value 10 is considered a level up to 10
print "1"
For J = 2 To First Step 1
Value = A (I-1, J-1) + A (I-1, J)
print value;
Next J
Print "1";
Print 'Down Line
Next I
End Sub
READ MORE - Pascal triangle

The data type is a limit value that can be saved

The data type is a limit value that can be saved. In MS-Access there are different kinds of data types include:
- Byte
- Integer
- Text
- Date / Time
- Number
Suppose you want to keep track student's name. Names of the students to like "Rita", "Ahmad Dahlan", "Betra Aginta Ginter", and so forth. The name is composed of the characters. To accommodate the character data of MS-Access provides a data type text. Another example suppose you want to keep the weight of a student data. Weight data are generally stored in the fractions. For example, Ani weight 45.5 kg. To accommodate the data is numeric, MS-Access provides a data type Number.
READ MORE - The data type is a limit value that can be saved

Arithmetic Statement

Arithmetic Statement

Unknown 3 (three) pieces of numbers A, B and C. Make a visual basic program to solve the following arithmetic equation:
P = A + B
Q = B-A
X = A + BC
R = (A + B) * C
S = (A + B) * (A-C)
M = A Mod 2
N = B-A + C ^ 2

- user interface program

- Implementation

Dim A, B, C As Single 'Global Declaration

Private Sub cmdHitungM_Click ()
Dim B As Single
A = Val (txtA.Text)
B = Val (txtB.Text)
M = A Mod 2
txtM.Text = Str (M)
End Sub

Private Sub cmdHitungN_Click ()
Dim N As Single
A = Val (txtA.Text)
B = Val (txtB.Text)
C = Val (txtC.Text)
N = B - A + C ^ 2
txtN.Text = Str (N)
End Sub

Private Sub cmdHitungP_Click ()
Dim P As Single
A = Val (txtA.Text)
B = Val (txtB.Text)
P = A + B
txtP.Text = Str (P)

End Sub

Private Sub cmdHitungQ_Click ()
Dim Q As Single
A = Val (txtA.Text)
B = Val (txtB.Text)
Q = B - A
txtQ.Text = Str (Q)
End Sub

Private Sub cmdHitungR_Click ()
Dim R As Single
A = Val (txtA.Text)
B = Val (txtB.Text)
C = Val (txtC.Text)
R = (A + B) * C
txtR.Text = Str (R)
End Sub

Private Sub cmdHitungS_Click ()
Dim S As Single
A = Val (txtA.Text)
B = Val (txtB.Text)
C = Val (txtC.Text)
S = (A + B) * (A - C)
txtS.Text = Str (S)
End Sub

Private Sub cmdHitungX_Click ()
Dim X As Single
A = Val (txtA.Text)
B = Val (txtB.Text)
X = A + B * C
txtX.Text = Str (X)
End Sub

Private Sub cmdTutup_Click ()
End
End Sub

- Running

Analysis
 Statement P = A + B, can be understood by Visual Basic because the procedure of writing (syntax) is correct. This expression can be described also as follows:
 P is the operand
 = Is the operator
 A is the operand
 + Is an operator
 B is the operand
 So from the above statement there are 3 pieces of operands.

Operands in Visual Basic can be identifiers, functions or constants. The statement Z = 5 + 5 also can be recognized by visual basic. Number 5 in the statement is an operand whose value is 5. Statement
 Z = rank (5) + A also can be understood by Visual Basic when the definition of rank function with the parameters already defined.

Each statement of Visual Basic can be divided into 2 (two) groups:
 -Groups of the left (left operand) and
 Right-group (right) operand)
 between groups separated by an equal sign (=)

On the left of the group must be identification, whether variable or constant identifier and not the value of variables, constants. Visual Basic does not recognize this writing the following statement:
 5 = A + B 'false statement
 5 + 5 = A 'statement wrong
 "Santi" = A 'statement wrong
 Rank (5) = 10 'false statement

The statement will be true when written like this:
 Z = A + B
 A = 5 + 5
 A = "santi" 'set of characters (string) given to the identification A
 Z = rank (5) 'statement called the rank function with 5 parameters

The order of execution in both groups will start from the second group. Further progress in the second group will be tailored to the degree of the operator (see note below for details). Suppose there is a statement:
 Z = A + C - B
 then the process will begin the process of:
 1. A + B, ie X
 2. X - B, ie R
 3. R was given to Z

Notes
 -Of particular interest in the formation of an arithmetic expression is a sequence of execution of each operator.
 -The order processing service will start from the left.
 -If found, the bracketed expressions in parentheses will be done the first time
 Rank-Operator (^) is the operator that has the highest degree of workmanship. The execution of the operator ^ more precedence than the operator /, *, Mod, + or -.
 -Operator for (/), times (*) and Mod (remainder of) have the same degree of craftsmanship and workmanship higher priority than the operator plus (+) and minus (-).
 -The operator plus (+) and minus (-) have the same degree of workmanship.
READ MORE - Arithmetic Statement

Arithmetic operations

Arithmetic operations

Arithmetic operation is an operation involving arithmetic operators. Arithmetic Operators in Visual Basic is:
- plus (+)
- minus (-)
- times (*)
- for (/)
- rank (^)
- residual for (mod)

Arithmetic operators generally operate on two operands. For example the expression 2 + 2, means:
2 is the first operand
Arithmetic operator + is added
2 is the second operator.

But in some respects, especially operators + and less operate on one operand, such as giving the value of +5 (positive 5) or -5 (negative five).

In visual basic arithmetic operators workmanship has set the degree of workmanship as follows:

Operator Degrees
^ 1
* / Mod 2
+ - 3

operators who have the same degree will be done starting from the left.
For example there is the statement:
A = 2 + 2-5
seen that there are two of the arithmetic operators + and -. It was decided that the operators + and - have the same degree of craftsmanship so that the operator of the most left will done first. Thus the order of execution of the statement are:
1. 2 + 2 provides the results of 4
2. 4-5 give the results -1
3. -1 was given to a variable A

Suppose there are statements like the following:
A = 2 + 5 * 10, then the process sequence is
1. 5 * 10 = 50
2. 2 + 50 = 52
3. 52 were given to A

We consider the operator * is done in advance rather than operator +. How about if we change the order of workmanship want where desired operator + higher degree of workmanship of the operator *. To do this on a operator operators + plus open parenthesis and close parenthesis so that the form of a statement becomes:
A = (2 +5) * 10, then the order of the process becomes:
1. 2 + 5 = 7
2. 7 * 10 = 70
3. 70 were given to A

If there are parentheses within parentheses, the innermost parentheses to be done first. For example there is a statement as follows:
A = 7 * ((2 +5) * 10), then the sequence of the process becomes:
1. 2 + 5 = 7
2. 7 * 10 = 70
3. 7 * 70 = 490
4. 490 were given to A

Suppose there is a statement as follows:
A = (2 + 5) * 10-15 + 7 ^ 2, then the order of execution of the statement are:
1. 2 + 5 = 7
2. 7 ^ 2 = 49
3. 7 * 10 = 70
4. 70-15 = 55
5. 55 + 49 = 104
6. The value 104 was given to A
READ MORE - Arithmetic operations
 
THANK YOU FOR VISITING