Showing posts with label Pemprograman. Show all posts
MessageBOX C#
C# MessageBox.Show
Dialog boxes interrupt users. They force users to respond before further action is taken. This is necessary in some situations. MessageBox.Show is useful if a warning is important or a serious error occurred.Example
To start, the MessageBox.Show method is a static method, which means you do not need to create a new MessageBox() anywhere in your code. Instead, you can simply type "MessageBox" and press the period, and then select Show.Static MethodIn this example, the MessageBox.Show method is used in the Form1_Load event handler. To make the Form1_Load event handler, create a new Windows Forms application and double-click on the window in the designer.
Windows Forms program that uses MessageBox: C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//
// The simplest overload of MessageBox.Show. [1]
//
MessageBox.Show("Dot Net Perls is awesome.");
//
// Dialog box with text and a title. [2]
//
MessageBox.Show("Dot Net Perls is awesome.",
"Important Message");
//
// Dialog box with two buttons: yes and no. [3]
//
DialogResult result1 = MessageBox.Show("Is Dot Net Perls awesome?",
"Important Question",
MessageBoxButtons.YesNo);
//
// Dialog box with question icon. [4]
//
DialogResult result2 = MessageBox.Show("Is Dot Net Perls awesome?",
"Important Query",
MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Question);
//
// Dialog box with question icon and default button. [5]
//
DialogResult result3 = MessageBox.Show("Is Visual Basic awesome?",
"The Question",
MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2);
//
// Test the results of the previous three dialogs. [6]
//
if (result1 == DialogResult.Yes &&
result2 == DialogResult.Yes &&
result3 == DialogResult.No)
{
MessageBox.Show("You answered yes, yes and no.");
}
//
// Dialog box that is right-aligned (not useful). [7]
//
MessageBox.Show("Dot Net Perls is the best.",
"Critical Warning",
MessageBoxButtons.OKCancel,
MessageBoxIcon.Warning,
MessageBoxDefaultButton.Button1,
MessageBoxOptions.RightAlign,
true);
//
// Dialog box with exclamation icon. [8]
//
MessageBox.Show("Dot Net Perls is super.",
"Important Note",
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1);
}
}
}
And:
The MessageBox.Show calls above call into different,
overloaded implementations of the function based on the parameter lists.
Overload
Tip:
For a parameter such as "MessageBoxButtons",
type in "MessageBoxButtons" and press period to see all the options.
Also:
You do not need to create a new MessageBoxButtons() object.
This is an enum type, not a class.
Enum
Images:
The image at the top of this document shows eight dialog boxes.
These correspond to MessageBox.Show calls.
Note:
Dialog box [6] only is shown when you specify
certain options on the previous three dialogs. It tests the DialogResult enumeration.
DialogResult
Next, type in "==" and Visual Studio will suggest options from the DialogResult enumeration. You can compare DialogResult like you would compare an integral type such as int. You can even use it in a switch.
DialogResult
More overloads
Interface:
An interface in the C# language is a contract
that can be used to treat object instances in a more general way.
InterfaceHelpNavigator parameter.
The MessageBox.Show method also has overloads that
allow you to specify Help options. In my experience, these options are
not used most of the time, so I leave the specifics here up to MSDN.Obtrusive
Well-written, helpful error messages are crucial to a quality user
experience. Poorly written error messages result in low product satisfaction, and
are a leading cause of avoidable technical support costs. Unnecessary error messages
break users' flow.
Error Messages: MSDNSummary
And:
We reviewed many other options
of MessageBox.Show, including many parameters to the static method.
So:
The MessageBox.Show method is ideal for many simpler Windows Forms programs
with less specific requirements.
sumber : http://www.dotnetperls.com/messagebox-show
ARRAY (LARIK) DAN RECORD (REKAMAN) DALAM PASCAL
- Record
Sebuah
record merupakan koleksi satuan data yang heterogen, yakni terdiri dari
berbagai type. Satuan data tersebut sering disebut sebagai field dari
record. Field dipanggil dengan menggunakan namanya masing-masing. Suatu field dapat terdiri atas beberapa subfield. Sebuah record rekaman disusun oleh beberapa field. Tiap
field berisi data dari tipe dasar / bentukan tertentu. Record mempunyai
kelebihan untuk menyimpan suatu sekumpulan elemen data yang
berbeda-beda tipenya (di banding array). Contoh , sebuah record dengan
empat buah field.
Deklarasi record
Type
Variable = record
…field = type data
…field = type data
…field = type data
End.
STATEMENT “WITH”
Selain cara yang telah disebutkan diatas, untuk memproses suatu record dapat
digunakan
statement WITH. Dengan statement ini penulisannya akan lebih sederhana.
Bentuk Umum penulisan statement WITH ini adalah :
WITH nama_record DO statement
Perhatikan deklarasi dibawah ini :
TYPE x = RECORD
No : integer;
Kode : char;
Juml : integer;
Harga : real;
END;
VAR p,q : x;
Untuk membaca variabel p dan q di atas dengan memanfaatkan statement WITH bentuknya menjadi :
WITH p,q DO read (no, kode, juml, harga);
Bandingkan jika digunakan cara sebelumnya :
Read(p.no, p.kode, p.juml,p.harga,q.no,q.kode,q.juml,q.harga);
Pernyataan seperti :
Data.npm :=‘22297566’
Data.Nama:=‘Abdul Kadir’
Data.Fakultas:=‘Teknik’
Dapat diganti dengan :
WITH Data Do
Begin
npm :=‘22297566’
Nama:=‘Abdul Kadir’
Fakultas:=‘Teknik’
end;
Contoh program record sederhana:
Type
Hasil = record
Jari-jari = real;
Keliling = real;
Luas = real;
End.
Var
Lingkarang = hasil;
Begin
Write (jari-jari lingkaran?); real readln (lingkaran.jari-jari);
Lingkaran.keliling :=2 * Pi * lingkaran.jari-jari;
Lingkaran.luas := Pi * sqr (lingkaran jari-jari);
Writeln;
Writeln (‘keliling lingkaran =’, lingkaran.keliling:7:2);
Writeln (‘luas lingkaran =’, lingkaran luas :7:2);
End.
program record;
uses crt;
type
TSiswa = record
nim : string[8];
nama : string[25];
agama : string[10];
ktp : string[25];
end;
var
s : TSiswa;
umur,ts,tl : integer;
begin
clrscr;
write (’Masukkan tahun sekarang: ‘); readln (ts);
writeln (’Isikan data anda dalam Form ini’);
write (’NIM : ‘); readln (s.nim);
write (’NAMA : ‘); readln (s.nama);
write (’TAHUN LAHIR : ‘); readln (tl);
umur := (ts-tl);
write (’AGAMA : ‘);readln (s.agama);
write (’NO.KTP : ‘); readln (s.ktp);
writeln;
writeln (’Berikut ini informasi yang anda berikan: ‘);
writeln (’NIM : ‘, s.nim);
writeln (’NAMA : ‘, s.nama);
writeln (’Umur : ‘,umur);
writeln (’AGAMA : ‘, s.agama);
writeln (’NO.KTP : ‘, s.ktp);
READLN;
end.
- Array (Larik)
Array
adalah tipe data terstruktur yang terdiri dari sejumlah
komponen-komponen yang mempunyai tipe sama. Komponen-komponen tersebut
disebut sebagai komponen type, larik mempunyai jumlah komponen yang
jumlahnya tetap. Banyaknya komponen dalam larik ditunjukkan oleh suatu
index, dimana tiap komponen di array dapat diakses dengan menunjukkan
nilai indexnya atau subskript. Array dapat bertipe data sederhana
seperti byte, word, integer, real, bolean, char, string dan tipe data
scalar atau subrange. Tipe larik mengartikan isi dari larik atau
komponen- komponenya mempunyai nilai dengan tipe data tersebut.
Array
didefinisikan sebagai suatu kumpulan dimana elemen-elemennya berjenis
data sama. (homogeny) Suatu array dapat dibedakan atas 2 (dua) bagian,
yaitu :
a. Array Berdimensi Satu
Array
berdimensi satu dapat dikatakan sebagai suatu daftar yang linier atau
sebuah kolom. Bentuk deklarasi dari array jenis ini dalam bahasa Pascal
adalah:
VAR nama_array : ARRAY [index] OF jenis_elemen;
Contoh Program :
Program Contoh_Array_Input;
Uses Crt;
Var
Bilangan : array[1..50] of Integer;
Begin
ClrScr;
Bilangan[1]:=3;
Bilangan[2]:=29;
Bilangan[3]:=30;
Bilangan[4]:=31;
Bilangan[5]:=23;
Writeln('nilai varibel bilangan ke 3 =',Bilangan[3]);
Readln;
End.
Array
tidak hanya dapat berupa suatu varibel yang dideklarasikan di bagian
deklarasi variabel, tetapi dapat juga berupa konstanta (const).
Contoh Program :
Program;
Uses Crt;
Const
Tetap : Array[1..4] of Integer=(7,10,21,20);
Var
i : Integer;
Begin
For i:= 1 to 4 Do
Writeln('Nilai Konstan array ke ',i:2,' =',Tetap[i]);
Readln;
End.
b. Array Multi Dimensi
Array dimensi dua ini dapat dianggap sebagai sebuah matriks yang jumlah kolomnya lebih dari satu. Bentuk deklarasi :
VAR nama_array : ARRAY [indeks_baris,indeks_kolom] OF jenis;
Di
dalam pascal Array dapat berdimensi lebih dari satu yang disebut dengan
array dimensi banyak (Multidimensional array), disini akan dibahas
array 2 dimensi saja. Array 2 dimensi dapat mewakili suatu bentuk tabel
atau matrik, yaitu indeks pertama menunjukkan baris dan indeks ke dua
menunjukkan kolom dari tabel atau matrik.
Untuk mengetahui cara mendeklarasikan dari penggunaan aray dua dimensi dapat dilihat pada listing program dibawah ini.
Program_Deklarasi_Array_Dua_Dimensi;
Uses Crt;
Var Tabel : Array[1..3,1..2] of Integer;
i,j : Integer;
Begin
ClrScr;
Tabel[1,1]:=1;
Tabel[1,2]:=2;
Tabel[2,1]:=3;
Tabel[2,2]:=4;
Tabel[3,1]:=5;
Tabel[3,2]:=6;
For I := 1 to 3 Do Begin For J:= 1 to 2 Do Begin Writeln('Elemen ',i,',',j,'= ',tabel[i,j]);
End;
End;
Readln;
End.
Contoh program Array dalam record:
Type barang= RECORD
nmbrg:string[20];
jmlbrg:array[1..3]of byte;
hrgbrg:real;
total:real;
end;
var jual:barang;
tbarang, i:integer;
Begin
clrscr;
write(‘Nama Barang :’);readln(jual.nmbrg);
for i:=1to 3 do
begin
write(‘Jumlah barang ’,I,’ : ’);readln(jual.jmlbrg[i]);
tbarang:=tbarang+jual.jmlbrg[i];
end;
write(‘Harga barang :’);readln(jual.hrgbrg);
jual.total:=tbarang*jual.hrgbrg;
writeln(‘Total Harga Barang = ‘, jual.total:10:2);
end.
Coba lihat sendiri perbedaan antara array tipe record dan array dalam record dari dua contoh program di atas !
Program Penjumlahan_matrik;
uses crt;
var
matrik1, matrik2 , hasil : array[1..3,1..2] of integer;
i , j : integer;
begin
clrscr;
{ input matrik ke satu }
writeln(' Elemen matrik satu');
for i := 1 to 3 do
begin
for j := 1 to 2 do
begin
write('Elemen baris -',i,' kolom -',j,'= ');
readln(matrik1[i,j]);
end;
end;
{input matrik ke dua}
writeln('input elemen matrik dua');
for i:= 1 to 3 do
begin
for j:= 1 to 2 do
begin
write('Elemen baris -',i,' kolom -',j,'= ');
readln(matrik2[i,j]);
end;
end;
{proses penjumlahan tiap elemen}
for i := 1 to 3 do
begin
for j:= 1 to 2 do
begin
hasil[i,j]:=matrik1[i,j]+matrik2[i,j];
end;
end;
{proses cetak hasil}
writeln(' ');
for i:= 1 to 3 do
begin
for j:= 1 to 2 do
begin
write(matrik1[i,j]:4);
end;
writeln;
end;
writeln('+');
for i:= 1 to 3 do
begin
for j:= 1 to 2 do
begin
write(matrik2[i,j]:4);
end;
writeln;
end;
writeln('=');
for i:= 1 to 3 do
begin
for j:= 1 to 2 do
begin
write(hasil[i,j]:4);
end;
writeln;
end;
readln;
Algoritma Stack and Queue
1. Stack :
Berupa susunan data yang di buat dari array atau linked list dan memiliki aturan seperti ini. Data yang masuk pertama akan di keluarkan terakhir kali. Bisa di anggap ini adalah sebuah pipa dengan satu lubang dan memasukkan beberapa bola kedalamnya. untuk mengeluarkan bola yang pertama, kita harus mengeluarkan bola yang terkhir dan lainya terlebih dahulu. Kira kira seperti itulah konsep dari stack. Data yang di proses pada stack hanya data yang berada pada urutan teratas
2. Queue :
Berupa susunan antrian yang di representasikan dengan array atau linked list. Sistemnya adalah data yang pertama kalo masuk, adalah data yang pertama kali keluar pula, atau dapat di anggap sebagai pola pipa dua pintu, dimana pintu masuk dan pintu keluar berbeda. Biasanya sistem ini di terapkan dalam antrian di berbagai tempat seperti apotik, bank, rumahsakit dan lain lain.