- 帖子
- 7
- 主題
- 1
- 精華
- 0
- 積分
- 58
- 點名
- 0
- 作業系統
- Win7
- 軟體版本
- Office 2010
- 閱讀權限
- 20
- 註冊時間
- 2021-7-3
- 最後登錄
- 2025-11-23
|
底下是我測試ChatGpt 的問題:
請產生華氏與攝氏互換的VBA程式碼
結果產生兩個自訂函數程式碼如下:
'將華氏轉換為攝氏
Function FahrenheitToCelsius(fahrenheit As Double) As Double
Celsius = (fahrenheit - 32) * 5 / 9
FahrenheitToCelsius = Celsius
End Function
'將攝氏轉換為華氏
Function CelsiusToFahrenheit(celsius As Double) As Double
fahrenheit = celsius * 9 / 5 + 32
CelsiusToFahrenheit = fahrenheit
End Function
它另提供底下一個巨集範例:
Sub Example()
Dim celsius As Double
Dim fahrenheit As Double
celsius = 25 '設置攝氏溫度為25度'
fahrenheit = CelsiusToFahrenheit(celsius) '轉換攝氏溫度為華氏溫度'
MsgBox "攝氏 " & celsius & " 度等於華氏 " & fahrenheit & " 度。"
End Sub |
|