JSP Base

Sunday, October 25, 2009

What jsp that?
java server pages (jsp) be a tenologi servlet-based that used in web tier to present dynamic and static content. jsp be text-based and majority full template text html that united with specific tags dynamic content.

why use jsp?

- since jsps be document text like html, developers avoid formats and manipulation that make possible string very long to produce output. content html now is not being embeddinged with assortedly code from java. this matter makes it easier to maintained.
- jsps more knowledgeable by everybody with eruditions from html, only with study markup dynamic. this matter makes it may be to desainer site to make template html from a site, with developers processed it in a moment later to put into tags that produce dynamic content. this matter also make easy in web development page.
- jsps has built-in that support for software component use that can be used back(javabeans). this matter not only lets developers avoid possibilities finds to return kernel/rudder from every application, has supporter software to separate software component to handle logic promotes separation from presentation and business logic.
- jsps, be solution part from java for web application developers, be multi-platform indivisible and can be run in various container servlet
compatible, beglectfully vendor or the operation system.
- in the hook by work jsps, they don't want compilation from developers. this compilation there for us in container servlet. modification jsps detected automatically. this matter is relatively makes it easy to built.
example jsp

selamatdatang. Jsp

picture on file jsp simple that do expectation to site user information date and time in this time for user.
from example on, we can see that file jsp be most of html. only in this part is difference:
<%= new java.util.Date()%>
this matter is part from java code to display day and date forthwith. this matter simplifies for make new object to makes object date and display it as string.
under this be result output from file jsp on.

Use IDE enterprise

jsp can be run from assorted project web application in IDE. with assumption that project is ready.

spesification from file jsp this then can be run from IDE directly with depress shift + f6. alternative other, project web can be run as WAR file and upload into server. then jsp can be accessinged with url typing follow:

use build tool

jsp also can be run with keep it as WAR file by using build tool(like one of the outlined in chapter servlet base), and then run WAR file into server web.

directory structure

jsp file must be kept in directory web.

jsp channel

container servlet regulate jsps at one particular manner to regulate servlet itself: pass use a channel jsp so can be run well.
method servlet that taken from container different: jspinit() for phase initialization, _jspservice() to service phase, and jspdestroy() to destroy phase.

from example jsp that given, seen to stump to discuss method jspinit or _jspservice(). example from jsp only simple text page majority come from content html: he doesn't has method other. answer from matter: jsps -compile into class servlet same by server. this matter causess class servlet that handle demand for page jsp. translasi this putted into to into servlet and compilation subsequent finished used by server: unnecessary developers doubt about how prosedure this finished.
if you hope to see class servlet -generate installation from kiss server application 8.1 laid them in this directory:



Saturday, October 24, 2009

JSF identification
JSF framework to build interFaces user for web application. Built to base on concepts that introduced by Struts and divide with profit a architecture genuinely separate layer presentation from business logic and a interFaces user standards component the ware similar to Swing widget.
Under this detail description hows framework Faces work

such as those which we see, JSF has also clear separation between layer component Model, View, and Controlller. same like Struts, JSF has a Controlller servlet frontage that is FacesServlet that to get request from client and then run action that wanted that guided by framework. Another similarity both of them uses action handler apart from Controller servlet frontage. Bevertheless handle Faces this is a little differ from Struts.
Faces and Struts has aim same related to layer View. Here, Struts only prepare a set libray tag that added in part on function standards HTMLunction. On the contrary, Faces prepare set self from components along with a set library to show these components as tag and a result component render that translate UI component be HTML.

Layer Controller from Faces that consist of Controller servlet (FacesServlet), a set of configuration file XML and a set action handler.

FacesServlet responsible to get request from client and run operation that need to produce response. This operation belongs to prepare UI components that wanted for request, update component status, call action handler that wanted (if there), and UI components result render that be part from response.
FacesServlet provided for us by framework JSF, and only want configuration in a development descriptor application before ready for used.
Under this cut that for us how configure FacesServlet for our application.

