Explanation of AJAX

Your Ad Here

How Does Ajax Work?

With Ajax, Web applications finally start feeling like desktop applications to your users. That’s because Ajax enables your Web applications to work behind the scenes, getting data as they need it, and displaying that data as you want. And as more and more people get fast Internet connections, working behind the scenes to access data is going to become all the rage. Soon,

it’ll be impossible to distinguish dedicated desktop software from software that’s actually on the Internet, far from the user’s machine. To help you understand how Ajax works, the following sections look at Ajax from a user’s and a programmer’s perspective.



A user’s perspective

To show you how Ajax makes Web applications more like desktop applications, I’ll use a simple Web search as an example. When you open a typical search engine, you see a text box where you type a search term. So say you type Ajax XML because you’re trying to figure out what XML has to do with Ajax. Then, you click a Search the Web button to start the search. After that, the browser flickers, and a new page is loaded with your search results.


A developer’s perspective

In the article "Ajax: A New Approach to Web Applications" (www.adaptivepath.com/publications/essays/archives/000385.php), Jesse James Garrett, who was the first to call this technology Ajax, made important insights about how it could change the Web. He noted that although innovative

new projects are typically online, Web programmers still feel that the rich capabilities of desktop software were out of their reach. But Ajax is closing the gap.

So how does Ajax do its stuff? The name Ajax is short for Asynchronous JavaScript and XML, and it’s made up of several components:

Browser-based presentation using HTML and Cascading Style Sheets (CSS).

- Data stored in XML format and fetched from the server

- Behind-the-scenes data fetches using XMLHttpRequest objects in the browser

- JavaScript to make everything happen

JavaScript is the scripting language that nearly all browsers support, which will let you fetch data behind the scenes, and XML is the popular language that lets you store data in an easy format.


Here’s an overview of how Ajax works:


1. In the browser, you write code in JavaScript that can fetch data from the server as needed.

2. When more data is needed from the server, the JavaScript uses a special item supported by browsers, the XMLHttpRequest object, to send a request to the server behind the scenes — without causing a page refresh.

The JavaScript in the browser doesn’t have to stop everything to wait for that data to come back from the server. It can wait for the data in the background and spring into action when the data does appear (that’s called asynchronous data retrieval).

3. The data that comes back from the server can be XML, or just plain text if you prefer. The JavaScript code in the browser can read that data and put it to work immediately. That’s how Ajax works — it uses JavaScript in the browser and the XMLHttpRequest object to communicate with the server without page refreshes, and handles the XML (or other text) data sent back from the server. I explain how all these components work together in more detail.


This also points out what you’ll need to develop Web pages with Ajax. You’ll add JavaScript code to your Web page to fetch data from the server, and you’ll need to store data and possibly write server-side code to interact with the browser behind the scenes. In other words, you’re going to need access to an online server where you can store the data that you will fetch using Ajax. Besides just storing data on the

server, you might want to put code on the server that your JavaScript can interact with. For example, a popular server-side language is PHP, and many of the examples in this book show how you can connect to PHP scripts on Web servers by using Ajax. Getting you up to speed on that language if you’re interested. So you’re going to need a Web

server to store your data on, and if you want to run server-side programs as well, your server has to support server-side coding for the language you want to work with (such as PHP).


Read More - Explanation of AJAX

ListView Dalam VisualBasic

Your Ad Here

ListView dalam Visual Basic biasanya digunakan untuk menampilkan data, baik dari database maupun bukan, ke dalam tabel dalam bentuk list atau grid. Dengan ListView, data yang ada dapat diurutkan, ditambahkan maupun dihapus dengan mudah dari list.


Menambahkan ListView

Untuk menambahkan ListViewke dalam form (project), cari tool yang bernama listview pada toolbox. Jika komponen tersebut belum ada di toolbox, maka Anda harus menambahkan / mengaktifkan komponen Microsoft Common Controls. Klik kanan pada toolbox dan pilih sub menu Components… Lihat gambar berikut ini :


