Microsoft® Visual Basic® Scripting Edition Äڵ忡 ÀÇÇÑ ·çÇÁ ó¸® |
VBScript ÀÚ½À¼ ÀÌÀü ÆäÀÌÁö| ´ÙÀ½ ÆäÀÌÁö |
·çÇÁ¸¦ »ç¿ëÇϸé ÀÏ´ÜÀÇ ¸í·É¹®µéÀ» ¹Ýº¹ÇÏ¿© ½ÇÇàÇÒ ¼ö ÀÖ½À´Ï´Ù. ·çÇÁ¿¡ µû¶ó¼ Á¶°Ç¹®ÀÌ False°¡ µÉ ¶§±îÁö ¶Ç´Â True°¡ µÉ ¶§±îÁö ¸í·É¹®À» ¹Ýº¹ÇÏ¿© ½ÇÇàÇÕ´Ï´Ù. ¶Ç ¸í·É¹®À» ƯÁ¤ Ƚ¼ö¸¸Å ¹Ýº¹ÇÏ¿© ½ÇÇàÇÏ´Â ·çÇÁµµ ÀÖ½À´Ï´Ù.VBScript¿¡¼ »ç¿ëÇÒ ¼ö ÀÖ´Â ·çÇÁ¹®Àº ¾Æ·¡¿Í °°½À´Ï´Ù.
- Do...Loop: Á¶°Ç¹®ÀÌ True°¡ µÉ ¶§±îÁö ¶Ç´Â TrueÀÎ µ¿¾È ¹Ýº¹ ½ÇÇàÇÕ´Ï´Ù.
- While...Wend: Á¶°Ç¹®ÀÌ TrueÀÎ µ¿¾È ¹Ýº¹ ½ÇÇàÇÕ´Ï´Ù.
- For...Next: Ä«¿îÅ͸¦ »ç¿ëÇÏ¿© ÁöÁ¤ÇÑ È½¼ö¸¸Å ¸í·É¹®À» ¹Ýº¹ ½ÇÇàÇÕ´Ï´Ù.
- For Each...Next: Ä÷º¼ÇÀÇ °¢ Ç׸ñÀ̳ª ¹è¿ÀÇ °¢ ¿ä¼Ò¿¡ µû¶ó¼ ÀÏ´ÜÀÇ ¸í·É¹®À» ¹Ýº¹ ½ÇÇàÇÕ´Ï´Ù.
Do...Loop¹®À» »ç¿ëÇϸé ÇÑ ºí·ÏÀÇ ¸í·É¹®À» ¹«ÇÑÇÏ°Ô ½ÇÇàÇÒ ¼ö ÀÖ½À´Ï´Ù. Á¶°Ç¹®ÀÌ TrueÀÎ µ¿¾È ¶Ç´Â True°¡ µÉ ¶§±îÁö ¸í·É¹®À» ¹Ýº¹ÇÕ´Ï´Ù.Á¶°Ç¹®ÀÌ TrueÀÎ µ¿¾È ¸í·É¹®À» ¹Ýº¹ ½ÇÇà
While Å°¿öµå¸¦ »ç¿ëÇÏ¿© Do...Loop¹®ÀÇ Á¶°ÇÀ» °Ë»çÇÕ´Ï´Ù. ¾Æ·¡ ChkFirstWhile ¿ë·Êó·³ ·çÇÁ·Î µé¾î °¡±â Àü¿¡ ¶Ç´Â ChkLastWhile ¿ë·Êó·³ ·çÇÁ¸¦ Àû¾îµµ ÇÑ ¹ø ½ÇÇàÇÑ ÈÄ¿¡ Á¶°ÇÀ» °Ë»çÇÒ ¼ö ÀÖ½À´Ï´Ù. ChkFirstWhile ÇÁ·Î½ÃÀú¿¡¼´Â myNumÀ» 20 ´ë½Å¿¡ 9·Î ÁöÁ¤ÇÏ¸é ·çÇÁ ¾È¿¡ ÀÖ´Â ¸í·É¹®Àº °áÄÚ ½ÇÇàµÇÁö ¾ÊÁö¸¸, ChkLastWhile ÇÁ·Î½ÃÀú¿¡¼´Â ÇØ´ç Á¶°ÇÀÌ ÀÌ¹Ì FalseÀ̹ǷΠ·çÇÁ ¾È¿¡ ÀÖ´Â ¸í·É¹®ÀÌ ÇÑ ¹ø¸¸ ½ÇÇàµË´Ï´Ù.Sub ChkFirstWhile() Dim counter, myNum counter = 0 myNum = 20 Do While myNum > 10 myNum = myNum - 1 counter = counter + 1 Loop MsgBox "·çÇÁ¸¦ " & counter & "¹ø ¹Ýº¹ÇÏ¿´½À´Ï´Ù." End Sub Sub ChkLastWhile() Dim counter, myNum counter = 0 myNum = 9 Do myNum = myNum - 1 counter = counter + 1 Loop While myNum > 10 MsgBox "·çÇÁ¸¦ " & counter & "¹ø ¹Ýº¹ÇÏ¿´½À´Ï´Ù." End SubÁ¶°ÇÀÌ True°¡ µÉ ¶§±îÁö ¸í·É¹®À» ¹Ýº¹ ½ÇÇà
µÎ °¡Áö ¹æ½ÄÀ¸·Î Until Å°¿öµå¸¦ »ç¿ëÇÏ¿© Do...Loop¹®ÀÇ Á¶°ÇÀ» °Ë»çÇÕ´Ï´Ù. ¾Æ·¡ ChkFirstUntil ¿ë·Êó·³ ·çÇÁ·Î µé¾î °¡±â Àü¿¡ ¶Ç´Â ChkLastUntil ¿ë·Êó·³ ·çÇÁ¸¦ Àû¾îµµ ÇÑ ¹ø ½ÇÇàÇÑ ´ÙÀ½ Á¶°ÇÀ» °Ë»çÇÒ ¼ö ÀÖ½À´Ï´Ù. Á¶°ÇÀÌ FalseÀÎ µ¿¾È ¹Ýº¹ ½ÇÇàµË´Ï´Ù.Sub ChkFirstUntil() Dim counter, myNum counter = 0 myNum = 20 Do Until myNum = 10 myNum = myNum - 1 counter = counter + 1 Loop MsgBox "·çÇÁ¸¦ " & counter & "¹ø ¹Ýº¹ÇÏ¿´½À´Ï´Ù." End Sub Sub ChkLastUntil() Dim counter, myNum counter = 0 myNum = 1 Do myNum = myNum + 1 counter = counter + 1 Loop Until myNum = 10 MsgBox "·çÇÁ¸¦ " & counter & "¹ø ¹Ýº¹ÇÏ¿´½À´Ï´Ù." End Sub·çÇÁ ¾È¿¡¼ Do...Loop¹® ³¡³»±â
Exit Do¹®À» »ç¿ëÇÏ¿© Do...Loop¹®À» ºüÁ® ³ª°¥ ¼ö ÀÖ½À´Ï´Ù. ¹«ÇÑ ·çÇÁ¸¦ ÇÇÇÏ´Â °Íó·³ ´ë°³ ¾î¶² »óȲ¿¡¼¸¸ ºüÁ® ³ª°¡·Á°í ÇϹǷΠExit Do¹®Àº If...Then...Else¹®ÀÇ True ºí·Ï¹®¿¡¼ »ç¿ëÇØ¾ß ÇÕ´Ï´Ù. Á¶°Ç¹®ÀÌ FalseÀÎ µ¿¾È¿¡´Â ·çÇÁ¸¦ º¯ÇÔ¾øÀÌ ½ÇÇàÇÕ´Ï´Ù.¾Æ·¡ ¿ë·Ê¿¡¼ myNumÀº ¹«ÇÑ ·çÇÁ¸¦ ¸¸µå´Â °ªÀ¸·Î ÁöÁ¤µÇ¾ú½À´Ï´Ù. If...Then...Else¹®Àº ÀÌ Á¶°ÇÀ» °Ë»çÇÏ¿© ¹«ÇÑÇÏ°Ô ¹Ýº¹ÇÏ¿© ½ÇÇàÇÏÁö ¾Êµµ·Ï ÇÕ´Ï´Ù.
Sub ExitExample() Dim counter, myNum counter = 0 myNum = 9 Do Until myNum = 10 myNum = myNum - 1 counter = counter + 1 If myNum < 10 Then Exit Do Loop MsgBox "·çÇÁ´Â " & counter & "¹ø ¹Ýº¹ÇÏ¿´½À´Ï´Ù." End Sub
VBScript¿¡¼´Â ±× »ç¿ë¿¡ Àͼ÷ÇÑ »ç¿ëÀÚ¸¦ À§ÇØ While...Wend¹®À» Á¦°øÇÏ°í ÀÖ½À´Ï´Ù. ±×·¯³ª While...Wend¹®Àº À¯¿¬¼ºÀÌ ºÎÁ·ÇϹǷΠ±× ´ë½Å Do...Loop¹®À» »ç¿ëÇÏ´Â °ÍÀÌ ÁÁ½À´Ï´Ù.
For...Next¹®À» »ç¿ëÇϸé ƯÁ¤ Ƚ¼ö¸¸Å ÇÑ ºí·ÏÀÇ ¸í·É¹®À» ½ÇÇàÇÒ ¼ö ÀÖ½À´Ï´Ù. For ·çÇÁ´Â ·çÇÁ¸¦ ¹Ýº¹ÇÒ ¶§¸¶´Ù ±× °ªÀÌ Áõ°¨ÇÏ´Â Ä«¿îÅÍ º¯¼ö¸¦ »ç¿ëÇÕ´Ï´Ù.¿¹¸¦ µé¾î, ¾Æ·¡ ÇÁ·Î½ÃÀú´Â MyProc ÇÁ·Î½ÃÀú¸¦ 50ȸ ¹Ýº¹Çϵµ·Ï ÇÕ´Ï´Ù. For¹®¿¡¼ Ä«¿îÅÍ º¯¼ö x¿Í ±× ½ÃÀÛ°ú ³¡ °ªÀ» ÁöÁ¤ÇÕ´Ï´Ù. Next¹®¿¡¼´Â Ä«¿îÅÍ º¯¼öÀÇ °ªÀ» Çϳª¾¿ Áõ°¡½Ãŵ´Ï´Ù.
Step Å°¿öµå¸¦ »ç¿ëÇϸé Ä«¿îÅÍ º¯¼ö °ªÀ» ÁöÁ¤ÇÑ °ª¸¸Å¾¿ Áõ°¨½Ãų ¼ö ÀÖ½À´Ï´Ù. ¾Æ·¡ ¿ë·Ê¿¡¼ ·çÇÁ¸¦ ÇÑ ¹ø¾¿ ¹Ýº¹ÇÒ ¶§¸¶´Ù Ä«¿îÅÍ º¯¼ö j´Â 2¸¸Å¾¿ Áõ°¡ÇÕ´Ï´Ù. ·çÇÁ¸¦ ¸¶ÃÆÀ» ¶§ totalÀÇ °ªÀº 2, 4, 6, 8, 10ÀÇ ÇÕÀÌ µË´Ï´Ù.Sub DoMyProc50Times() Dim x For x = 1 To 50 MyProc Next End SubÄ«¿îÅÍ º¯¼öÀÇ °ªÀ» °¨¼Ò½ÃÅ°·Á¸é À½¼öÀÎ Step °ªÀ» »ç¿ëÇÕ´Ï´Ù. ³¡ °ªÀ» ½ÃÀÛ °ªº¸´Ù ÀÛ°Ô ÁöÁ¤ÇØ¾ß ÇÕ´Ï´Ù. ¾Æ·¡ ¿ë·Ê¿¡¼ ·çÇÁ¸¦ ÇÑ ¹ø¾¿ ¹Ýº¹ÇÒ ¶§¸¶´Ù Ä«¿îÅÍ º¯¼ö myNumÀº 2¸¸Å¾¿ °¨¼ÒÇÕ´Ï´Ù. ·çÇÁ¸¦ ¸¶ÃÆÀ» ¶§ totalÀÇ °ªÀº 16, 14, 12, 10, 8, 6, 4 , 2ÀÇ ÇÕÀÌ µË´Ï´Ù.Sub TwosTotal() Dim j, total For j = 2 To 10 Step 2 total = total + j Next MsgBox "ÃÑ " & total & "ÀÔ´Ï´Ù." End Sub
Exit For¹®À» »ç¿ëÇϸé Ä«¿îÅÍ º¯¼ö°¡ ³¡ °ª¿¡ µµ´ÞÇϱâ Àü¿¡ For...Next¹®À» ºüÁ® ³ª°¥ ¼ö ÀÖ½À´Ï´Ù. ´ë°³ ¿À·ù°¡ ¹ß»ýÇÏ´Â °Íó·³ ¾î¶² ƯÁ¤ »óȲ¿¡¼ ·çÇÁ¸¦ ºüÁ® ³ª°¡·Á°í ÇϹǷΠExit For¹®Àº If...Then...Else¹®ÀÇ True ºí·Ï¹®¿¡¼ »ç¿ëÇØ¾ß ÇÕ´Ï´Ù. Á¶°Ç¹®ÀÌ FalseÀÎ µ¿¾È¿¡´Â ·çÇÁ¸¦ º¯ÇÔ¾øÀÌ ½ÇÇàÇÕ´Ï´Ù.Sub NewTotal() Dim myNum, total For myNum = 16 To 2 Step -2 total = total + myNum Next MsgBox "ÃÑ " & total & "ÀÔ´Ï´Ù." End Sub
For Each...Next ·çÇÁ´Â For...Next ·çÇÁ¿Í ºñ½ÁÇÕ´Ï´Ù. ÁöÁ¤ÇÑ È½¼ö¸¸Å ¸í·É¹®À» ¹Ýº¹ ½ÇÇàÇÏ´Â ´ë½Å For Each...Next ·çÇÁ´Â Ä÷º¼ÇÀÇ °¢ Ç׸ñÀ̳ª ¹è¿ÀÇ °¢ ¿ä¼Ò¿¡ µû¶ó¼ ¸í·É¹®À» ¹Ýº¹ÇÏ¿© ½ÇÇàÇÕ´Ï´Ù. Ä÷º¼ÇÀÇ ¿ä¼Ò °³¼ö¸¦ ¾Ë ¼ö ¾ø´Â °æ¿ì¿¡ ƯÈ÷ À¯¿ëÇÕ´Ï´Ù.¾Æ·¡ HTML ÄÚµå ¿ë·Ê¿¡¼´Â Dictionary °³Ã¼ÀÇ ³»¿ëÀÌ ¿©·¯ °³ÀÇ ÀԷ¶õÀÇ ÅؽºÆ®¸¦ ä¿ì´Â µ¥ »ç¿ëµË´Ï´Ù.
<HTML> <HEAD><TITLE>Æû°ú ¿ä¼Ò</TITLE></HEAD> <SCRIPT LANGUAGE="VBScript"> <!-- Sub cmdChange_OnClick Dim d 'º¯¼ö¸¦ ÀÛ¼ºÇÕ´Ï´Ù. Set d = CreateObject("Scripting.Dictionary") d.Add "0", "Athens" 'Å°¿Í Ç׸ñÀ» Ãß°¡ÇÕ´Ï´Ù. d.Add "1", "Belgrade" d.Add "2", "Cairo" For Each I in d Document.frmForm.Elements(I).Value = D.Item(I) Next End Sub --> </SCRIPT> <BODY> <CENTER> <FORM NAME="frmForm" <Input Type = "Text"><p> <Input Type = "Text"><p> <Input Type = "Text"><p> <Input Type = "Text"><p> <Input Type = "Button" NAME="cmdChange" VALUE="¿©±â¸¦ Ŭ¸¯ÇϽʽÿÀ."><p> </FORM> </CENTER> </BODY> </HTML>