CyberChaos(さいばかおす)

プログラミング言語、トランスパイラ、RPA、ChatGPT、データマイニング、リバースエンジニアリングのための忘備録

VBAでチャットボットを作ってみた

2023-05-12 21:17:06 | VBA

最近発表されたgoogle のAIチャットで質問をしてみた。

VBAでチャットボットを作りたいと。

早速ソースコードの例が生成されたが、

Bard AI 「What would you like to talk about?」

俺様「hello」の場合、Bard AI「Hello there!」

俺様「goodbye」の場合、Bard AI「Goodbye!」

俺様「上記以外」の場合、Bard AI「I don't understand. Please try again.」

というショボいものだった。

あまりにもショボいので改造してみた。

Sub ChatBot()
Dim userInput As String
userInput = InputBox("何をしましょうか?")
Select Case userInput
Case "直線"
MsgBox "始点と終点の座標を指定してください。"

Dim StartX As Integer
Dim StartY As Integer
Dim EndX As Integer
Dim EndY As Integer
StartX = InputBox("始点のX座標を入力してください。")
StartY = InputBox("始点のY座標を入力してください。")
EndX = InputBox("終点のX座標を入力してください。")
EndY = InputBox("終点のY座標を入力してください。")

With ActiveSheet.Shapes.AddLine(StartX, StartY, EndX, EndY)
.Line.Weight = 2 ' Set the line thickness to 2 points
End With
Case "円"
MsgBox "中心の座標と半径を入力してください。"

Dim centerX As Variant
Dim centerY As Variant
Dim radius As Variant
Dim drawingSheet As Worksheet
Dim newCircle As Shape
Set drawingSheet = ActiveSheet
centerX = Application.InputBox("Enter the x-coordinate of the center of the circle", "Center X", Type:=1)
centerY = Application.InputBox("Enter the y-coordinate of the center of the circle", "Center Y", Type:=1)
radius = Application.InputBox("Enter the radius of the circle", "Radius", Type:=1)
Set newCircle = drawingSheet.Shapes.AddShape(msoShapeOval, _
-radius, centerY - radius, radius * 2, radius * 2)
With newCircle.Line
.Weight = 2 ' Set the line thickness to 2 points
.DashStyle = msoLineSolid ' Set the line style to solid
.ForeColor.RGB = RGB(255, 0, 0) ' Set the line color to red
End With
newCircle.Fill.Visible = msoFalse ' Set the fill to transparent
Case Else
MsgBox "そのような操作はできません。"
End Select
End Sub

結果はバッチリ!

次はセレクトボックスを表示させ、やりたい操作を選ばせて、数字を入力する形式にしてみたい。