ListView Dalam VisualBasic

Mengatur Header ListView

Untuk mengatur ListViewListView, perhatikan contoh berikut ini :


.. .. ..
Dim ch As ColumnHeader
Set ch = ListView1.ColumnHeaders.Add(, , "No.", 600)
Set ch = ListView1.ColumnHeaders.Add(, , "Kode", 900, vbCenter)
Set ch = ListView1.ColumnHeaders.Add(, , "Nama Barang", 2300,
vbLeftJustify)
Set ch = ListView1.ColumnHeaders.Add(, , "Byk", 900, vbCenter)
Set ch = ListView1.ColumnHeaders.Add(, , "Harga Satuan", 1500,
vbRightJustify)
Set ch = ListView1.ColumnHeaders.Add(, , "Jumlah", 1580,
vbRightJustify)
ListView1.GridLines = True
.. .. ..


Program di atas akan mengatur header ListView menjadi 7 kolom, yaitu kolom No, Kode, Nama Barang, Byk, Harga Satuan dan Jumlah. kamujuga dapat mengatur perataan dan lebar masing-masing kolom. Tampilan ListView yang dihasilkan dari program di atas kurang lebih sebagai berikut :


ListView Dalam VisualBasic

Menambahkan Record (Item) ke dalam ListView

Untuk menambahkan Record (Item) ke dalam ListView , perhatikan contoh sebagai berikut :


.. .. ..
Dim lv As ListItem
Set lv = lsttampil.ListItems.Add(, , 1)
lv.SubItems(1) = "B001"
lv.SubItems(2) = "Buku Tulis"
lv.SubItems(3) = "30"
lv.SubItems(4) = "2100"
lv.SubItems(5) = "63000"
.. .. ..

Program di atas akan menambahkan sebuah record (item) baru ke dalam ListView. Tampilan ListViewkurang lebih menjadi sebagai berikut :


ListView Dalam VisualBasic

Ok Segitu dulu penjelasannya, semoga bermanfaat...
Jangan Lupa Comment ya

Read More - ListView Dalam VisualBasic

Creating Mailing list Application

Your Ad Here

In this time I will show, how to make a simple mailing list application with VB. The application allows the entry of information (names and addresses) to build a mailing list. An added feature is a timer that keeps track of the time spent entering addresses. After each entry, rather than write the information to a database (as we would normally do), the input information is simply displayed in a Visual Basic message box. We present this example to illustrate the steps in building an application. If you feel comfortable building this application and understanding the corresponding code, you probably possess the Visual Basic skills needed to proceed with this course.


1. Start a new project. Place two frames on the form (one for entry of address information and one for the timing function). In the first frame, place five labels, five text boxes, and two command buttons. In the second frame, place a label control, a timer control and three command buttons. Remember you need to ‘draw’ controls into frames. Resize and position controls so your form resembles this:


2. Set properties for the form and controls (these are just suggestions – make any changes you might like):

Form1:
Name frmMailingList
BorderStyle 1-Fixed Single
Caption Mailing List Application


Frame1:
Name fraMail
Caption Address Information
Enabled False

Label1:
Caption Name

Label2:
Caption Address

Label3:
Caption City

Label4:
Caption State

Label5:
Caption Zip

Text1:
Name txtInput
Index 0 (a control array)
TabIndex 1
Text [blank it out]

Text2:
Name txtInput
Index 1
TabIndex 2
Text [blank it out]

Text3:
Name txtInput
Index 2
TabIndex 3
Text [blank it out]

Text4:
Name txtInput
Index 3
TabIndex 4
Text [blank it out]


Text5:
Name txtInput
Index 4
TabIndex 5
Text [blank it out]

Command1:
Name cmdAccept
Caption &Accept
TabIndex 6

Command2:
Name cmdClear
Caption &Clear

Frame1:
Name fraTime
Caption Elapsed Time

