ユーザ用ツール

サイト用ツール


it技術:vb2clr

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン前のリビジョン
it技術:vb2clr [2026/01/30 17:51] – [テキストファイルの書込み] yajuadminit技術:vb2clr [2026/01/30 17:53] (現在) – [テキストファイルの読込み] yajuadmin
行 202: 行 202:
  
 ==== テキストファイルの読込み ==== ==== テキストファイルの読込み ====
 +=== StreamReader ===
 <code vb> <code vb>
 Sub filetextReader()  Sub filetextReader() 
行 239: 行 240:
 </code> </code>
  
 +=== ReadAllText ===
 +<code vb>
 +Public Function ReadFile() As Variant
 +
 +    Dim host As New CLRHost
 +    host.Initialize False
 +
 +    host.CLRLoadAssembly ("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
 +
 +    Dim filetype As mscorlib.Type
 +    Set filetype = host.CLRResolveType("System.IO.File")
 +    Dim encType As mscorlib.Type
 +    Set encType = host.CLRResolveType("System.Text.Encoding")
 +    Dim enc As mscorlib.Object
 +    Set enc = host.CLRInvokeStaticMethod(encType, "GetEncoding", "Shift_JIS")
 +    
 +    ' パス
 +    Dim path As String
 +    path = ThisWorkbook.path & "\SJISText.txt"
 +
 +    ' File.ReadAllText(path) を呼ぶ(静的メソッド)
 +    Dim text As Variant
 +    text = host.CLRInvokeStaticMethod(filetype, "ReadAllText", path, enc)
 +    
 +    ReadFile = CStr(text)
 +
 +    Set host = Nothing
 +
 +End Function
 +</code>
 ==== emfファイルをpngファイルに変換 ==== ==== emfファイルをpngファイルに変換 ====
 <code vb> <code vb>
it技術/vb2clr.txt · 最終更新: 2026/01/30 17:53 by yajuadmin