وی بی اسکریپت شرطی جملات
- پچھلے پیج وی بی پروگرام
- آئندہ پیج وی بی حلقة
مثال
- If...then..else 语句
- ایسائی نمائش کی وضاحت کی گئی ہے کہ کس طرح if...then..else کو لکھا جائے۔
- If...then..elseif 语句
- ایسائی نمائش کی وضاحت کی گئی ہے کہ کس طرح if...then...elseif... کو لکھا جائے۔
- Select case 语句
- 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 complete 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 code sets, you can use this statement.
- if...then...elseif statement
- If you want to execute one of the code sets, you can use this statement.
- Select case statement
- If you want to execute one of the code sets, 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 ਹੋਣ ਉੱਤੇ ਕਿਸੇ ਵਾਕੀਅਨ ਨੂੰ ਚਲਾਉਣਾ ਚਾਹੁੰਦੇ ਹੋ ਅਤੇ ਸਿਧਾਂਤ ਨਹੀਂ ਹੋਣ ਉੱਤੇ ਦੂਜੇ ਵਾਕੀਅਨ ਨੂੰ ਚਲਾਉਣਾ ਚਾਹੁੰਦੇ ਹੋ, ਤਾਂ "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
假如你希望选择多套代码之一来执行,可以使用 SELECT 语句:
select case payment case "Cash" msgbox "آپ نقد سے ادائیگی کریں گے" case "Visa" msgbox "آپ وائس سے ادائیگی کریں گے" case "AmEx" msgbox "آپ امریکن ایکسپریس سے ادائیگی کریں گے" case Else msgbox "نا معلوم ادائیگی کا طریقہ" اند سیکلیپٹ
مذکورہ کوڈ کا کام کا طریقہ: ابتدا میں، ہمیں ایک سادا ایکسیپریشن (چھوٹی پروگرام کا ایک متغیر کی طرح) کی ضرورت ہوتی ہے، جس کا ایک بار ملاحظہ کیا جائے گا۔ بعد میں، ایکسیپریشن کا ملاحظہ کیا جانے والا ملاحظہ کی جائے گا، جس کا ملاحظہ کیا جانا چاہئے، اگر میچ کیا جائے تو میچ کی جائے والی کیج کا کاود کا کوئی کاود کو چلایا جائے گا۔
- پچھلے پیج وی بی پروگرام
- آئندہ پیج وی بی حلقة