Label6:
Name lblElapsedTime
Alignment 2-Center
Backcolor White
BorderStyle 1-Fixed Single
Caption 00:00:00
FontBold True
FontSize 14

Timer1:
Name timSeconds
Enabled False
Interval 1000

Command3:
Name cmdStart
Caption &Start

Command4:
Name cmdPause
Caption &Pause
Enabled False


Command5:
Name cmdExit
Caption E&xit

When done, the form application should appear something like this:



3. Put these lines in the General Declarations area of the code window:

Option Explicit
Dim ElapsedTime As Variant
Dim LastNow As Variant


4. Put these lines in the Form_Load event procedure:

Private Sub Form_Load()
ElapsedTime = 0
End Sub


5. Put this code in the txtInput_KeyPress event procedure:

Private Sub txtInput_KeyPress(Index As Integer, KeyAscii As Integer)
'Check for return key
If KeyAscii = vbKeyReturn Then
If Index = 4 Then
cmdAccept.SetFocus
Else
txtInput(Index + 1).SetFocus
End If
End If
'In Zip text box, make sure only numbers or backspace pressed
If Index = 4 Then
If (KeyAscii >= Asc("0") And KeyAscii <= Asc("9")) Or KeyAscii = vbKeyBack Then Exit Sub Else KeyAscii = 0 End If End If End Sub

Note the line beginning with ‘If (KeyAscii >= Asc(“0”) And ...’ is so long that the word processor wraps the line around at the margin. Type this as one long line, not two separate lines or review the use of the Visual Basic line continuation character (_). Be aware this happens quite often in these notes when actual code is being presented.
.



6. Put this code in the cmdAccept_Click event procedure:

Private Sub cmdAccept_Click()
Dim S As String, I As Integer
'Accept button clicked - form label and output in message box
'Make sure each text box has entry
For I = 0 To 4
If txtInput(I).Text = "" Then
MsgBox "Each box must have an entry!", vbInformation + vbOKOnly, "Error"
Exit Sub
End If
Next I
S = txtInput(0).Text + vbCrLf + txtInput(1).Text + vbCrLf
S = S + txtInput(2).Text + ", " + txtInput(3).Text + " " + txtInput(4).Text
MsgBox S, vbOKOnly, "Mailing Label"
Call cmdClear_Click
End Sub


7. Put this code in the cmdClear_Click event procedure:

Private Sub cmdClear_Click()
Dim I As Integer
'Clear all text boxes
For I = 0 To 4
txtInput(I).Text = ""
Next I
txtInput(0).SetFocus
End Sub


8. Put this code in the cmdStart_Click event procedure:

Private Sub cmdStart_Click()
'Start button clicked
'Disable start and exit buttons
'Enabled pause button
cmdStart.Enabled = False
cmdExit.Enabled = False
cmdPause.Enabled = True
'Establish start time and start timer control
LastNow = Now
timSeconds.Enabled = True
'Enable mailing list frame
fraMail.Enabled = True
txtInput(0).SetFocus
End Sub


9. Put this code in the cmdPause_Click event procedure:

Private Sub cmdPause_Click()
'Pause button clicked
'Disable pause button
'Enabled start and exit buttons
cmdPause.Enabled = False
cmdStart.Enabled = True
cmdExit.Enabled = True
'Stop timer
timSeconds.Enabled = False
'Disable editing frame
fraMail.Enabled = False
End Sub


10. Put this code in the cmdExit_Click event procedure:

Private Sub cmdExit_Click()
'Exit button clicked
End
End Sub


11. Put this code in the timSeconds_Timer event procedure:

Private Sub timSeconds_Timer()
'Increase elapsed time and display
ElapsedTime = ElapsedTime + Now - LastNow
lblElapsedTime.Caption = Format(ElapsedTime, "hh:mm:ss")
LastNow = Now
End Sub


12. Save the application. Run the application. Make sure it functions as designed. Note that you cannot enter mailing list information unless the timer is running.


Read More - Creating Mailing list Application