Pages

Sunday, January 23, 2011

Menentukan Nama Hari Menggunakan DateTimePicker

Jika Anda menggunakan DateTimePicker dan ingin mengetahui apakah pada tanggal tertentu merupakan hari tertentu (misalnya hari Minggu), kita dapat menggunakan DayOfWeek. Berikut ini adalah sepenggal syntax-nya:

If DateTimePicker1.Value.DayOfWeek = 0 Then
   MessageBox.Show("Hari ini adalah hari Minggu.")
Else
   MessageBox.Show("Hari ini bukan hari Minggu tetapi hari " + DateTimePicker1.Value.DayOfWeek.ToString)
End If


Keterangan:
DayOfWeek menggunakan angka integer untuk menentukan nama hari dimulai dari 0 yang menunjukkan hari Minggu sampai dengan 6 untuk hari Sabtu.

Tuesday, January 4, 2011

Pembulatan Angka pada VB Net

Jika Anda ingin membulatkan hasil dari perhitungan menjadi berapa desimal di belakang koma gunakan fungsi Round pada VB Net.

Imports System.Math
Dim Hasil as Decimal = Round(nilai, digit)

Keterangan:
Pertama kali Anda harus mengimpor komponen yang diperlukan agar fungsi Round dapat berjalan, yaitu System.Math
Nilai berisi angka yang ingin dilakukan pembulatan sedangkan Digit berisi berapa digit angka di belakang koma yang diinginkan.

Membaca Data pada Record Terakhir dari Database

Seringkali banyak yang menanyakan bagaimana caranya jika ingin membaca data pada record terakhir dari database. Saya menemukan salah satu solusinya jika Anda menggunakan perintah ExecuteReader untuk membaca data pada database.
Berikut ini adalah sepenggal syntax-nya:

dr = cmd.ExecuteReader
Do while dr.read
   Dim nama as string = dr!Nama
   Dim alamat as string = dr!Alamat
Loop
TxtNama.Text = nama
TxtAlamat.Text = alamat
dr.Close()

Penjelasan:
Program akan membaca data nama dan alamat pada record yang telah ditemukan sesuai dengan perintah SQL. Data nama dan alamat akan dideklarasikan ke dalam variabel nama dan alamat. Pada akhir dari proses looping variabel nama dan alamat hanya akan berisi data nama dan alamat yang terdapat pada record terakhir dari database dengan asumsi bahwa semua record sudah tersusun secara ascending.

Perintah SQL TOP
Cara lain untuk menuju ke record terakhir adalah menggunakan perintal SQL TOP.
Berikut ini contoh syntax perintah SQL:

SELECT TOP 1 * FROM STOK WHERE KODE_BARANG = '001' ORDER BY TANGGAL DESC

Penjelasan:
Query akan menampilkan semua field dari 1 record paling atas pada tabel Stok yang memiliki Kode_Barang '001' dimana record tersusun secara descending berdasarkan Tanggal sehingga record terakhir berada pada urutan atas.

Thursday, December 16, 2010

Connection String for SQL Server 2008

.NET Framework Data Provider for SQL Server
Type:    .NET Framework Class Library
Usage:  System.Data.SqlClient.SqlConnection

#Standard Security

Data Source=myServerAddress;Initial Catalog=myDataBase;UserId=myUsername;Password=myPassword;

Use serverName\instanceName as Data Source to connect to a specific SQL Server instance. Are you using SQL Server 2008 Express? Don't miss the server name syntax Servername\SQLEXPRESS where you substitute Servername with the name of the computer where the SQL Server Express installation resides.

#Connect via an IP address

Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;

DBMSSOCN=TCP/IP. This is how to use TCP/IP instead of Named Pipes. At the end of the Data Source is the port to use. 1433 is the default port for SQL Server.

Sumber: http://www.connectionstrings.com

Friday, December 3, 2010

Membandingkan Selisih Nilai pada DataGridView

Ilustrasi Tabel Nilai


Ilustrasi Tabel Hasil

