4.3 Menulis kode pemrogram sesuai dengan aturan dan sintaks bahasa pemrograman

https://www.youtube.com/watch?v=VPszGL3aWEs Syntax Proses

If...Then...Else Statement

contoh   https://www.youtube.com/watch?v=EBB2ZrJunQc

               https://www.youtube.com/watch?v=VPszGL3aWEs

Dim Number, Digits, MyString

Number = 53    ' Initialize variable.

If Number < 10 Then

    Digits = 1

ElseIf Number < 100 Then

' Condition evaluates to True so the next statement is executed.

    Digits = 2

Else

    Digits = 3

End If

    ' Assign a value using the single-line form of syntax.

Tetapkan nilai menggunakan bentuk baris tunggal sintaks

If Digits = 1 Then MyString = "One" Else MyString = "More than one"

Use If TypeOf construct to determine whether the Control passed into a procedure is a text box

 

Contoh

Sub ControlProcessor(MyControl As Control)

    If TypeOf MyControl Is CommandButton Then

        Debug.Print "You passed in a " & TypeName(MyControl)

    ElseIf TypeOf MyControl Is CheckBox Then

        Debug.Print "You passed in a " & TypeName(MyControl)

    ElseIf TypeOf MyControl Is TextBox Then

        Debug.Print "You passed in a " & TypeName(MyControl)

    End If

End Sub

 

----------------------------------

Do...Loop Statement

 

Syntax

 

Do [{While | Until} condition]

[statements]

[Exit Do]

[statements]

Loop

 

Or, you can use this syntax:

------------

Do

[statements]

[Exit Do]

[statements]

-------------------

Loop [{While | Until} condition]

 

Contoh

Dim Check, Counter

Check = True: Counter = 0    ' Initialize variables.

Do    ' Outer loop.

    Do While Counter < 20    ' Inner loop.

        Counter = Counter + 1    ' Increment Counter.

        If Counter = 10 Then    ' If condition is True.

            Check = False    ' Set value of flag to False.

            Exit Do    ' Exit inner loop.

        End If

    Loop

Loop Until Check = False    ' Exit outer loop immediately.

 

-------------------

 

While...Wend Statement

Syntax

While condition

[statements]

 

Wend

The While...Wend statement syntax has these parts:

contoh

Dim Counter

Counter = 0    ' Initialize variable.

While Counter < 20    ' Test value of Counter.

    Counter = Counter + 1    ' Increment Counter.

Wend    ' End While loop when Counter > 19.

Debug.Print Counter    ' Prints 20 in the Immediate window

 

-----------------------

 

Do...Loop Statement

 

Syntax

Do [{While | Until} condition]

[statements]

[Exit Do]

[statements]

Loop

 

Or, you can use this syntax:

Do

[statements]

[Exit Do]

[statements]

 

Loop [{While | Until} condition]

 

The Do Loop statement syntax has these parts

Remarks

Any number of Exit Do statements may be placed anywhere in the Do…Loop as an alternate way to exit a Do…Loop. Exit Do is often used after evaluating some condition, for example, If…Then, in which case the Exit Do statement transfers control to the statement immediately following the Loop.

When used within nested Do…Loop statements, Exit Do transfers control to the loop that is one nested level above the loop where Exit Do occurs

 

----------------------------

 

For...Next Statement

 

Syntax

For counter = start To end [Step step]

[statements]

[Exit For]

[statements]

 

Next [counter]

The For…Next statement syntax has these parts:

Dim Words, Chars, MyString

For Words = 10 To 1 Step -1     ' Set up 10 repetitions.

    For Chars = 0 To 9    ' Set up 10 repetitions.

        MyString = MyString & Chars    ' Append number to string.

    Next Chars    ' Increment counter

    MyString = MyString & " "    ' Append a space.

 

Next Words

--------------------

 

For Each...Next Statement

      Repeats a group of statements for each element in an array or collection.

 

Syntax

For Each element In group

[statements]

[Exit For]

[statements]

Next [element]

The For...Each...Next statement syntax has these parts:

statement / pernyataan

Unit lengkap secara sintaksis yang mengekspresikan satu jenis tindakan, deklarasi, atau definisi. Pernyataan biasanya menempati satu baris, meskipun Anda dapat menggunakan titik dua (:) untuk menyertakan lebih dari satu pernyataan pada satu baris. Anda juga dapat menggunakan karakter kelanjutan baris (_) untuk melanjutkan satu baris logis ke baris fisik kedua

 

------------------------

Catatan

Anda harus membuka file sebelum operasi I / O dapat dilakukan padanya. Open mengalokasikan buffer untuk I / O ke file dan menentukan mode akses untuk digunakan dengan buffer.

 

 

 

 

 

 

 

 

 

 

 

Komentar

Postingan populer dari blog ini

Simbol Flowchart / Bagan Alir