Excel


マクロ

構造体名メンバ型メンバ名配列サイズ
HogeSt?unsigned charx3
TestSt?st
TTTttt5
 Enum memType
     MEMTYPE_NORM
     MEMTYPE_PT
     MEMTYPE_ARRAY
 End Enum
 
 Type StData
     typeName As String
     varName As String
     memType As memType
     arraySize As String
 End Type
 
 Sub autoCode()
     Const START_ROW = 4
     Const TARGET_ST_NAME = "testSt"
 
     Dim targetSt As String
 
     Dim code As String
     Dim member() As StData
     Dim num As Integer
     Dim i As Integer
     Dim val As String
     
     Dim tmpName As String
         
     
     targetSt = Cells(START_ROW, 1).Value
     
     num = 1
     Do
         If Cells(num + START_ROW - 1, 2) = "" Then
             num = num - 1
             Exit Do
         End If
         num = num + 1
     Loop
     
     ReDim member(num)
     
     For i = 1 To num
         member(i - 1).typeName = Cells(i + START_ROW - 1, 2).Value
         member(i - 1).varName = Cells(i + START_ROW - 1, 3).Value
         member(i - 1).memType = MEMTYPE_NORM
         member(i - 1).arraySize = 0
         
         If Cells(i + START_ROW - 1, 4).Value = "*" Then
             member(i - 1).memType = MEMTYPE_PT
         ElseIf Not Cells(i + START_ROW - 1, 4).Value = "" Then
             member(i - 1).memType = MEMTYPE_ARRAY
             member(i - 1).arraySize = Cells(i + START_ROW - 1, 4).Value
         End If
     Next i
     
     
     UserForm1.Show
     code = ""
     
     
     '######## 宣言部分 ########
     
     code = code & "    " & targetSt & " " & TARGET_ST_NAME & ";" & vbCrLf & vbCrLf
     
     For i = 1 To num
         tmpName = member(i - 1).varName
         If member(i - 1).memType = MEMTYPE_ARRAY Then tmpName = tmpName & "[" & member(i - 1).arraySize & "]"
         
         code = code & "    " & member(i - 1).typeName & " " & tmpName & ";" & vbCrLf
     Next i
     
     code = code & vbCrLf & vbCrLf
     
      
     '######## memset部分 ########
     
     For i = 1 To num
         tmpName = member(i - 1).varName
         If member(i - 1).memType = MEMTYPE_NORM Then
             tmpName = "&" & tmpName
         End If
         
         code = code & "    memset(" & tmpName & ", 0, sizeof(" & member(i - 1).varName & "));" & vbCrLf
     Next i
     
     code = code & vbCrLf & vbCrLf
     
     
     '######## 代入部分 ########
     
     For i = 1 To num
         tmpName = member(i - 1).varName
         
         If member(i - 1).memType = MEMTYPE_NORM Then
             code = code & "    " & TARGET_ST_NAME & "." & tmpName & " = " & tmpName & ";" & vbCrLf
         Else
             code = code & "    memcpy(" & TARGET_ST_NAME & "." & tmpName & ", " & tmpName & ", sizeof(" & tmpName & "));" & vbCrLf
         End If
 
     Next i
     
     
     UserForm1.TextBox1.Value = code
 End Sub

最新の20件

2021-03-31 2020-06-09 2020-05-30 2019-12-02 2018-10-18 2018-07-05 2018-01-11 2015-12-07 2015-08-03
  • Excel
2015-07-20 2012-07-19 2012-06-30 2012-06-23 2012-01-25 2011-11-09 2011-11-08 2011-10-02

今日の9件

  • counter: 123
  • today: 1
  • yesterday: 0
  • online: 1