VBScript শিক্ষাক্রম

ইনস্ট্যান্স

If...then..else 语句
এই উদাহরণে আপনাকে if...then..else স্টেটমেন্ট লিখতে কিভাবে দেখানো হয়েছে。
If...then..elseif 语句
এই উদাহরণে আপনাকে if...then...elseif... স্টেটমেন্ট লিখতে কিভাবে দেখানো হয়েছে。
সিলেক্ট কেস স্টেটমেন্ট
This example demonstrates how to write a select case statement.

Conditional statements

Frequently, when we write code, we need to perform different operations based on different judgments. We can use conditional statements to do this work.

In VBScript, we can use three conditional statements:

if statement
If you want to execute a series of codes when the condition is true, you can use this statement.
if...then...else statement
If you want to execute one of the two sets of code, you can use this statement.
if...then...elseif statement
If you want to execute one of the sets of code, you can use this statement.
Select case statement
If you want to execute one of the sets of code, you can use this statement.

If....Then.....Else

In the following cases, you can use the If...Then...Else statement:

  • Execute a segment of code when the condition is true
  • Select two code segments to execute

যদি আপনি true হলে শুধুমাত্র একটি বিধান বাস্তবায়িত করতে চাই, তাহলে কোডটিকে একটি সারিতে লিখতে হবে:

if i=10 Then msgbox "Hello"

উপরোক্ত কোডে, .else.. বিধান নেই। আমরা শুধুমাত্র true হলেই একটি কোডবলিত কোড বাস্তবায়িত করছি (যখন i 10-এর সঙ্গে সমান)।

যদি আমরা true হলে একাধিক বিধান বাস্তবায়িত করতে চাই, তাহলে একটি সারিতে একটি বিধান লিখতে হবে, এবং এটি শেষ করতে "End If" শব্দ ব্যবহার করতে হবে:

if i=10 Then
   msgbox "Hello"
   i = i+1
end If

উপরোক্ত কোডে, .else.. বিধান নেই। আমরা শুধুমাত্র কোডটি true হলেই বাস্তবায়িত করছি。

যদি আমরা শর্ত true হলে কোনও বিধান বাস্তবায়িত করতে চাই, এবং যদি শর্ত false হলে আরেকটি বিধান বাস্তবায়িত করতে চাই, তাহলে "Else" শব্দ যোগ করতে হবে:

if i=10 then
   msgbox "Hello"
else
   msgbox "Goodbye"
end If

যখন শর্ত true হলে প্রথম কোডবলিত কোড বাস্তবায়িত হবে, যখন শর্ত বাস্তবায়িত না হলে দ্বিতীয় কোডবলিত কোড বাস্তবায়িত হবে (যখন i 10-এর বাইরে থাকে)।

If....Then.....Elseif

আমি আপনাকে একটি সমস্ত কোডগুলির মধ্যে একটি চুনতে চাই, তাহলে if...then...elseif বিধান ব্যবহার করতে পারেন:

if payment="Cash" then
   msgbox "You are going to pay cash!"
 elseif payment="Visa" then
   msgbox "You are going to pay with visa."
 elseif payment="AmEx" then
   msgbox "You are going to pay with American Express."
 else
   msgbox "Unknown method of payment."
end If

Select Case

If you want to execute one of multiple blocks of code, you can use the SELECT statement:

select case payment
 case "Cash"
   msgbox "You are going to pay cash"
 case "Visa"
   msgbox "You are going to pay with visa"
 case "AmEx"
   msgbox "You are going to pay with American Express"
 case Else
   msgbox "Unknown method of payment"
end select

উপরোক্ত কোডের কার্যকারিতা: প্রথমে, আমরা একটি সহজ এক্সপ্রেশন (প্রায়শই একটি ভ্যারিয়েবল) চাই, এবং এই এক্সপ্রেশনটির মান প্রথমবার পরীক্ষা করা হবে।তারপর, এক্সপ্রেশনের মানকে প্রত্যেক case-এর মানের সাথে তুলনা করা হবে, যদি ম্যাচ করা হয়, তবে ম্যাচ করা case-এর সংক্রান্ত কোডটি চালু করা হবে。