teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

crc = &HFFFF

2020/04/19 14:59

投稿

pokemonta
pokemonta

スコア170

title CHANGED
File without changes
body CHANGED
@@ -4,6 +4,8 @@
4
4
   また、"\x01\x04\x00\x00\x00\x01"を1バイトずつ取得したいのですが
5
5
   inputdataには、10進数の値が入ります。(1310721)
6
6
  どこを改善すればよろしいでしょうか
7
+ crc = &HFFFFも失敗
8
+ crcがbyte型なので16bitの初期化ができないし
7
9
 
8
10
  ```python
9
11
  # -*- coding: utf-8 -*-

2

link

2020/04/19 14:59

投稿

pokemonta
pokemonta

スコア170

title CHANGED
File without changes
body CHANGED
@@ -82,4 +82,8 @@
82
82
 
83
83
  End Function
84
84
 
85
- ```
85
+ ```
86
+
87
+ [リンク内容](https://vbabeginner.net/vba%E3%81%A72%E9%80%B2%E6%95%B0%E3%81%8B%E3%82%8916%E9%80%B2%E6%95%B0%E3%81%B8%E5%A4%89%E6%8F%9B%E3%81%99%E3%82%8B/)
88
+
89
+ [リンク内容](http://excel.syogyoumujou.com/memorandum/hex_binary.html)

1

program修正

2020/04/19 14:39

投稿

pokemonta
pokemonta

スコア170

title CHANGED
File without changes
body CHANGED
@@ -1,5 +1,8 @@
1
1
  PythonでCRC-16のサンプルプログラムがありましたので
2
- VBAでコンバートさせました。しかしながら全く動きせん
2
+ VBAでコンバートさせました。しかしながら以下のエラーが発生いたし
3
+  「For Eachは、コレクションオブジェクトまたは配列でのみ繰り返しを実行します。」
4
+  また、"\x01\x04\x00\x00\x00\x01"を1バイトずつ取得したいのですが
5
+  inputdataには、10進数の値が入ります。(1310721)
3
6
  どこを改善すればよろしいでしょうか
4
7
 
5
8
  ```python
@@ -34,26 +37,28 @@
34
37
  ```
35
38
 
36
39
  ```VBA
40
+
37
41
  'CRC16計算
38
42
  Private Sub CommandButton1_Click()
39
43
  Dim anser As Byte
40
- Dim inputdata As Byte
44
+ Dim inputdata As Long
41
45
 
42
46
  'b"\x01\x04\x00\x00\x00\x01"
43
- Set inputdata = &H140001
47
+ inputdata = &H140001
44
48
  anser = CRC16_Calculate(inputdata)
45
49
 
46
50
  End Sub
47
51
 
52
+
48
53
  'CRC-16
49
- Public Function CRC16_Calculate(ByVal str As Byte) As Byte
54
+ Public Function CRC16_Calculate(ByVal str As Long) As Byte
50
55
  Dim crc As Byte
51
56
  Dim i As Integer
52
57
  Dim DecByte As Byte
53
58
  Dim tmp As Byte
54
59
 
55
- Set crc = &HFFFF
60
+ crc = &HFFFF
56
- Set ibm16 = &HA001
61
+ ibm16 = &HA001
57
62
 
58
63
  For Each cel In str
59
64
  DecByte = cel.Value