返回列表 上一主題 發帖

使用 chatGPT 學習寫程式

底下是我測試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

TOP

        靜思自在 : 能付出愛心就是福,能消除煩惱就是慧。
返回列表 上一主題