action handlers
Explained previous that Faces use action handler independent from Controller servlet frontage, same like Struts. Bevertheless, Faces do this function differently.
In Faces, there two manners makes action handler. First with make one a method JavaBean to act as action handler, and second with make a class instans implementation interFaces ActionListener.

application method
a method that must has a UI component to act as action handler be called method application. Then, in part View, we shall see to how cordage finished. meanwhile, there are some rule that wanted to make a method application:
-method must public declaration
-method must without parameter
-kind return method must be a String

Under this a method may be can we use to handle a event as result from user that try to logging:

One of the profit from kind action handling this decrease quantity object developers beeds to -maintain. Method this can in every JavaBean that known by framework, although usually detectable in bean that used as backing Model for page form certain. In example on, loginname and password properties in backing Model.
String that returned by method application give information FacesServlet where next seen by user. String has reasonable names, sometimes called outcome; outcome this adjusted with regulations navigation that inscribed in configuration file.
One important matter to is registerred manner that goed by us in laid object into scope session in framework JSF. In Struts, because handling object action form that given a instans HttpServletRequest, be easy to get a copy from scope session that represent object httpsession. any way, bo matter to action handler in Faces. inste, object in framework Faces get access profit to context external (web container, portlets, etc) use a instans from object Facescontext.

after get object Facescontext, we get portfolio representation object in scope session with call getExternalContex(). getSessionMap().


Manner other implementation action handler in JSF make a class implementation interFaces ActionListener. This interFaces spells out a method single:

public void processaction(actionevent event)

object actionevent letted pass as parameter in method that prepare access implementation class to component that caused by event. This matter similar to how does manner object event work in Swing programming.
Under this a implementation example ActionListener that used to logging user action.

up to in this time, better use method application to act as action handler. First, they can be laided in class same where act as backing Model a form, and matter like that has easier access to user prepares data. second, be backing Model admits developers to classify together a data and method that in one class, make more make -maintain. Third, method application will can to return outcome give information FacesServlet display that will displayed furthermore. ActionListener can not, thereby only can bring user return to original page after handling a event.
ActionListener appropriate choice, bevertheless if you want ability general refactor that you can use to return across multiple action sources.
If we see coming, maked to has a method application with a or more ActionListener to work as handler to action certain. Best matter to is done then get best from both: has a method application to do special handling to action, and then has ActionListener that do general aim function.

Faces-config. XML
This matter acts as principal configuration file to layer Controller from framework JSF. as against the colleague friend in framework Struts, he not full configuration inputs for navigation rules, will like also to JavaBean that be identified by framework.

Framework JSF doesn't decide to return every class or component developers is obligated to accustomed to describe every class implementation business logic from application. Any way, in Faces be wanted to has class that will keep UI status component in every page. This class called backing those elements Model.

This class not class when looked at carefully under perspective from Model architecture 2. Any way, when only think UI components, the mentioned can be understood to call class these part from Model, especially if we are to compare it with MVC implementation from component class UI Swing. Remember, in Swing that is rendering layer called View, component status Model and action handler part Controller.

Although they are called part from Model, several things necessary be payed that must be taken in developments from this class like them must not influence kernel function from your application (actually Model). Very good to remember that these components meants to keep status for UI component and may be explain operation base that accessing data stored where can act as method application. They are not meant to do heavy process or every process absolutely that can be used to return in other application.
Make a backing Model for containing page UI JSF component very easy. Same the easy like to make a JavaBean with properties that every component in a page. In this case, they are similar to object actionform in framework Struts, with exception that is them unnecessary to extended every class base that provided by framework.


Thursday, October 22, 2009

up to in this time, web application follows architecture channel next: one of the manner in represent new content(for example, in responsive interaction between user with page in application) done by send request to server and display new page in user. found technology client eunuch scripting (javascript, vbscript, and as it) give description in user that them open new content with a click in button. but, scripting technology only can modify content found on a page; technology also only can work towards information that sent in client.
various solution has been made previous, aim to change existing paradigm, but several between has commercial (has a solution only functioned with internet explorer), difficult to programminged, and can not be accessinged easily.
then present AJAX as the completion.


