Sei sulla pagina 1di 48

04

Modul ke:

Fakultas

FASILKOM
Program Studi

Sistem
Informasi

PEMOGRAMAN
VISUAL CLIENT SERVER
Form Variable, Data Type, Operator, Condition,
Iteration
Hariesa B.P, ST, MM

Module Overview

Declaring Variable and assigning values


Data Type
Operator
Condition
Iteration

Variables

Variables
A variable represents a named location in memory for
piece of data. An application can access a piece of data
by using the variable it has been assigned to.
A varible has the following six facets:
Name : Unique identifier that refer to the variable in code
Address : Memory location of the variable.
Data type : Type and size of data that the variable can store
Value : Value at the address of the variable.
Scope : Define area of code that can access and use the
variable.
Lifetime : Period of time that a variable is valid and available for
use

Examples of variable
As a counter for loop structure
As Temporary storage for property values
As a container to store a value that was return from a function

Data Type

Data Type

Declaring & Assigning Variables

Note :
C# is case sensitive. Variable MyData is not the same with
myData

Declaring & Assigning Variables

What is variable scope

Variable can have one of the


following level of scope
Block
Procedure
Class
Namespace

What is variable scope

Converting a Value to Different Data Type

There are two type of conversions :


Implicit conversion. Automatically
performed by the common language
runtime (CLR) on operations that are
guaranteed to succeed
Explicit conversion. Require to write
code to perform a conversion that
otherwise could lose information or
procedure an error.

Converting a Value to Different Data Type

Implicit Conversion

Explicit Conversation

Class for conversation :


System.Convert

Operators

Operators Assignment

Decision Statement

Using One Way If Statement

Using ? Or If Statement

Using ? Or If Statement

Using Multiple Outcome If Statement

Using the Switch Statement

Using the Switch Statement

Guideline for Choosing a Decision Construct

Practice
Right click on the solution name, Add new project, click visual C#, click windows, click windows form, give the
project name with latihan4
Right click on project name, click set as startup project
Create a New Form and name as DecisionForm

Field

Description

Name

DecisionForm

Text

decision Form Aplikasi

StartPosition

CenterScreen

Decision Form

Add 2 textbox, 2 label and 3 button

Properties Label
Field

Description

Name

label1

Text

Variabel 1

Name

Label2

Text

Variabel 2

Properties TextBox
Field

Description

Name

tbVar1

Name

tbVar2

Properties Button
Field

Description

Name

btnIf

Text

GO If

Name

btnItenary

Text

GO ?

Name

btnSwitch

Text

Go Switch

Code For btnIf

Code for btnItenary

Set as to run for first time then click


F5

Code for btnSwitch

Iteration Statement

Type Of Iteration Statement

While Statement

Do Loop Statement

For Statement

Break & Continue Statment

Practice

Create a New Form and name as


IterationForm
Field

Description

Name

IterationForm

Text

Iteration Form Aplikasi

StartPosition

CenterScreen

Layout Iteration Form

Add 2 Label, 2 textbox and 3 Button

Properties Label
Field

Description

Name

label1

Text

Nilai Awal

Name

label2

Text

Batas AKhir

Properties TextBox
Field

Description

Name

textbox1 -> tbNilaiAwal

Name

textbox2 -> tbCounter

Properties Button
Field

Description

Name

btnWhile

Text

While

Name

btnDo

Text

Do

Name

btnFor

Text

For

Code For btnWhile

Code For btnDo

Code for btnFor

Set as the Form for run, then click F5

Reference

MCT 10266
MCT 2546
netIndonesia.net
MSDN

Terima Kasih

Potrebbero piacerti anche