Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 在VisualStudio 2015中将Access VBA转换为Visual Basic_Vb.net_Vba_Philips Hue - Fatal编程技术网

Vb.net 在VisualStudio 2015中将Access VBA转换为Visual Basic

Vb.net 在VisualStudio 2015中将Access VBA转换为Visual Basic,vb.net,vba,philips-hue,Vb.net,Vba,Philips Hue,我有一个在Microsoft Access中创建的功能齐全的应用程序,我用它来控制我的飞利浦色调灯。它们通过使用JSON命令的RESTful接口进行操作,在VBA中创建代码非常简单。我想制作一个独立的Windows应用程序,这样我就可以在没有访问权限的计算机上运行它 我正试图使用Visual Studio 2015使用VB.net制作一个通用应用程序,但在转换部分代码时遇到问题。我能够修复大多数故障,但是我无法让winHttpReq命令工作。在我的研究中,听起来它们在VB.net中没有直接的相关

我有一个在Microsoft Access中创建的功能齐全的应用程序,我用它来控制我的飞利浦色调灯。它们通过使用JSON命令的RESTful接口进行操作,在VBA中创建代码非常简单。我想制作一个独立的Windows应用程序,这样我就可以在没有访问权限的计算机上运行它

我正试图使用Visual Studio 2015使用VB.net制作一个通用应用程序,但在转换部分代码时遇到问题。我能够修复大多数故障,但是我无法让winHttpReq命令工作。在我的研究中,听起来它们在VB.net中没有直接的相关性,但我发现的建议都不起作用

  Dim Result As String
  Dim MyURL As String, postData As String, strQuote As String
  Dim winHttpReq As Object
  winHttpReq = CreateObject("WinHttp.WinHttpRequest.5.1")

    'Create address and lamp
    MyURL = "http://" & IP.Text & "/api/" & Hex.Text & "/lights/" & "1" & "/state"
    postData = Code.Text

    winHttpReq.Open("PUT", MyURL, False)
    winHttpReq.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
    winHttpReq.Send(postData)
我得到的错误是没有声明“CreateObject”。由于其保护级别,可能无法访问。我对VB.net编码相当陌生,但所有关于替代发布方法的建议似乎都不起作用。如有任何建议,将不胜感激

在VB.Net中,使用:


查看System.Web名称空间新的.NET4.5+版本,谢谢,这绝对是正确的方向。我一直在摆弄它,但似乎找不到如何摆脱最后的错误代码GetResponse“”不是“WebRequest”的成员。未声明“Current”。由于其保护级别,可能无法访问。”控制台“”未声明。由于其保护级别,可能无法访问。”Close不是StreamReader的成员。“Close”不是WebResponse的成员。您需要为WebRequest导入System.Net,为Stream导入System.IO。
'Create address and lamp
MyURL = "http://" & IP.Text & "/api/" & Hex.Text & "/lights/" & "1" & "/state"
Dim request As WebRequest = WebRequest.Create(MyURL)
' Get the response.
Dim response As WebResponse = request.GetResponse()
' Display the status.
Console.WriteLine(CType(response,HttpWebResponse).StatusDescription)
' Get the stream containing content returned by the server.
Dim dataStream As Stream = response.GetResponseStream()
' Open the stream using a StreamReader for easy access.
Dim reader As New StreamReader(dataStream)
' Read the content.
Dim responseFromServer As String = reader.ReadToEnd()
' Display the content.
Console.WriteLine(responseFromServer)
' Clean up the streams and the response.
reader.Close()
response.Close()