resemble J2EE, AJAX 2 matters that united: be a technology, all at once programming arsitecture.

AJAX as a technology

AJAX abbreviation from “Asynchronous Javascript and XML”, made from technology series with various ability: Javascript, XML and a asinkron method communication between client and server.
3 technologies interact: javascript get hint, movement with action. as in situation that may be happen,Javascript use communication stripe in server (javascript object by the name of XMLHttpRequest.) to call method stored in server and use xml as data delivery mechanism. if Javascript in client get response from server, so javascript will use the load ability to will manipulate DOM structure page to will add content that got from server. change that in structure dom then translated by browser in client, so that increase interactivity effect in user.

AJAX as a architecture

initially AJAX made as a series from technology, but then AJAX development experience. for example, web application existence doesn't use xml in data transfer from client to server. manner done by using object XMLHttpRequest.
based on above realita, several sides defines as new paradigm in programming, beside technology that functionality ready. let us study more deepen about AJAX architecture.
developers has developed web programming before present it AJAX: action from user that need data from server displayeds in page that used, where is data request from user sent to aim server. after cultivate page, server displays new page for user that contains result from previous process.
The problem from architecture kind slow and enough consume time, especially when compared with desktop application. desktop application can to responsive fast on request from user, this application will not processed to repeat every interfaces component that will displayed as response.
AJAX use programming architecture in web application. than give a full page in server and get also a full page as operation result, AJAX admit us to send request in size smaller in server. used page only modification to displays result, is not replaced with a new page.
another important factor from AJAX architecture request and response run according to asinkron: AJAX doesn't user prohibit to do process other on page that worn. user can fill and use area other on page, while AJAX put hand to background.
last, AJAX admit user for interacted with server as response towards entire matters that done by user. existing architecture only admits us to communicate with server at the (time) of user buttons or link that will send data on page. AJAX permit to request new data from server in the form of mouseovers, keypress and even other that identified by javascript.

process that done by AJAX

let us look at real example that shows to how AJAX enrich user interactivity and how do we use it in application.

example above simple example from form registration. but here found a troubleshoot, not all users detects number of the zip code.

JAVA Language Identification

Wednesday, October 21, 2009


In this chapter be discussed in a word about JAVA history and JAVA technology definition. This chapter also a little will touch about phases in JAVA program.
By the end of discussion, the reader supposed can:
1. Explain Features technology from JAVA cover JAVA Virtual Machine (JVM), garbage collection, and security code.
2. Explain phase difference in JAVA programming

JAVA Background

JAVA Short History

in 1991, a SUN engineer group led by Patrick Naughton and James Gosling want to design computer language for ware consumer like cable television box. Because ware doesn't has many memories, language must little measure and contain tough code. Also because manufacturing differ choose processor different also, so language must free from manufacturing whatever. Project is given code name ”Green”.
Need for flexibility, little, tough and neutral code towards platform delivers team studies implementation pascal ever tried. Niklaus Wirth, language creator pascal design language portable that produce intermediate code for hypothesis engine. This engine often is called mechanically illusion (Virtual Machine). This code then can be used at just any engine that has interpreter. Project Green use illusion engine to overcome principal rumors about neutral towards engine architecture.
Because the person at Green project based on C++ and not pascal so majority sintaxs taken from C++, with adopted object orientation and not prosedural. Language the beginning that created given name ”Oak” by James Gosling that get inspiration from a tree that present in across the office, but caused by name Oak self be programming language name that preexist, then SUN to replaced it with JAVA. JAVA name self inspiration at the (time) of they are enjoying a coffee cup at a cafe then intuitively one of them is mentioning word JAVA that meaningful coffee ore origin. Final they are unanimous to give programming language name by the name of JAVA.
first Project product Green Star 7 (7), a long distance rein very intelligent. caused by market still not yet interested with product consumer intelligent so project Green must find market other from technology that created. At the (time) of same, implementation WWW and internet is experiencing fast development. On the other hand, member from project Green also realize that JAVA can be used in internet programming, so that applications furthermore aim to be technology that impersonate at web.

