Skip to content

Instantly share code, notes, and snippets.

@taka2
Created October 20, 2009 12:01
Show Gist options
  • Select an option

  • Save taka2/214207 to your computer and use it in GitHub Desktop.

Select an option

Save taka2/214207 to your computer and use it in GitHub Desktop.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<title>VB.NET実行</title>
<style type = "text/css">
#btnExec
{
width: 200px;
height: 30px;
}
</style>
<script language = "VBScript">
Sub Window_onLoad
window.resizeTo 650,680
End Sub
Sub btnExec_Click
' 各種オブジェクトの生成
Set wsh = CreateObject("WScript.Shell")
Set fs = CreateObject("Scripting.FileSystemObject")
' デスクトップフォルダの取得
strDesktopFolder = wsh.SpecialFolders("Desktop")
strSourceFile = strDesktopFolder & "\\Test.vb"
strExecutableFile = strDesktopFolder & "\\Test.exe"
' ソースファイルを保存
Set ts = fs.CreateTextFile(strSourceFile)
ts.Write(document.form1.source.value)
ts.Close()
' コンパイル
Dim vbcExePath
vbcExePath = getVbcExePath()
Set oExec = wsh.Exec(vbcExePath & " /out:""" & strExecutableFile & """ """ & strSourceFile & """")
Do While oExec.Status = 0
idTimer = window.setTimeout("PausedSection", 100, "VBScript")
Loop
' コンパイル結果の表示
compileMessage = ""
While oExec.StdOut.AtEndOfStream = False
msg = oExec.StdOut.ReadLine()
compileMessage = compileMessage & msg & vbCrLf
Wend
document.form1.compiler_message.value = compileMessage
' 実行
If fs.FileExists(strExecutableFile) Then
wsh.Run """" & strExecutableFile & """", 10, True
End If
' ファイル削除
fs.DeleteFile(strSourceFile)
If fs.FileExists(strExecutableFile) Then
fs.DeleteFile(strExecutableFile)
End If
End Sub
Sub PausedSection
window.clearTimeout(idTimer)
End Sub
Function getVbcExePath
DOTNET_FOLDER_PATH = "C:\WINDOWS\Microsoft.NET\Framework"
Set fs = CreateObject("Scripting.FileSystemObject")
Set objDotnetFolder = fs.GetFolder(DOTNET_FOLDER_PATH)
For Each objFolder In objDotnetFolder.SubFolders
If Left(objFolder.Name, 1) = "v" Then
If fs.FileExists(objFolder.Path & "\vbc.exe") Then
vbcPath = objFolder.Path & "\vbc.exe"
End If
End If
Next
getVbcExePath = vbcPath
End Function
</script>
</head>
<body>
<form name = "form1">
<p>
ソースコード:<br>
<textarea name = "source" cols = "80" rows = "25">
Imports System
Class Test
Public Shared Sub Main()
Try
' ここにコードを書く
Console.WriteLine("Hello, VB.NET World!")
Catch ex As Exception
Console.WriteLine(ex)
Finally
Console.WriteLine("Enterを押下してプログラムを終了してください。")
Console.ReadLine()
End Try
End Sub
End Class
</textarea>
<p>
<input id = "btnExec" type = "button" name = "btnExec" value = "実行" onClick = "btnExec_Click">
</p>
</p>
<p>
コンパイラメッセージ:<br>
<textarea name = "compiler_message" cols = "80" rows = "10" readonly>
</textarea>
</p>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment