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
 
THANK YOU FOR VISITING