JAVA give accomodations almost entire Features important language - existing programming language since human modern computation development:
1. From SIMULA, language in the year 1965, language most influence JAVA all at once C++. From this language is adopted forms base from programming object orientation.
2. From LISP - language year 1955, adopted facilities garbage collection, with ability to imitate generic list processing, although this facilities is seldom that make use it.
3. From Algol - language in the year 1960, taken rein has structure.
4. From C++, adopted sintaks, a part semantiks and exception handling
5. From there language, taken strongly type, and exception handling.
6. From Objective c, taken interfaces facilities.
7. From SmallTalk language, taken to approach single-root class hiƩrarchie, where does object one inheritance hierarchy unitary
8. From eiffel language, facilities assertion that begin to applied in this part of JDK 1.4

What that is technology JAVA?

A programming language
As a programming language, JAVA can make entire application forms, desktop, web and another, as made by using conventional programming language.
JAVA programming language object orientation (OOP) and can be run in various platform operating system. Development JAVA not only focus in one operating system, but developed to various operating system and has open source.

A development ENVIRONMENT
As a builder device, JAVA technology prepare many tools: compiler, interpreter, documentation composers, class package and as it.

A application
Application with JAVA technology in general application serbt a to that can be run in entire engines that has JAVA RUNTIME ENVIRONMENT (JRE).

A deployment ENVIRONMENT
Found two principal components from deployment ENVIRONMENT. First JRE, found on J2SDK package, contain classes for all JAVA package technology that cover class base from JAVA, GUI component and as it. Other component found in browser web. Almost entire commercial browser webs prepares interpreter and RUNTIME ENVIRONMENT from JAVA technology.

why study JAVA?
Based on white paper official from SUN, JAVA has characteristics next:
1. Simple
JAVA language Programming use sintaks resemble with C++ but sintaks in JAVA many repaired especially cause the loss of complex pointer use and multiple inheritance. JAVA also use automatic memory allocation and memory garbage collection.
2. Object oriented
JAVA use programming object oriented that make program can be made according to modular and can be used to return. Programming object oriented memodel real world intoes object and do interaction delivers objects.
3. Distributed
JAVA made to make application distributings easyly with existence libraries networking integration in JAVA.
4. Interpreted
JAVA program run to use interpreter that is JAVA Virtual Machine (JVM). this matter has caused source code JAVA that compilation be JAVA bytecodes can be run in platform that various.
5. Robust
JAVA has reliability tall. Compiler in JAVA has ability detects error according to carefuler compared programming language other. JAVA has RUNTIME-exception handling to help to overcome error in programming.
6. Secure
As programming language for internet application and distributing, JAVA has several security mechanisms to watch over application is not used to botch computer system that run application.
7. Architecture Neutral
JAVA Program be platform independent. Program enough has one version that can be run in platform differ from Java Virtual Machine.
8. Portable
Source code also JAVA program can easily be brought to platform that vary without having to compilation repeat.
9. Performance
Performance in JAVA often said less tall. But performance JAVA can be increased to use compilation JAVA other like product inprise, microsoft and or symantec that use just in time compilers (JIT).
10. Multithreaded
JAVA has ability to make a program that can do several jobs according to all at once and simultaneous.
11. Dynamic
JAVA design to can be run in dinamic ENVIRONMENT. change at one particular class with add properties and or method can be done without harry program that use class.

A part Features from JAVA

Java Virtual Machine (JVM)
JVM a imaginary engine (illusion) that with resembles application in a real engine. JVM prepare spesification hardware and platform where does code compilation JAVA happen. This spesification makes application based on JAVA be to free from whatever platform because compilation process is finished by JVM.
JAVA program application created with text file extension .java. This program is compilation produces one bundle bytecode extension. class or more. Bytecode series engine code instruction similar instruction. The difference engine code must be run in where must compilation be must be attributed, temporary bytecode walk in JAVA interpreter available at all platform computer system and operating system.

