View Full Version : Aral Programming


earletam
19th May '08 Mon, 21:56
LANGUAGE WE WILL USE : VB.NET, C#.NET
RDBMS : MS access, MS SQL server, MySql

post ko lahat ng alam ko.

kung mey question kayo post lang about the said topic.

earletam
19th May '08 Mon, 22:33
unang una cguro e kong anu-anong mga programming application na ating gagamitin.

SOFTWARE REQUIRED:
*Visual Basic 2005 express edition and Visual C# 2005 express edition or Visual Studio 2005(mas completo)
*Ms Access, MS Sql Server 2005, MySql

hindi ako magaling sa mga terminology ng databasing kaya sana maintindihan niyo.

Malaking help cguro kong may experience kayo sa c, c++, java, OOP programming

"A long journey always starts with a single step" ika nga

Variables

ginagamit ang mga variable para mag store ng data(iba't ibang data)

eg:
int, uint, long, ulong, float, double, decimal, string, char, bool
eg

VB :
Dim x As Integer
Dim y As string

x = 10
y = "Hello"

C# :
int x;
string y;

x = 10;
y = "Hello";


Expression

+ = ginagamit pang add ng numeric na data type or para mag append ng string at char

VB:
x = 12 + 1
y = "hello" + " there"

C#:
x = 12 + 1;
y = "hello" + " there";

- = ginagamit pang deduction ng numeric na data type
VB:
x = 12 - 1

C#:
x = 12 - 1;

* = ginagamit pang multiply ng numeric na data type
VB:
x = 12 * 1

C#:
x = 12 * 1;

/ = ginagamit pang divide ng number na data type
VB:
x = 12 / 1

C#:
x = 12 / 1;

earletam
19th May '08 Mon, 22:53
Comments
ginagamit po as descriptive text para sa mga code
VB:
'declaration of x

C#:
//declaration of x

Boolean Logic
bool type hold only true or false

ginagamit po eto for data comparison

== = is equal?

!= = is not equal?

< = is less than?

> = is greater than?

<= = is greater than or equal?

>= = is less than or equal?

eg:

VB:
Dim x As Integer
Dim y As Integer
x=0
y=1

if (x=y) '0==1 false
if (x!=y) '0!=1 true
if (x<y) '0<1 true
if (x>y) '0>1 false

C#:
int x;
int y;
x=0;
y=0;

if (x==y) //0==1 false
if (x!=y) //0!=1 true
if (x<y) //0<1 true
if (x>y) //0>1 false

underverse
19th May '08 Mon, 23:24
babalik ako sa thread na to
kapag malapit na namin pag-aralan
ang vb.net^_^ thanks sir earl^__^

earletam
19th May '08 Mon, 23:28
Branching
-more on controlling po eto kung anu-anong mga line ang dapat execute

if statement

VB:
Dim x As Integer
Dim y As Integer
x=0
y=0
If (x = y)
MessageBox.Show(“x is equal y”)
End If

C#:
int x;
int y;
x=0
y=0
if (x == y)
{
MessageBox.Show(“x is equal y”);
}

Select Case for VB and switch for C#

VB:
Dim x As Integer
x=0
Select Case (x)
Case 0
MessageBox.Show(“x is equal to 0”)
Case 1
MessageBox.Show(“x is equal to 1”)
Case Else
MessageBox.Show(“x is not 0 or 1”)

End Select

C#:
int x;
x=0;
switch (x)
{
case 0 :
MessageBox.Show(“x is equal to 0”);
break;
case 1 :
MessageBox.Show(“x is equal to 1”);
break;
default :
MessageBox.Show(“x is not 0 or 1”);
break;
}

earletam
19th May '08 Mon, 23:52
Looping
-ginagamit para mag execute ng code paulit-ulit

For Loop

VB:
Dim x As Integer
For x = 0 To 5
MessageBox.Show(x.ToString());
Next

C#:
Int x=0;
For (x=0; x<=5; x++)
{
MessageBox.Show(x.ToString());
}


While Loop

VB:
Dim x As Integer
While (x <= 5)
MessageBox.Show(x.ToString())
x += 1
End While

C#:

int x=0;
while (x <= 5)
{
MessageBox.Show(x.ToString());
x++;
}

earletam
19th May '08 Mon, 23:54
babalik ako sa thread na to
kapag malapit na namin pag-aralan
ang vb.net^_^ thanks sir earl^__^

no problem sir

earletam
20th May '08 Tue, 00:35
Conversion
-pag convert ng isang data type sa ibang data type

Command Result

Convert.ToBoolean(val) val converted to bool.

Convert.ToByte(val) val converted to byte.

Convert.ToChar(val) val converted to char.

Convert.ToDecimal(val) val converted to decimal.

Convert.ToDouble(val) val converted to double.

Convert.ToInt16(val) val converted to short.

Convert.ToInt32(val) val converted to int.

Convert.ToInt64(val) val converted to long.

Convert.ToSByte(val) val converted to sbyte.

Convert.ToSingle(val) val converted to float.

Convert.ToString(val) val converted to string.

Convert.ToUInt16(val) val converted to ushort.

Convert.ToUInt32(val) val converted to uint.

Convert.ToUInt64(val) val converted to ulong.

VB:
Dim x As String ‘x is a string data type
Dim y As Integer ‘y is a integer data type
x = "0" ‘x gets the value 0 as string
y = Convert.ToInt32(x) ‘y gets the value of the convert x as Integer data type
x = y.ToString() ‘x gets the value of the convert y as String data type


C#:
string x; //x is a string data type
int y; //y is a integer data type
x = “0”; //x gets the value 0 as string
y = Convert.ToInt32(x); //y gets the value of the convert x as Integer data type
x = y.ToString(); //x gets the value of the convert y as String data type

earletam
20th May '08 Tue, 05:59
Arrays
-ginagamit sa pag store ng maraming data sa i-isang data type depende sa array size

In VB, Kung ang gusto mong size ng array mo ay 5 kailangan mag minus ka ng isa :

Dim x(4) As Integer
x(0) = 1 ‘element of x in 0 gets the value 1
x(1) = 2 ‘element of x in 0 gets the value 2
x(2) = 3 ‘element of x in 0 gets the value 3
x(3) = 4 ‘element of x in 0 gets the value 4
x(4) = 5 ‘element of x in 0 gets the value 5

For Each xElement As Integer In x
MessageBox.Show(xElement)
Next

In C#, Kung gusto mong size ng array mo ay 5 di mo kailangan mag minus :

int[] x = new x[5];
x[0] = 1; //element of x in 0 gets the value 1
x[1] = 2; //element of x in 0 gets the value 2
x[2] = 3; //element of x in 0 gets the value 3
x[3] = 4; //element of x in 0 gets the value 4
x[4] = 5; //element of x in 0 gets the value 5

foreach (Int32 xElement in x)
{
MessageBox.Show(xElement);
}

String Manipulation
-pag manipulate ng string data type

To lowercase and To uppercase

VB:
Dim x As String
x = "HeLLo" ‘x gets the value HeLLo
MessageBox.Show(x.ToLower()) `x has the value HeLLo changed to lowercase
MessageBox.Show(x.ToUpper()) `x has the value HeLLo changed to uppercase

C#:
string x;
x = "Hello"; ‘x gets the value HeLLo
MessageBox.Show(x.ToLower()); `x has the value HeLLo changed to lowercase
MessageBox.Show(x.ToUpper()); `x has the value HeLLo changed to uppercase

Replace

VB:
Dim x As String
x = "Symbianize.yahoo" 'x gets the value Symbianize.yahoo as string data type
MessageBox.Show(x.Replace(".", "@")) ' replace all . to @ in x

C#:

string x; //
x = "Symbianize.yahoo"; //x gets the value Symbianize.yahoo as string data type
MessageBox.Show(x.Replace(".","@")); //replace all . to @ in x

jhonex
20th May '08 Tue, 06:27
ask lang po, puwidi sa windows vista business edition ang visual basic v6 at saka crystal report v8 using office access 2007?

earletam
20th May '08 Tue, 06:55
ask lang po, puwidi sa windows vista business edition ang visual basic v6 at saka crystal report v8 using office access 2007?

actually sir visual basic 8.0 or vb 2005 po tong ginagamit natin. regarding crystal report pwede yan gingamit ko sa report. never tried access 2007.

kurabo
20th May '08 Tue, 07:26
sana meron poh para sa Java..

earletam
20th May '08 Tue, 07:55
Functions

Return values

VB:
Private Function AddCalculate(ByVal Val1 As Integer, ByVal Val2 As Integer) As Integer
Return Val1 + Val2
End Function

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim x As Integer
Dim y As Integer
x = 5
y = 2
MessageBox.Show(AddCalculate(x, y))
End Sub

C#:
private int AddCalculate(int Val1, int Val2)
{
return Val1 + Val2;
}

private void Form1_Load(object sender, EventArgs e)
{
int x;
int y;
x = 5;
y = 2;
MessageBox.Show(AddCalculate(x, y).ToString());
}

No Return values

VB:
Private Sub AddCalculate()
x += y
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
x = 5
y = 2
MessageBox.Show(x)
AddCalculate()
MessageBox.Show(x)
End Sub

C#:
int x;
int y;
private void AddCalculate()
{
x += y;
}
private void Form1_Load(object sender, EventArgs e)
{
x = 5;
y = 2;
MessageBox.Show(x.ToString());
AddCalculate();
MessageBox.Show(x.ToString());
}

earletam
20th May '08 Tue, 13:03
Error Handling
-ginagamit para malaman at ma handle ng mabuti ang error/s

Try .. Catch .. Finally
Try = dito and mga code na naniis natin e execute
catch = dito patutungo pag mey error sa try
Finally = dito pupunta magkaron man ng error o wala

VB:
Dim
Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Access.mdb;Persist Security Info=true")
Try
conn.Open()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
conn.Close()
End Try

C#:
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Access.mdb;Persist Security Info=true");
try
{
conn.Open();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}

earletam
20th May '08 Tue, 14:20
Gagawa po tayo ng simpling button click event

sa desktop niyo hanapin ang may icon na tulad nito, visual studio icon then double click lang
http://i113.photobucket.com/albums/n225/earletam/SYMBIANIZE/1.jpg

Pag Load ng Visual Studio, e click po ang File>New>Project
http://i113.photobucket.com/albums/n225/earletam/SYMBIANIZE/3.jpg

makikita niyo tong iba't-ibang mga projects ng visual studio, piliin and Windows Application at click and Ok button
http://i113.photobucket.com/albums/n225/earletam/SYMBIANIZE/4.jpg

may lalabas po na isang Form na ang pangalan ay Form1(nasa bandang upper left ng form)
http://i113.photobucket.com/albums/n225/earletam/SYMBIANIZE/5.jpg

makikita niyo din po and toolbox at mga controls na naka dock sa left corner ng visual studio
http://i113.photobucket.com/albums/n225/earletam/SYMBIANIZE/6.jpg

e drag niyo po and button na control sa gitna ng form
http://i113.photobucket.com/albums/n225/earletam/SYMBIANIZE/7.jpg

eto po may button na tayo sa form na ang pangalan ay button1, double click niyo po ang button
http://i113.photobucket.com/albums/n225/earletam/SYMBIANIZE/8.jpg

lalabas po tong Form1.vb(coding tab), dito tayo magtype-type ng mga codes
http://i113.photobucket.com/albums/n225/earletam/SYMBIANIZE/9.jpg

ngayon e type po ang MessageBox.Show("Button1 is clicked") sa loob ng Button1_Click(..)
http://i113.photobucket.com/albums/n225/earletam/SYMBIANIZE/10.jpg

e debug at execute po natin ang application, hanapin ang parang play na icon sa toolbar
http://i113.photobucket.com/albums/n225/earletam/SYMBIANIZE/11.jpg

makikita po natin ang isang form na lalabas
http://i113.photobucket.com/albums/n225/earletam/SYMBIANIZE/12.jpg

e click po nating ang button na ang pangalan ay button1
http://i113.photobucket.com/albums/n225/earletam/SYMBIANIZE/13.jpg

lalabas po ang isang MessageBox na may nakasulat na Button1 is clicked

Close niyo muna ang form, drag tayong ng Textbox control sa form mula sa Toolbox
http://i113.photobucket.com/albums/n225/earletam/SYMBIANIZE/14.jpg

e lagay niyo sa taas ng button
http://i113.photobucket.com/albums/n225/earletam/SYMBIANIZE/15.jpg

balik tayo sa coding tab click niyo ang Form1.vb tab
http://i113.photobucket.com/albums/n225/earletam/SYMBIANIZE/16.jpg

makikita niyo ulit eto
http://i113.photobucket.com/albums/n225/earletam/SYMBIANIZE/10.jpg

lagyan niyo ng TextBox1.Text = "Button1 is clicked" sa ilalim ng MessageBox.Show("Button1 is clicked")
http://i113.photobucket.com/albums/n225/earletam/SYMBIANIZE/17.jpg

e debug at execute po ulit natin
http://i113.photobucket.com/albums/n225/earletam/SYMBIANIZE/11.jpg

makikita po natin ang form na may button at Textbox
http://i113.photobucket.com/albums/n225/earletam/SYMBIANIZE/18.jpg

e click po nating ang button na ang pangalan ay button1,lalabas po ang isang MessageBox, click po natin ang Ok
http://i113.photobucket.com/albums/n225/earletam/SYMBIANIZE/13.jpg

lalabas sa ating Textbox ang Text na "Button1 is clicked"
http://i113.photobucket.com/albums/n225/earletam/SYMBIANIZE/19.jpg