VBScript.md
... ...
@@ -13,126 +13,123 @@
13 13
14 14
# 連想配列
15 15
16
-~[Dictionary オブジェクト](http://msdn.microsoft.com/library/ja/default.asp?url=/library/ja/script56/html/jsobjdictionary.asp)が連想配列として使える。
17
-```vbscript
18
- <%@ language="VBScript" %>
19
- <%
20
- ' HashTable.asp
21
- Dim HashTable
22
- Set HashTable = CreateObject("Scripting.Dictionary")
23
- HashTable.add "key1", "value1"
24
- HashTable.Item("key2") = "value2"
25
-
26
- Response.ContentType = "text/plain"
27
- Response.Charset = "Shift_JIS"
28
- Response.Expires = -1
29
-
30
- Response.write "key1: " & HashTable.Item("key1") & vbCRLF
31
- Response.write "key2: " & HashTable.Item("key2") & vbCRLF
32
- %>
33
-```
34
-
35
-~ 既に存在するキーに対して、addメソッドを使うとエラーとなるが、Itemプロパティを使った場合には警告なく置き換えられる。
16
+- [Dictionary オブジェクト](http://msdn.microsoft.com/library/ja/default.asp?url=/library/ja/script56/html/jsobjdictionary.asp)が連想配列として使える。
17
+ ```visualbasic
18
+ <%@ language="VBScript" %>
19
+ <%
20
+ ' HashTable.asp
21
+ Dim HashTable
22
+ Set HashTable = CreateObject("Scripting.Dictionary")
23
+ HashTable.add "key1", "value1"
24
+ HashTable.Item("key2") = "value2"
25
+
26
+ Response.ContentType = "text/plain"
27
+ Response.Charset = "Shift_JIS"
28
+ Response.Expires = -1
29
+
30
+ Response.write "key1: " & HashTable.Item("key1") & vbCRLF
31
+ Response.write "key2: " & HashTable.Item("key2") & vbCRLF
32
+ %>
33
+ ```
34
+
35
+- 既に存在するキーに対して、addメソッドを使うとエラーとなるが、Itemプロパティを使った場合には警告なく置き換えられる。
36 36
37 37
# 環境変数
38 38
39
-~環境変数を読み出すには[Requestオブジェクト](http://msdn.microsoft.com/library/ja/default.asp?url=/library/ja/jpiis/iishelp/iis/htm/asp/vbob5ulw.asp)の[ServerVariablesコレクション](http://msdn.microsoft.com/library/ja/default.asp?url=/library/ja/jpiis/iishelp/iis/htm/asp/vbob5vsj.asp)を読み出せばよい。
40
-```vbscript
41
- Browser = Request.ServerVariables ( "HTTP_USER_AGENT" )
42
-
43
- <html>
44
- <%@ language="VBScript" %>
45
- <!-- printEnv.asp -->
46
- <body>
47
- <table border="1">
48
- <tr><th>Server Variable</th><th>Value</th></tr>
49
- <% For Each strKey In Request.ServerVariables %>
50
- <tr><td><%= strKey %></td><td><%= Request.ServerVariables(strKey) %></td></tr>
51
- <% Next %>
52
- </table>
53
- </body>
54
- </html>
55
-```
39
+- 環境変数を読み出すには[Requestオブジェクト](http://msdn.microsoft.com/library/ja/default.asp?url=/library/ja/jpiis/iishelp/iis/htm/asp/vbob5ulw.asp)の[ServerVariablesコレクション](http://msdn.microsoft.com/library/ja/default.asp?url=/library/ja/jpiis/iishelp/iis/htm/asp/vbob5vsj.asp)を読み出せばよい。
40
+ ```visualbasic
41
+ Browser = Request.ServerVariables ( "HTTP_USER_AGENT" )
42
+
43
+ <html>
44
+ <%@ language="VBScript" %>
45
+ <!-- printEnv.asp -->
46
+ <body>
47
+ <table border="1">
48
+ <tr><th>Server Variable</th><th>Value</th></tr>
49
+ <% For Each strKey In Request.ServerVariables %>
50
+ <tr><td><%= strKey %></td><td><%= Request.ServerVariables(strKey) %></td></tr>
51
+ <% Next %>
52
+ </table>
53
+ </body>
54
+ </html>
55
+ ```
56 56
57 57
# FileSystemObjectオブジェクト
58 58
59
-[FileSystemObjectオブジェクト](http://msdn.microsoft.com/library/ja/default.asp?url=/library/ja/script56/html/fsooriScriptingRun-TimeReference.asp)
59
+- [FileSystemObjectオブジェクト](http://msdn.microsoft.com/library/ja/default.asp?url=/library/ja/script56/html/fsooriScriptingRun-TimeReference.asp)
60 60
61 61
# Webからのダウンロード
62 62
63
-~ [IXMLHTTPRequestオブジェクト](http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/7924f6be-c035-411f-acd2-79de7a711b38.asp)を使って、指定したURIをダウンロードして表示する。
64
-
65
-```
66
-TinyProxy.asp?URI=http://xxx〜
67
-```
68
-
69
-~ charsetを返さないサーバに対して使用すると文字化けする。
70
-
71
-```vbscript
72
- <%@ language="VBScript" %>
73
- <!-- #include File="adovbs.inc" -->
74
- <%
75
- ' TinyProxy.asp
76
-
77
- Response.ContentType = "text/html"
78
- Response.Charset = "Shift_JIS"
79
- Response.Expires = -1
80
-
81
- Dim sHTML
82
-
83
- sHTML = getURL( Request.QueryString("URI") )
84
-
85
- Response.Write sHTML
86
-
87
- ''''''''
88
-
89
- Function getURL( sURL )
90
- Dim oXMLHTTP, sHTML, sEncoding
91
- Set oXMLHTTP = Server.CreateObject("MSXML2.XMLHTTP")
92
-
93
- oXMLHTTP.Open "GET", sURL, False
94
- oXMLHTTP.Send
95
- sHTML = oXMLHTTP.responseBody
96
- sEncoding = oXMLHTTP.getResponseHeader("Content-type")
97
-
98
- Dim oRegExp
99
- Set oRegExp = New RegExp
100
- oRegExp.Pattern = ".*\s*charset=(.*)\s*"
101
- oRegExp.IgnoreCase = True
102
- oRegExp.Global = True
103
- If oRegExp.Test(sEncoding) Then
104
- sEncoding = oRegExp.Replace( sEncoding, "$1" )
105
- Else
106
- sEncoding = "Shift_JIS"
107
- End If
108
- Set oRegExp = Nothing
109
-
110
- Dim oStream
111
- Set oStream = Server.CreateObject("ADODB.Stream")
112
- oStream.Open
113
- oStream.Type = adTypeBinary
114
- oStream.Write sHTML
115
- oStream.Position = 0
116
- oStream.Type = adTypeText
117
- oStream.Charset = sEncoding
118
- getURL = oStream.ReadText()
119
- oStream.Close
120
- Set oStream = Nothing
121
-
122
- Set oXMLHTTP = Nothing
123
- End Function
124
- %>
125
-```
126
-
127
-~ (参考) ダウンロードしたHTMLを加工しない場合
128
-```vbscript
129
- Dim oXMLHTTP
130
- Set oXMLHTTP = Server.CreateObject("MSXML2.XMLHTTP")
131
-
132
- oXMLHTTP.Open "GET", sURL, False
133
- oXMLHTTP.Send
134
- Response.BinaryWrite oXMLHTTP.responseBody
135
-```
63
+- [IXMLHTTPRequestオブジェクト](http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/7924f6be-c035-411f-acd2-79de7a711b38.asp)を使って、指定したURIをダウンロードして表示する。
64
+
65
+ ```
66
+ TinyProxy.asp?URI=http://xxx〜
67
+ ```
68
+
69
+- charsetを返さないサーバに対して使用すると文字化けする。
70
+ ```visualbasic
71
+ <%@ language="VBScript" %>
72
+ <!-- #include File="adovbs.inc" -->
73
+ <%
74
+ ' TinyProxy.asp
75
+
76
+ Response.ContentType = "text/html"
77
+ Response.Charset = "Shift_JIS"
78
+ Response.Expires = -1
79
+
80
+ Dim sHTML
81
+ sHTML = getURL( Request.QueryString("URI") )
82
+ Response.Write sHTML
83
+
84
+ ''''''''
85
+
86
+ Function getURL( sURL )
87
+ Dim oXMLHTTP, sHTML, sEncoding
88
+ Set oXMLHTTP = Server.CreateObject("MSXML2.XMLHTTP")
89
+
90
+ oXMLHTTP.Open "GET", sURL, False
91
+ oXMLHTTP.Send
92
+ sHTML = oXMLHTTP.responseBody
93
+ sEncoding = oXMLHTTP.getResponseHeader("Content-type")
94
+
95
+ Dim oRegExp
96
+ Set oRegExp = New RegExp
97
+ oRegExp.Pattern = ".*\s*charset=(.*)\s*"
98
+ oRegExp.IgnoreCase = True
99
+ oRegExp.Global = True
100
+ If oRegExp.Test(sEncoding) Then
101
+ sEncoding = oRegExp.Replace( sEncoding, "$1" )
102
+ Else
103
+ sEncoding = "Shift_JIS"
104
+ End If
105
+ Set oRegExp = Nothing
106
+
107
+ Dim oStream
108
+ Set oStream = Server.CreateObject("ADODB.Stream")
109
+ oStream.Open
110
+ oStream.Type = adTypeBinary
111
+ oStream.Write sHTML
112
+ oStream.Position = 0
113
+ oStream.Type = adTypeText
114
+ oStream.Charset = sEncoding
115
+ getURL = oStream.ReadText()
116
+ oStream.Close
117
+ Set oStream = Nothing
118
+
119
+ Set oXMLHTTP = Nothing
120
+ End Function
121
+ %>
122
+ ```
123
+
124
+- (参考) ダウンロードしたHTMLを加工しない場合
125
+ ```visualbasic
126
+ Dim oXMLHTTP
127
+ Set oXMLHTTP = Server.CreateObject("MSXML2.XMLHTTP")
128
+
129
+ oXMLHTTP.Open "GET", sURL, False
130
+ oXMLHTTP.Send
131
+ Response.BinaryWrite oXMLHTTP.responseBody
132
+ ```
136 133
137 134
- [WSHで作るRSSアグリゲータ](http://signal9.exblog.jp/1537443)
138 135
... ...
@@ -161,7 +158,7 @@ TinyProxy.asp?URI=http://xxx〜
161 158
- [Java:CSVパーサを作る(その2) - RFC4180対応 前編: 愛ゆえにプログラムは美しい](http://endeavour.cocolog-nifty.com/developer_room/2008/06/javacsv_389b.html) K3フォーマットについて
162 159
163 160
SaveAsK3.bas
164
-```vbscript
161
+```visualbasic
165 162
Attribute VB_Name = "Module1"
166 163
Private Const g_cnsDQ = """"
167 164
Private Const g_cnsSQ = "'"
... ...
@@ -248,7 +245,7 @@ SaveAsK3.bas
248 245
```
249 246
250 247
ThisWorkbook.cls
251
-```vbscript
248
+```visualbasic
252 249
VERSION 1.0 CLASS
253 250
BEGIN
254 251
MultiUse = -1 'True
... ...
@@ -295,7 +292,7 @@ ThisWorkbook.cls
295 292
# 正規表現にマッチする部分を強調するアドイン
296 293
- [HighlightRegEx.zip](HighlightRegEx.zip)
297 294
- HighlightRegEx.bas
298
-```vbscript
295
+```visualbasic
299 296
Attribute VB_Name = "Module1"
300 297
Private Const defaultPattern = "\*[^\*]+\*"
301 298
... ...
@@ -334,7 +331,7 @@ Sub HighlightRegEx()
334 331
End Sub
335 332
```
336 333
- HighlightRegEx.cls
337
-```vbscript
334
+```visualbasic
338 335
VERSION 1.0 CLASS
339 336
BEGIN
340 337
MultiUse = -1 'True
... ...
@@ -399,7 +396,7 @@ End Sub
399 396
- [Application.MacroOptions メソッド (Excel)](https://msdn.microsoft.com/ja-jp/vba/excel-vba/articles/application-macrooptions-method-excel)
400 397
401 398
# Excel VBA でプラットフォーム情報の取得
402
-```vbscript
399
+```visualbasic
403 400
Sub showPlatform()
404 401
Dim myOS As String
405 402
Dim myVer As String
... ...
@@ -416,7 +413,7 @@ End Sub
416 413
417 414
## ソース
418 415
- [LoadXML.zip](LoadXML.zip)
419
-```vbscript
416
+```visualbasic
420 417
Attribute VB_Name = "Module1"
421 418
' 初心者のための XML DOM ガイド
422 419
' http://msdn.microsoft.com/ja-jp/library/aa468547.asp
... ...
@@ -476,7 +473,7 @@ End Sub
476 473
477 474
## ソース
478 475
- [showTables.zip](showTables.zip)
479
-```vbscript
476
+```visualbasic
480 477
' Access ファイル中のテーブルを列挙する。
481 478
' http://hardsoft.at.webry.info/200908/article_6.html
482 479
' http://msdn.microsoft.com/en-us/library/windows/desktop/ms681520.aspx
... ...
@@ -563,4 +560,4 @@ ODBCでは読み取りに権限設定の変更が必要。
563 560
[[VBScript/Database]]を参照。
564 561
565 562
# Base64 エンコード/デコード
566
-[BASE64のサンプルコード](http://www.asahi-net.or.jp/~ai2h-ykmz/tech/base64vb.htm)
... ...
\ No newline at end of file
0
+[BASE64のサンプルコード](http://www.asahi-net.or.jp/~ai2h-ykmz/tech/base64vb.htm)