Garbage collection

Many languages programming other that admit a programer allocate memory at the (time) of run. But, after use memory allocation, must found manner to laid to return memory block so that program other can use it. In C, C++ and another language, programmer absolute will responsible of this thing. This matter can difficult when programmer beglect to return memory block so that causes situation that be be known by the name of memory leaks.
program JAVA do garbage collection that mean unnecessary program wipes off self object - object is not used again. this facilities decreases memory management load by programmer and decrease or eliminate biggest error source found on language that makes dinamic allocation.

Code security

Code security implementation in JAVA pass use JAVA RUNTIME ENVIRONMENT (JRE). JAVA use pacification model 3 layers to protect system from untrusted JAVA code.
1. First, class-loader handle class loading JAVA to RUNTIME interpreter. This process prepares pacification with separate classes that come from local disk with classes that taken from network. This matter limits trojan application because classes that come from local disk that held beforehand.
2. Second, bytecode verifier read bytecode before run and guarantee bytecode fulfil rules JAVA language base.
3. Third, security management handles application level security with restrain to what program justifiably accessing resource likes file system, port network, external process and windowing system.

After entire process finished run, then program code at execution.
JAVA also prepare various pacification technique other:
1. Language designeds to complicate vandal code execution. pointer begation is pacification big step. JAVA do not know pointer operation. On-hand expert programmer, pointer operation is remarkable matter to optimasi and efficient program maker with astonishing. But this fashion can be disaster before programmer wicked. Pointer is tool incredible to access not otoritation. With pointer operation begation, JAVA can be language more safe.
2. JAVA has several passwords towards applet. To prevent program acts to disturb storage media, so applet is not permitted to do open, read and or write towards bundle according to just any. Because JAVA applet can open new window browser, so has logo JAVA and identification text towards window that opened. This matter prevents window pop-up cheat as enquiry username and password.

phases of JAVA programming
This under picture explain compilation process current and execution a JAVA program:

first step in maker a program based on JAVA inscribes program code in text editor. Example text editor that can be used among others: notepad, vi, emacs and other as it. Program code that made then stored in a bundle extension. java.
After make and keep program code, program code containing file compilation by using JAVA compiler. result from shaped bundle bytecode with extension. class.
bundle that contain bytecode then conversion by JAVA interpreter will be engine language as according to kind and platform that used.

know java

Tuesday, October 20, 2009

This beginning part will invite you to will know bearer
programming language Java. Specialer again, we explorer
fundamental components necessary once
known and understood well. Besides, this part also
lengten marginally about fitur new Java version 5.0
and 6. Supposed this explanation later can help to make easy
you when want to uncover secrets Java furthermore.

In a flash Java
of course you are old stuff by the name of Java, a language
programming orientation object that developed by SUN
microsystems. At this beginning part, we shall lengten about in a flash
Java that reviewed from development environment aspect and
product. Supposed this review later can clarify terminology
and or statements often time stump,
especially for bew knows Java.

• Development environment
in discuss Java, presumably so important to distinguish
between programming language Java, Java virtual machine,
and platform Java. Programming language Java language
used to produce applications Java. In general,
only define sintaks programming language and behaviour
At the (time) of program Java compile, he convertion to form
bytecode, be engine language portable. Furthermore,
bytecode run at Java virtual machine (or
called Java vm or JVM). Although JVM can implement
direct at hardware, but usually implementation
in the form of software program emulation engine
(computer) and used to menginterpretasi bytecode.
Platform can be defined as supporter software
for certain activities. Platform Java self in principle
differ from language Java or JVM. Platform Java
classes collection Java that defined previous
and eksis since installation Java. Platform Java also threaten in
environment runtime or fire (application programming interfaces)

• Java edition

