ãããã®ãµã³ãã«ãªã©ã§ã¯ãã¾ãã«ä»¥ä¸ã®ãããªã¤ã³ãã³ãããã¦ããªãã³ã¼ããããã
Sub FizzBuzz() For i = 1 To 100 If i Mod 15 = 0 Then Debug.Print "FizzBuzz" ElseIf i Mod 3 = 0 Then Debug.Print "Fizz" ElseIf i Mod 5 = 0 Then Debug.Print "Buzz" Else Debug.Print i End If Next End Sub
ããã¯HTMLã§åç´ã«ã¿ããã¹ãã¼ã¹ãå ¥åãã¦ãåè§ã¹ãã¼ã¹ã²ã¨ã¤ã«ç½®ãæãã£ã¦ãã¾ãããã ã¨æãããã
å人ãµã¤ããªãHTMLã®ç¥èãããã°æ¹åã§ãããã®ã®ãå¤é¨ãµã¼ãã¹ã®æ©è½ã§ããã°ã©ããããããªãã
ä¾ãã°ãã¯ã¦ãªããã°ã®ã³ã¡ã³ãæ¬ã«ã¤ã³ãã³ãæãã®ã³ã¼ããå¼µãä»ãã¦ãã¤ã³ãã³ãã¯æ¶ãã¦ãã¾ãããæ²ç¤ºæ¿ãQAãµã¤ããªã©ã§ã対çãåããã¦ããªãå ´åã¯ã¤ã³ãã³ãããªããªãã
ã¾ããWebã§ãªãã¦ããè¤æ°äººãã¡ã³ããã³ã¹ãããã¯ãã¯ã¤ã³ãã³ããã¬ã¿ã¬ã¿ã«ãªã£ã¦ãããã¨ãããã
ä»åã¯ãããã³ã¼ãã§ãªãã¨ããããã¨ãã話ã
ã¾ãæããå
¥ãã¦ããã¨ãä»åã¯ããªããã£ã¤ãä»äºã§ãåé·ãªã³ã¼ãã«ãªã£ã¦ããã
ãã¸ãã¯ãèããéç¨ã§ç¶ºéºã«æ¸ããã¨ã¯èãããå¢ãã§ã¬ãªã¬ãªæ¸ãã¦ãªãã¨ãåãå½¢ã«ãã£ã¦ãã£ãã¨ããã¨ããã
ã³ã¼ã
使ãæ¹ã¯ãã¤ã³ãã³ãããã¦ããªãã³ã¼ãï¼ã¾ãã¯ã¬ã¿ã¬ã¿ã®ã³ã¼ãï¼ãã¯ãªãããã¼ãã«ã³ãã¼ãã¦ããã以ä¸ã®AutoIndenterãå®è¡ããã¨ãã¤ããã£ã¨ã¤ãã¦ã¤ã³ãã¦ã«æ´å½¢ãããã³ã¼ããåºã¦ãããã²ã¨ã¾ãä¸ã®FizzBuzzã§è©¦ãã¦ã¿ã¦ã»ããã
â»ä¸ã«ããã¦ããäºã¤ã®é¢æ°ãå¿
è¦
Sub AutoIndenter() Dim CB As New DataObject CB.GetFromClipboard If Not CB.GetFormat(1) Then MsgBox "ã¯ãªãããã¼ãã空ã§ãã", vbExclamation Exit Sub End If Dim Lines() As String: Lines = Split(CB.GetText, vbNewLine) For Each x In Lines x2 = ConvertString(x) If InStr(1, x2, "End Sub") > 0 Then T = 0 Debug.Print String(T, vbTab) & Trim(x) ElseIf InStr(1, x2, "Exit Sub") > 0 Then Debug.Print String(T, vbTab) & Trim(x) ElseIf InStr(1, x2, "Go Sub") > 0 Then Debug.Print String(T, vbTab) & Trim(x) ElseIf InStr(1, x2, "Sub ") > 0 Then Debug.Print Debug.Print String(T, vbTab) & Trim(x) T = 1 ElseIf InStr(1, x2, "End Function") > 0 Then T = 0 Debug.Print String(T, vbTab) & Trim(x) ElseIf InStr(1, x2, "Function ") > 0 Then Debug.Print Debug.Print String(T, vbTab) & Trim(x) T = 1 ElseIf InStr(1, x2, "For ") > 0 Then Debug.Print String(T, vbTab) & Trim(x) T = T + 1 ElseIf InStr(1, x2, "Next") > 0 Then T = T - 1 Debug.Print String(T, vbTab) & Trim(x) ElseIf InStr(1, x2, "Loop") > 0 Then T = T - 1 Debug.Print String(T, vbTab) & Trim(x) ElseIf InStr(1, x2, "Do") > 0 Then Debug.Print String(T, vbTab) & Trim(x) T = T + 1 ElseIf InStr(1, x2, "End With") > 0 Then T = T - 1 Debug.Print String(T, vbTab) & Trim(x) ElseIf InStr(1, x2, "With") > 0 Then Debug.Print String(T, vbTab) & Trim(x) T = T + 1 ElseIf InStr(1, x2, "End If") > 0 Then T = T - 1 Debug.Print String(T, vbTab) & Trim(x) ElseIf InStr(1, x2, "Else") > 0 Then T = T - 1 Debug.Print String(T, vbTab) & Trim(x) T = T + 1 ElseIf InStr(1, x2, "If ") > 0 Then Debug.Print String(T, vbTab) & Trim(x) T = T + 1 ElseIf Trim(x) <> "" Then Debug.Print String(T, vbTab) & Trim(x) End If Next End Sub Function ConvertString(ByVal x As String) As String ConvertString = x If InStr(1, x, """") > 0 Then If InStr(1, x, "'") > 0 Then If InStr(1, x, """") < InStr(1, x, "'") Then ConvertString = InnerConvertString(x) End If Else ConvertString = InnerConvertString(x) End If End If End Function Private Function InnerConvertString(x As String) As String Dim newstr As String Dim IsString As Boolean For i = 1 To Len(x) IsString = (Mid(x, i, 1) = """") Xor IsString If Not IsString Then newstr = newstr & Mid(x, i, 1) End If Next InnerConvertString = newstr End Function
æ´å½¢åºåãããFizzBuzz
Sub FizzBuzz() For i = 1 To 100 If i Mod 15 = 0 Then Debug.Print "FizzBuzz" ElseIf i Mod 3 = 0 Then Debug.Print "Fizz" ElseIf i Mod 5 = 0 Then Debug.Print "Buzz" Else Debug.Print i End If Next End Sub
課é¡
ã¨ãããããIfãForãDoæã«ã¯å¯¾å¿ãããããSelectæãªã©ã¯å¯¾å¿ãã¦ããªãããDoEventãDoã¨ééã£ã¦ãã¾ããªã©è²ã ã¨åé¡ã¯åãã§ãããã¾ãæã®ç©ºããã¨ãã«ã§ãæ£è¦è¡¨ç¾ã使ãå½¢ã«ç´ãããã¨æããã¾ããDebug.Printãã¾ã¨ããããããºã ããã¤ã³ãã³ããä¸ãã¦ããåºåããã±ã¼ã¹(End Ifãªã©)ã¨ãåºåãã¦ãã次ã®è¡ã«åãã¦ã¤ã³ãã³ããå¢ããã±ã¼ã¹(Ifãªã©)ãããããããããã£ãã®ã§ã¨ããããå ¨ç¶æ³å¤æã«Debug.Printãæ¸ãããå¤æ°å®£è¨ãå¿ è¦æä½éãããã¦ããªãã
ç´°é¨ã§ã¤ã¾ããã¦é·èã«é¥ãã¨ãæåã«æµ®ããã å ¨ä½ãã¸ãã¯ã®ã¢ã¤ãã¢ãé ããå¹ãé£ãã§ãã¾ããããåããããåæã§æå¾ã¾ã§æ¸ããã£ã¦ããæ´çããã¹ã¿ã³ã¹ã§ããã
ãªãã空è¡ã¯åé¤ããä»æ§ã«ãã¦ããããæå¾ã®ElseIfãElseã«æ¸ãæããã°ç©ºè¡ãåºåãããã
ã空è¡ç ´æ£ã
ElseIf Trim(x) <> "" Then Debug.Print String(T, vbTab) & Trim(x) End If Next End Sub
ã空è¡ãåºåã
Else Debug.Print String(T, vbTab) & Trim(x) End If Next End Sub
ã¾ããã³ã¼ãã¯æ±ããªãããç§ãã¡ã³ããããã£ãã³ã¼ãã«å¯¾ãã¦ã¯ãã¾ãåä½ããã®ã§ãç®çã¯éããã
ã¡ãã£ã¨ä»ã¯ãããæ¸ãç´ãæ°åã¯èµ·ããªãã®ã§ãã¾ãä»åº¦ã«ãããã¨æãã
â»ããå½¹ç«ã¡ãããªããèªç±ã«ã使ããã ããã