Diilustrasikan terdapat sebuah tabel yang akan kita hitung selisih perbandingan dari masing-masing entitas berdasarkan masing-masing kriteria penilaian, yaitu Tabel Nilai. Tabel Nilai berisi skor penilaian masing-masing karyawan terhadap masing-masing kriteria penilaian, yaitu IQ, EQ, dan Penampilan sedangkan Tabel Hasil menampilkan hasil perhitungan selisih skor berdasarkan salah satu kriteria yang telah dipilih (terlihat kriteria yang dipilih pada gambar adalah IQ) dengan membandingkan dari setiap karyawan dimana tabel-tabel tersebut ditampilkan dalam bentuk DataGridView. Jadi, ada DataGridView untuk menampilkan Tabel Nilai (sebut saja DGVNilai) dan ada DataGridView untuk menampilkan Tabel Hasil (sebut saja DGVHasil).

Ilustrasi perhitungan dari Tabel Hasil sebagai berikut:
Skor penilaian dari Pegawai-1 akan dibandingkan dengan skor nilai dari masing-masing pegawai yang lain, yaitu dimulai dari Pegawai-1, Pegawai-2, Pegawai-3, Pegawai-4, dan terakhir Pegawai-5. Skor nilai dari Pegawai-1 untuk IQ adalah 2 kemudian dari skor tersebut akan kita kurangkan dengan skor nilai dari masing-masing pegawai lain. Untuk membandingkan dengan skor nilai Pegawai-1 dengan Pegawai-2 kita mengurangkan 2-5 = -3, lanjut ke Pegawai-3 dengan 2-4 = -2, dan seterusnya.

Berikut ini adalah syntax programnya:
'---
Dim H, N, col As Integer

'col adalah index kolom pada Tabel Nilai
col = ComboBox1.SelectedIndex + 1
   For T As Integer = 1 To DGVHasil.Columns.Count - 1
      N = DGVNilai.Rows(T - 1).Cells(col).Value
         For W As Integer = 0 To DGVNilai.Rows.Count - 1
            H = N - DGVNilai.Rows(W).Cells(col).Value
            DGVHasil.Rows(W).Cells(T).Value = H
         Next 'Baris berikutnya pada DGVNilai
   Next 'Kolom berikutnya pada DGVHasil
'---

Tampilan Aplikasi

Tuesday, August 31, 2010

Bulding Graphical MIDlets

Numeric Color Component Values




Lines
Dipakai untuk menggambar garis.
Syntax: 
drawLine(int x1, int y1, int x2, int y2)
dimana x1, y1 adalah starting point dan x2, y2 adalah ending point.

Contoh:

public void paint(Graphics g) {
g.drawLine(5, 10, 15, 55);
}


Rectangles
Dipakai untuk menggambar persegi atau persegi panjang.

Syntax: drawRect(int x, int y, int width, int height)

Contoh:

public void paint(Graphics g) {
g.drawRect(5, 10, 15, 55);
}


Arcs
Dipakai untuk menggambar sudut.

Syntax: drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)


Contoh:

public void paint(Graphics g) {
g.drawArc(5, 10, 150, 75, 95, 115);
}


Drawing Text
Dipakai untuk menambahkan teks.

Syntax: setFont(Font font)


Font getFont(int face, int style, int size)



The font face must be one of the following values: FACE_SYSTEM, FACE_MONOSPACE, or FACE_PROPORTIONAL.
The style of font must be one of the constants I mentioned earlier: STYLE_PLAIN or a combination 
of STYLE_BOLD, STYLE_ITALIC, and STYLE_UNDERLINED. T
he font size is specified 
as one of the following predefined constants: SIZE_SMALL, SIZE_MEDIUM, or SIZE_LARGE.


Contoh:

Font myFont = Font.getFont(Font.MONOSPACE, Font.LARGE, Font.BOLD | Font.UNDERLINED);


drawString(String str, int x, int y, int anchor)


An anchor point is associated with a horizontal constant and a
vertical constant, each of which determines the horizontal and vertical positioning of the 
text with respect to the anchor point. The horizontal constants used to describe an anchor 
point are LEFT, HCENTER, and RIGHT. One of these constants is combined with a vertical 
constant to fully describe an anchor point. The vertical constants are TOP, BASELINE, and 
BOTTOM.

Contoh:

g.drawString(“Look up here!”, getWidth() / 2, 0, Graphics.HCENTER | Graphics.TOP);


Drawing Images
 Dipakai untuk menambahkan image atau picture.
Contoh:
public void paint(Graphics g) {
// Clear the display

g.setColor(255, 255, 255); // White
g.fillRect(0, 0, getWidth(), getHeight());


// Create and load the image

Image img = Image.createImage(“Bull.png”);


// Draw the image

g.drawImage(img, getWidth()/2, getHeight()/2,

Graphics.HCENTER|Graphics.VCENTER);
}