to include different application environments, SUN
define 3 (three) editions Java.
• j2me (Java 2 micro edition)
this edition is attributed for environment with limited resource,
like smartcard, handphone, and pda.
• j2se (Java 2 standards edition)
this edition is attributed for environment workstation, like maker
applications dekstop.
• j2ee (Java 2 enterprise edition)
this edition is attributed for internet environment or application distributings
in big scale.

difference every edition covers fitur language that supported and
fire available. based on the stage, edition higher
can mengemulasi lower edition. as to sequence
edition from highest to low j2ee, j2se, and j2me.
• Java version
there piquancy and necessary we are accurate hit versions
Java that merilis. SUN to use two version kinds to
identify rilis Java, that is product version and version developer.
As we know, newest version in this time version 6 (versions
product) or version 1.6.0 (version developer), by the name of code mustang.
Since year 2006, SUN also simplified nomenclature platform
as a mean to reflect maturity level, stability,
skalabilitas, and security better. if previous version nomenclature
Java 2 platform, standards edition 5.0 (j2se 5.0),
so now being simplified to be Java platform, standards
edition 6 (Java se 6, or a more regular is called Java 6).

Server Web Apache, PHP and MySQL

Monday, October 19, 2009

Server Web Apache
principal task apache produces true web page
to client demander, based on PHP code that inscribed by
web page maker. If need, also based on PHP code
inscribed, so can a database be be accessinged particularly
formerly (for example in MySQL) to support web page contents
Apache bloom since the first version. This, author
use apache version 2.0.54. apache has open source,
mean everyone may use it freely. Even
also may take everyone and change apache code

PHP abbreviation from PHP: Hypertext Preprocessor. PHP
be programming language to make web has
server-side scripting. PHP make possible you to make
web page has dinamic.
PHP can be run in assorted system operations, for example
windows, LINUX, and Mac OS. Besides apache, PHP also support
several server webs other, microsoft for example IIS, caudium, PWS, and
Like ever be touched previous that PHP can make use database to produce dinamic web page.
Database management system often used with PHP
MySQL. But, PHP also support management system
database oracle, microsoft access, interbase, dbase, postgresql, and
Up to now, PHP bloom up to version 5. PHP 5 support
full object-oriented programming (OOP), integration xml,
support all newest extensions MySQL, web development
services with SOAP and REST, with hundreds enhanced other
compared previous version.
PHP has also open source so that everyone can use it freely.

MySQL a database management system has open
source. MySQL congenial pair from PHP. MySQL made and
developed by MySQL ab that correlating in Sweden.
MySQL can be used to make and managed database
along with its contents. You can make use MySQL to add, change, and wipe off data that reside in database. MySQL be database management system has relasional.
Will mean datas that managed in database mele -
not in several tables apart so that data manipulation
will be quicker.
MySQL can be used to managed database begin from
little up to very big. MySQL also can run
commands structured query language (SQL) to
managed databases relasional exist in depth.
Up to now, MySQL bloom up to version 5. MySQL 5
support trigger to make easy table management in

Microcontroller aplikasi dengan Basic Stamp

Tuesday, October 13, 2009

Microcontroller aplikasi dengan Basic Stamp, PIC, 8.051 dan berbagai orang lain seringkali dapat ditingkatkan dengan penggunaan PC port serial, dan antarmuka perangkat lunak. Merancang antarmuka kustom Anda sendiri perangkat lunak untuk aplikasi mikrokontroler berikutnya tidak sesulit yang Anda bayangkan.

Menggunakan port serial PC untuk interface ke dunia luar, dan aplikasi mikrokontroler berikutnya, dapat memberi Anda beberapa software yang sangat kuat / hardware solusi.

Seri artikel oleh Jared Hoylman akan memandu Anda melalui beberapa konsep dasar, dan kemudian beralih ke daerah yang lebih maju untuk berkomunikasi dengan hardware anda, dan memiliki perangkat keras Anda berkomunikasi kembali ke PC.


