質問編集履歴
4
意図的に内容を抹消する行為にあたるため
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
PythonのコードをC#かVBに変換したい
|
body
CHANGED
@@ -1,7 +1,88 @@
|
|
1
|
+
PythonのコードをVBかC#に変換したいです。
|
2
|
+
目的は学習です。
|
3
|
+
Pythonコードは正常に動作している物で
|
1
|
-
|
4
|
+
VBコードは現在動作していない物です。
|
5
|
+
元のPythonコードと、私が書いたVBコードを載せます。
|
6
|
+
例外エラーなどは出ず処理は一応実行できますが、動作しない状況です。
|
7
|
+
私が書いたVBコードはどこが間違えているのかご教示願いたいです。
|
2
8
|
|
3
|
-
|
9
|
+
```Python
|
4
|
-
|
10
|
+
import requests
|
11
|
+
import json
|
12
|
+
# csvファイル取得
|
13
|
+
def get_csv(groupcodes, commandbytes):
|
14
|
+
url = 'http://192.168.14.100:7001/testapi/sendbroadcastcommand?groupcodes={}&commandbytes={}'. format(json.dumps(groupcodes), json.dumps(commandbytes))
|
15
|
+
print(url)
|
16
|
+
headers = {
|
17
|
+
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
|
18
|
+
}
|
19
|
+
try:
|
20
|
+
response = requests.post(url=url, headers=headers)
|
21
|
+
except Exception as e:
|
22
|
+
print("POST 例外発生!")
|
23
|
+
print(e)
|
24
|
+
return -1
|
25
|
+
if response.status_code != 200:
|
26
|
+
print("POST 応答エラー")
|
27
|
+
return -2
|
5
|
-
|
28
|
+
if __name__ == '__main__':
|
29
|
+
grcd1 = ['A','B']
|
30
|
+
cmdbyte1 = [4, 17, 0, 234]
|
31
|
+
try:
|
32
|
+
get_csv(grcd1, cmdbyte1)
|
33
|
+
except Exception as e01:
|
34
|
+
print("get_scv()の中に例外発生!")
|
35
|
+
print(e01)
|
36
|
+
```
|
6
|
-
|
37
|
+
```VB
|
38
|
+
Imports Newtonsoft.Json
|
39
|
+
Public Class Form1
|
40
|
+
Public Class testjson
|
7
|
-
|
41
|
+
Public Property groupcodes As String
|
42
|
+
Public Property commandbytes As String
|
43
|
+
'Public Property sikaku As String()
|
44
|
+
End Class
|
45
|
+
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
|
46
|
+
Dim ret As Int32
|
47
|
+
'Dim postData As String
|
48
|
+
Dim postDataBytes As Byte()
|
49
|
+
Dim req As System.Net.WebRequest
|
50
|
+
Dim reqStream As System.IO.Stream = Nothing
|
51
|
+
Dim res As System.Net.WebResponse = Nothing
|
52
|
+
Dim resStream As System.IO.Stream = Nothing
|
53
|
+
Dim sr As System.IO.StreamReader = Nothing
|
54
|
+
Try
|
55
|
+
Dim syain1 As testjson = New testjson()
|
56
|
+
syain1.groupcodes = "['A','B']"
|
57
|
+
syain1.commandbytes = "[4, 17, 0, 234]"
|
58
|
+
Dim Json As String = JsonConvert.SerializeObject(syain1)
|
59
|
+
'バイト型配列に変換
|
60
|
+
postDataBytes = System.Text.Encoding.UTF8.GetBytes(Json)
|
61
|
+
'WebRequestの作成
|
62
|
+
req = System.Net.WebRequest.Create("http://192.168.14.100:7001/testapi/sendbroadcastcommand")
|
63
|
+
'メソッドにPOSTを指定
|
64
|
+
req.Method = "POST"
|
65
|
+
'ContentTypeを"application/json"にする
|
66
|
+
req.ContentType = "application/json"
|
67
|
+
''POST送信するデータの長さを指定
|
68
|
+
req.ContentLength = postDataBytes.Length
|
69
|
+
req.Proxy = Nothing
|
70
|
+
'データをPOST送信するためのStreamを取得
|
71
|
+
reqStream = req.GetRequestStream()
|
72
|
+
'送信するデータを書き込む
|
73
|
+
reqStream.Write(postDataBytes, 0, postDataBytes.Length)
|
74
|
+
ret = 0
|
75
|
+
Catch ex As Exception
|
76
|
+
'エラーコードの設定
|
77
|
+
ret = 100
|
78
|
+
Finally
|
79
|
+
If IsNothing(reqStream) = False Then
|
80
|
+
reqStream.Close()
|
81
|
+
End If
|
82
|
+
If IsNothing(sr) = False Then
|
83
|
+
sr.Close()
|
84
|
+
End If
|
85
|
+
End Try
|
86
|
+
End Sub
|
87
|
+
End Class
|
88
|
+
```
|
3
削除希望
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
※※質問削除願います※※
|
body
CHANGED
@@ -1,10 +1,7 @@
|
|
1
|
-
PythonのコードをVBかC#に変換したいです。
|
2
|
-
目的は学習です。
|
3
|
-
Pythonコードは正常に動作している物で
|
4
|
-
|
1
|
+
回答得られない為、本質問は取りやめます。
|
5
|
-
元のPythonコードと、私が書いたVBコードを載せます。
|
6
|
-
例外エラーなどは出ず処理は一応実行できますが、動作しない状況です。
|
7
|
-
私が書いたVBコードはどこが間違えているのかご教示願いたいです。
|
8
2
|
|
9
3
|
|
4
|
+
|
5
|
+
※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
|
10
|
-
|
6
|
+
コード削除
|
7
|
+
※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
|
2
回答得られない為、コード削除します。
title
CHANGED
File without changes
|
body
CHANGED
@@ -7,108 +7,4 @@
|
|
7
7
|
私が書いたVBコードはどこが間違えているのかご教示願いたいです。
|
8
8
|
|
9
9
|
|
10
|
-
```Python
|
11
|
-
import requests
|
12
|
-
import json
|
13
|
-
|
14
|
-
# csvファイル取得
|
15
|
-
def get_csv(groupcodes, commandbytes):
|
16
|
-
url = 'http://192.168.14.100:7001/testapi/sendbroadcastcommand?groupcodes={}&commandbytes={}'. format(json.dumps(groupcodes), json.dumps(commandbytes))
|
17
|
-
print(url)
|
18
|
-
headers = {
|
19
|
-
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
|
20
|
-
}
|
21
|
-
try:
|
22
|
-
response = requests.post(url=url, headers=headers)
|
23
|
-
except Exception as e:
|
24
|
-
print("POST 例外発生!")
|
25
|
-
print(e)
|
26
|
-
return -1
|
27
|
-
|
28
|
-
if response.status_code != 200:
|
29
|
-
print("POST 応答エラー")
|
30
|
-
return -2
|
31
|
-
|
32
|
-
|
33
|
-
if __name__ == '__main__':
|
34
|
-
grcd1 = ['A','B']
|
35
|
-
cmdbyte1 = [4, 17, 0, 234]
|
36
|
-
|
37
|
-
|
38
|
-
try:
|
39
|
-
get_csv(grcd1, cmdbyte1)
|
40
|
-
except Exception as e01:
|
41
|
-
print("get_scv()の中に例外発生!")
|
42
|
-
print(e01)
|
43
|
-
|
44
|
-
```
|
45
|
-
|
46
|
-
```VB
|
47
|
-
Imports Newtonsoft.Json
|
48
|
-
|
49
|
-
Public Class Form1
|
50
|
-
|
51
|
-
Public Class testjson
|
52
|
-
Public Property groupcodes As String
|
53
|
-
Public Property commandbytes As String
|
54
|
-
'Public Property sikaku As String()
|
55
|
-
End Class
|
56
|
-
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
|
57
|
-
Dim ret As Int32
|
58
|
-
'Dim postData As String
|
59
|
-
Dim postDataBytes As Byte()
|
60
|
-
Dim req As System.Net.WebRequest
|
61
|
-
Dim reqStream As System.IO.Stream = Nothing
|
62
|
-
Dim res As System.Net.WebResponse = Nothing
|
63
|
-
Dim resStream As System.IO.Stream = Nothing
|
64
|
-
Dim sr As System.IO.StreamReader = Nothing
|
65
|
-
|
66
|
-
Try
|
67
|
-
|
68
|
-
Dim syain1 As testjson = New testjson()
|
69
|
-
syain1.groupcodes = "['A','B']"
|
70
|
-
syain1.commandbytes = "[4, 17, 0, 234]"
|
71
|
-
|
72
|
-
Dim Json As String = JsonConvert.SerializeObject(syain1)
|
73
|
-
|
74
|
-
'バイト型配列に変換
|
75
|
-
postDataBytes = System.Text.Encoding.UTF8.GetBytes(Json)
|
76
|
-
|
77
|
-
'WebRequestの作成
|
78
|
-
req = System.Net.WebRequest.Create("http://192.168.14.100:7001/testapi/sendbroadcastcommand")
|
79
|
-
|
80
|
-
'メソッドにPOSTを指定
|
81
|
-
req.Method = "POST"
|
82
|
-
'ContentTypeを"application/json"にする
|
83
|
-
req.ContentType = "application/json"
|
84
|
-
|
85
|
-
''POST送信するデータの長さを指定
|
86
|
-
req.ContentLength = postDataBytes.Length
|
87
|
-
|
88
|
-
req.Proxy = Nothing
|
89
|
-
|
90
|
-
'データをPOST送信するためのStreamを取得
|
91
|
-
reqStream = req.GetRequestStream()
|
92
|
-
'送信するデータを書き込む
|
93
|
-
reqStream.Write(postDataBytes, 0, postDataBytes.Length)
|
94
|
-
ret = 0
|
95
|
-
|
96
|
-
Catch ex As Exception
|
97
|
-
|
98
|
-
'エラーコードの設定
|
99
|
-
ret = 100
|
100
|
-
|
101
|
-
Finally
|
102
|
-
|
103
|
-
If IsNothing(reqStream) = False Then
|
104
|
-
reqStream.Close()
|
105
|
-
|
10
|
+
※コード削除
|
106
|
-
If IsNothing(sr) = False Then
|
107
|
-
sr.Close()
|
108
|
-
End If
|
109
|
-
|
110
|
-
End Try
|
111
|
-
|
112
|
-
End Sub
|
113
|
-
End Class
|
114
|
-
```
|
1
自分が行った事を追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,6 +1,12 @@
|
|
1
|
-
|
1
|
+
PythonのコードをVBかC#に変換したいです。
|
2
|
+
目的は学習です。
|
2
|
-
|
3
|
+
Pythonコードは正常に動作している物で
|
4
|
+
VBコードは現在動作していない物です。
|
5
|
+
元のPythonコードと、私が書いたVBコードを載せます。
|
6
|
+
例外エラーなどは出ず処理は一応実行できますが、動作しない状況です。
|
7
|
+
私が書いたVBコードはどこが間違えているのかご教示願いたいです。
|
3
8
|
|
9
|
+
|
4
10
|
```Python
|
5
11
|
import requests
|
6
12
|
import json
|
@@ -26,8 +32,7 @@
|
|
26
32
|
|
27
33
|
if __name__ == '__main__':
|
28
34
|
grcd1 = ['A','B']
|
29
|
-
cmdbyte1 = [4, 17, 1, 233]
|
30
|
-
|
35
|
+
cmdbyte1 = [4, 17, 0, 234]
|
31
36
|
|
32
37
|
|
33
38
|
try:
|
@@ -36,4 +41,74 @@
|
|
36
41
|
print("get_scv()の中に例外発生!")
|
37
42
|
print(e01)
|
38
43
|
|
44
|
+
```
|
45
|
+
|
46
|
+
```VB
|
47
|
+
Imports Newtonsoft.Json
|
48
|
+
|
49
|
+
Public Class Form1
|
50
|
+
|
51
|
+
Public Class testjson
|
52
|
+
Public Property groupcodes As String
|
53
|
+
Public Property commandbytes As String
|
54
|
+
'Public Property sikaku As String()
|
55
|
+
End Class
|
56
|
+
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
|
57
|
+
Dim ret As Int32
|
58
|
+
'Dim postData As String
|
59
|
+
Dim postDataBytes As Byte()
|
60
|
+
Dim req As System.Net.WebRequest
|
61
|
+
Dim reqStream As System.IO.Stream = Nothing
|
62
|
+
Dim res As System.Net.WebResponse = Nothing
|
63
|
+
Dim resStream As System.IO.Stream = Nothing
|
64
|
+
Dim sr As System.IO.StreamReader = Nothing
|
65
|
+
|
66
|
+
Try
|
67
|
+
|
68
|
+
Dim syain1 As testjson = New testjson()
|
69
|
+
syain1.groupcodes = "['A','B']"
|
70
|
+
syain1.commandbytes = "[4, 17, 0, 234]"
|
71
|
+
|
72
|
+
Dim Json As String = JsonConvert.SerializeObject(syain1)
|
73
|
+
|
74
|
+
'バイト型配列に変換
|
75
|
+
postDataBytes = System.Text.Encoding.UTF8.GetBytes(Json)
|
76
|
+
|
77
|
+
'WebRequestの作成
|
78
|
+
req = System.Net.WebRequest.Create("http://192.168.14.100:7001/testapi/sendbroadcastcommand")
|
79
|
+
|
80
|
+
'メソッドにPOSTを指定
|
81
|
+
req.Method = "POST"
|
82
|
+
'ContentTypeを"application/json"にする
|
83
|
+
req.ContentType = "application/json"
|
84
|
+
|
85
|
+
''POST送信するデータの長さを指定
|
86
|
+
req.ContentLength = postDataBytes.Length
|
87
|
+
|
88
|
+
req.Proxy = Nothing
|
89
|
+
|
90
|
+
'データをPOST送信するためのStreamを取得
|
91
|
+
reqStream = req.GetRequestStream()
|
92
|
+
'送信するデータを書き込む
|
93
|
+
reqStream.Write(postDataBytes, 0, postDataBytes.Length)
|
94
|
+
ret = 0
|
95
|
+
|
96
|
+
Catch ex As Exception
|
97
|
+
|
98
|
+
'エラーコードの設定
|
99
|
+
ret = 100
|
100
|
+
|
101
|
+
Finally
|
102
|
+
|
103
|
+
If IsNothing(reqStream) = False Then
|
104
|
+
reqStream.Close()
|
105
|
+
End If
|
106
|
+
If IsNothing(sr) = False Then
|
107
|
+
sr.Close()
|
108
|
+
End If
|
109
|
+
|
110
|
+
End Try
|
111
|
+
|
112
|
+
End Sub
|
113
|
+
End Class
|
39
114
|
```
|