Sumber: Sams Teach Yourself: Wireless Java With J2ME in 21 Days

Tuesday, August 24, 2010

MIDP-Specific Classes and Interfaces

This portion of the MIDP API is divided among several packages, all of which are prefixed with the javax.microedition name:
• javax.microedition.midlet
• javax.microedition.lcdui
• javax.microedition.io
• javax.microedition.rms

The javax.microedition.midlet Package
The javax.microedition.midlet package is the central package in the MIDlet API, and contains only one class: the MIDlet class. The MIDlet class provides the basic functional overhead required of a MIDP application (MIDlet) that can execute on a mobile device.

The javax.microedition.lcdui Package
The javax.microedition.lcdui package includes classes and interfaces that support GUI components that are specially suited for the small screens found in mobile devices.
Following are the interfaces defined in this package:
Choice—An interface that describes a series of items from which the user can
choose.
CommandListener—An event listener interface for handling high-level commands.
ItemStateListener—An event listener interface for handling item state events.

In addition to these interfaces, also several classes are in the javax.microedition.lcdui package:
Alert—A screen that displays information to the user, and then disappears.
AlertType—Represents different types of alerts used with the Alert class.
Canvas—A low-level drawing surface that allows you to draw graphics on the screen.
ChoiceGroup—Presents a group of selectable items; used in conjunction with the Choice interface.
Command—Represents a high-level command that can be issued from within a MIDlet.
DateField—Presents a date and time so that it can be edited.
Display—Represents a mobile device’s display screen, and also handles the retrieval of user input.
Displayable—An abstract component that is capable of being displayed; other GUI components subclass this class.
Font—Represents a font and its associated font metrics.
Form—A screen that serves as a container for other GUI components.
Gauge—Displays a value as a percentage of a bar graph.
Graphics—Encapsulates two-dimensional graphics operations such as drawing lines, ellipses, text, and images.
Image—Represents a graphical image.
ImageItem—A component that supports the layout and display of an image.
Item—A component that represents an item with a label.
List—A component consisting of a list of choices that can be selected.
Screen—Represents a full screen of high-level GUI information, and serves as the base class for all MIDP GUI components.
StringItem—A component that represents an item consisting of a label and an associated string of text.
TextBox—A type of screen that supports the display and editing of text.
TextField—A component that supports the display and editing of text; unlike TextBox, this component can be placed on a form with other components.
Ticker—A “ticker tape” component that displays text moving horizontally across the display.


The javax.microedition.io Package
CLDC lays the groundwork for networking and I/O with the java.io package and the Generic Connection Framework (GCF). The MIDP API builds on this support with the addition of the HttpConnection interface, which is included in the javax.microedition.io package. The HttpConnection interface solidifies the GCF with support for an HTTP connection, which is useful for accessing Web data from within a MIDlet.

The javax.microedition.rms Package
Because few mobile devices have hard drives or any tangible file system, you probably won’t rely on files to store away persistent MIDlet data. Instead, the MIDP API describes an entirely new approach to store and retrieve persistent MIDlet data: the Record Management System (RMS). The MIDP RMS provides a simple record-based database API for persistently storing data. The classes and interfaces that comprise the RMS are all located in the javax.microedition.rms package.
Following are the RMS interfaces found in this package:
RecordComparator—An interface used to compare two records.
RecordEnumeration—An interface used to iterate through records.
RecordFilter—An interface used to filter records according to certain criteria.
RecordListener—An event listener interface used to handle record change events.
In addition to these interfaces, a few classes fit into the RMS architecture. Most importantly, the RecordStore class represents a record store, which is essentially a simplified database for MIDlet data storage.

The following classes are included in the javax.microedition.rms package:
InvalidRecordIDException—Thrown whenever an operation fails because the record ID is invalid
RecordStore—Represents a record store
RecordStoreException—Thrown whenever an operation fails because of a general exception
RecordStoreFullException—Thrown whenever an operation fails because the record store is full
RecordStoreNotFoundException—Thrown whenever an operation fails because the record store cannot be found
RecordStoreNotOpenException—Thrown whenever an operation is attempted on a closed record store


Sumber: Sams Teach Yourself: Wireless Java With J2ME in 21 Days
 

Blogger news

About Me

Palembang, Sumatera Selatan, Indonesia
Seorang yang ingin terus belajar.