* Option Explicit
* DataTypes
* Parsing Strings
* Advanced Parsing
* Mengirim data dari PC ke Microcontroller
* Menerima Data From The Microcontroller

Memahami dan Menggunakan Visual Basic Bagian 1

Menjadi seorang programmer VB ada banyak hal yang saya mengambil selama beberapa tahun yang sangat meningkatkan program saya dan kemampuan pemrograman. Dalam seri artikel ini saya akan membahas beberapa dasar-dasar pemrograman VB dan beberapa Tips dan Trik untuk memudahkan Anda di sepanjang jalan. Artikel seri ini akan mulai dengan keterampilan dasar yang diperlukan dan bekerja itu naik ke topik-topik lanjutan seperti mengirim dan menerima data dari Basic Stamp atau PIC Microchip ..!

Option Explicit
Saya yakin banyak dari Anda telah melihat kata-kata Option Explicit pada bagian atas beberapa kode VB sebelumnya. Mengapa di sana, dan apa fungsinya ..? Well, pernyataan Option Explicit memaksa Anda untuk mendeklarasikan variabel Anda sebelum Anda menggunakannya. Hingar-t-do, benar ..? Salah ..! Kedua kata sederhana dapat menghemat jam sakit kepala debugging program-program anda ..! Dapat juga mempercepat program Anda cukup jika digunakan dengan benar ..!

Dengan menempatkan Option Explicit pada bagian atas setiap kode modul sebelum prosedur Anda dapat menjamin bahwa Anda tidak akan misspell setiap variabel. Mari kita lihat sebuah contoh ...

Private Sub Command1_Click()
Dim sMississippi As String
sMississipi = "Hello" '<-- Note the missing "p"
MsgBox sMississippi
End Sub

Apa kode ini sebenarnya harus dilakukan adalah menampilkan sebuah MessageBox dengan sapaan "Halo". Karena variabel salah eja dan tidak ada Option Explicit pada bagian atas kode modul, Anda mendapatkan MessageBox kosong ..!

Sekarang, masuklah ke bagian paling atas kode modul dan ketik kata-kata Option Explicit. Jalankan program lagi. Apa yang terjadi ..? Anda mendapatkan "Variabel tidak didefinisikan" error. Ini adalah sederhana untuk memperbaiki apa yang bisa menjadi masalah yang kompleks.

Alasan lain bahwa Option Explicit begitu penting adalah karena jika Anda tidak mendeklarasikan variabel sebagai tipe data tertentu, VB default variabel menjadi tipe Variant (Lihat jenis data yang dijelaskan dalam artikel berikutnya). Sebuah variabel tipe Variant apapun dapat menahan data dari string, untuk bilangan bulat, bilangan bulat panjang, untuk tanggal, mata uang, dsb Meskipun ini mungkin terdengar seperti variabel paling baik untuk digunakan, tidak. Ini adalah jenis variabel paling lambat ..! Dengan mendefinisikan variabel khusus untuk jenis nilai yang akan disimpan di dalamnya, akan sangat meningkatkan kinerja program-program anda.

Dan untuk membuatnya bahkan lebih mudah, bagaimana kalau saya akan menunjukkan bagaimana membuat VB Option Explicit secara otomatis menambahkan kode untuk setiap modul ..! It's easy.

Klik pada menu Tools dan pilih Options ... Sekarang periksa Mengharuskan Deklarasi Variabel Klik OK

Sekarang setiap kali Anda membuka modul kode baru Option Explicit kata-kata itu secara otomatis muncul di bagian atas ..!

Memahami dan Menggunakan Visual Basic Part 2

Memahami dan Mengoptimalkan Tipe Data
Dalam Visual Basic 6 terdapat 11 tipe data yang berbeda. Ini adalah Boolean, Byte, Currency, Date, Double, Integer, Long, Object, Single, String, dan Variant. Mereka masing-masing memiliki tujuan tertentu dan menggunakan mereka dengan benar akan meningkatkan kinerja program-program anda. Aku akan menutupi tipe data yang paling sering digunakan.

