0% found this document useful (0 votes)
3 views

Function Example

The document contains various examples of VBA (Visual Basic for Applications) code snippets demonstrating different programming constructs such as functions, subroutines, conditional statements (If-Else), Select Case, loops (For-Next, Do-While, Do-Until), and object methods. Each section provides a brief code example illustrating the specific concept. The examples are designed to showcase basic programming techniques in a clear and concise manner.

Uploaded by

abhimanyupandav4
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Function Example

The document contains various examples of VBA (Visual Basic for Applications) code snippets demonstrating different programming constructs such as functions, subroutines, conditional statements (If-Else), Select Case, loops (For-Next, Do-While, Do-Until), and object methods. Each section provides a brief code example illustrating the specific concept. The examples are designed to showcase basic programming techniques in a clear and concise manner.

Uploaded by

abhimanyupandav4
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Function Example

Sub CATMain()

Dim Box

Box = MsgBox(Multiplication(1, 3))

End Sub

Function Multiplication(I, II)

Multiplication = I * II

End Function

================================================

Sub Routine Example

Sub CATMain()

Multiplication 1,3

End Sub

Sub Multiplication(I, II)

Dim Box

Box = MsgBox(I * II)

End Sub

=================================================

If - Else /And /Or

Sub CATMain()

Dim A,B

A =2

B =2

If (A >= 1) And (B=1) Then

MsgBox("C = 2")
MsgBox("D = 1")

Else

MsgBox (A*B)

End If

End Sub

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

Sub CATMain()

Dim A,B

A =2

B =2

If (A >= 1) Or (B=1) Then

MsgBox("C = 2")

MsgBox("D = 1")

Else

MsgBox (A*B)

End If

End Sub

==============================================

Select Case Else

Sub CATMain()

Dim Input

Input = Inputbox("Enter number between 0-2:",0)

Select Case Input

Case "0"

MsgBox("Number =0")
Case "1" , "2"

MsgBox("Number>0")

Case Else

MsgBox ("Wrong input")

End select

End Sub

=============================================

For-Next Case

Sub CATMain()

Dim I, Sum

Sum=0

For I =0 To 10 Step 1

Sum = Sum + I

Next

MsgBox (Sum)

End Sub

==============================================

Do-While Case

Sub CATMain()

Dim I, Sum

Sum=0

Do While Sum < 100

Sum = Sum + I

I=I+1

Loop
MsgBox (Sum)

End Sub

===============================================

Do-Until Case

Sub CATMain()

Dim I, Sum

Sum=0

Do

Sum = Sum + I

I=I+1

Loop Until (Sum>60) Or (I>10)

MsgBox (Sum)

End Sub

===============================================

Object-Method-Class

Print document name & part name

Sub CATMain()

Dim Part

Dim Doc

Set Doc = CATIA.ActiveDocument

Set Part = Doc.Part

MsgBox(Doc.Name)

MsgBox(Part.Name)

End Sub

You might also like