• Boolean
Jenis data yang Boolean hanya memiliki dua statement, Benar dan Salah. Tipe variabel ini disimpan sebagai 16-bit (2 Byte) angka, dan biasanya digunakan untuk bendera. Sebagai contoh, katakanlah Anda memiliki sebuah textbox (text1) dan perintah tombol (Command1). Anda hanya ingin menjadi Command1 Diaktifkan bila ada teks dalam text1. Anda akan melakukan hal seperti ini ...

Private Sub Form_Load()
Command1.Enabled = False ' Disables Command1
Text1.Text = vbNullString ' Sets Text1=""
End Sub

Private Sub Text1_Change()
Dim bEnable As Boolean
If Text1.Text <> "" Then bEnable = True
Command1.Enabled = bEnable
End Sub

Jalankan program dan Command1 hanya akan diaktifkan bila ada teks diketik ke dalam text1.

• Byte
Jenis data yang Byte adalah 8-bit variabel yang dapat menyimpan nilai antara 0 hingga 255. Tipe data ini sangat berguna untuk menyimpan data biner. Ini dapat juga sangat berguna bila mengirim / menerima nilai byte ke / dari Basic Stamp atau PIC.

• Double
Double tipe data adalah 64-bit floating point number digunakan bila diperlukan akurasi tinggi. Variabel ini dapat berkisar dari-1.79769313486232e308 ke-4.94065645841247e-324 untuk nilai negatif dan dari 4.94065645841247e-324 untuk 1.79769313486232e308 untuk nilai-nilai positif.

• Integer
Para tipe data Integer adalah 16-bit yang bisa berkisar dari -32.768 ke 32767. Bilangan bulat harus digunakan bila Anda bekerja dengan nilai-nilai yang tidak dapat berisi angka pecahan.

• Panjang
Tipe data Long adalah 32-bit yang bisa berkisar dari -2147483648 ke 2147483647. Panjang variabel hanya dapat berisi non-pecahan nilai-nilai integer. Saya sendiri menggunakan variabel yang panjang lebih dari Bilangan bulat untuk meningkatkan kinerja. Sebagian besar fungsi Win32 menggunakan tipe data ini untuk alasan ini.

• Single
Single tipe data adalah 32-bit mulai dari-3.402823e38 ke-1.401298e-45 untuk nilai negatif dan dari 1.401298e-45 untuk 3.402823e38 untuk nilai-nilai positif. Ketika Anda membutuhkan angka-angka pecahan dalam kisaran ini, ini adalah tipe data yang akan digunakan.

• String
String jenis data yang biasanya digunakan sebagai variabel-variabel jenis panjang. Variabel string panjang dapat berisi sampai kira-kira 2 milyar karakter. Masing-masing karakter memiliki nilai berkisar antara 0-255 didasarkan pada set karakter ASCII. String digunakan ketika Teks yang terlibat.

Puting All Of This Teknis Stuff To Use
Hanya untuk menunjukkan kepada Anda bagaimana menggunakan tipe data ini, di sini adalah contoh kecil. Katakanlah kita punya String berisi teks, "Ini adalah hal VB pretty darn cool ..!", dan kami ingin mengkonversi setiap huruf ke ASCII itu setara. Kami akan menampilkan setiap huruf bersama dengan ASCII yang setara dalam sebuah MessageBox satu per satu waktu.

Private Sub Command1_Click()
Dim sText As String
Dim lTextLength As Long
Dim sChar As String
Dim bASCII As Byte
Dim x As Long

sText = "This VB stuff is pretty darn cool..!"
lTextLength = Len(sText) 'Gets # of chars in sText

For x = 1 To lTextLength 'Loop through string one char at a time
sChar = Mid$(sText, x, 1)'Gets the x'th charcter in sText
bASCII = Asc(sChar) 'Gets ASCII value of character
MsgBox "The ASCII value of '" & sChar & "' is " & bASCII 'Display results
Next x

End Sub