# data[].attributes.body
Sub QuadraticEquation(a As Double, b As Double, c As Double)

Dim D As Double

Dim x1 As Double, x2 As Double

' 判斷是否為二次方程式

If a = 0 Then

MsgBox "這不是二次方程式 (a=0)。"

Exit Sub

End If

' 計算判別式

D = b ^ 2 - 4 a c

If D > 0 Then

x1 = (-b + Sqr(D)) / (2 * a)

x2 = (-b - Sqr(D)) / (2 * a)

MsgBox "有兩個實數解：" & vbCrLf & _

"x1 = " & x1 & vbCrLf & _

"x2 = " & x2

ElseIf D = 0 Then

x1 = -b / (2 * a)

MsgBox "有一個重根：" & vbCrLf & _

"x = " & x1

Else

MsgBox "無實數解（判別式 < 0）。"

End If

End Sub

Sub TestEquation()

Call QuadraticEquation(1, -3, 2)

End Sub

# data[].attributes.body
Sub CalculateRoots(ByVal a As Double, ByVal b As Double, ByVal c As Double)

Dim D As Double

Dim x1 As Double, x2 As Double

D = (b ^ 2) - (4* a * c)

If D > 0 Then

x1 = (-b + Sqr(D)) / (2 * a)

x2 = (-b - Sqr(D)) / (2 * a)

MsgBox "方程式 " & a & "x^2 + " & b & "x + " & c & " = 0 的解為：" & vbCrLf & "x1 = " & x1 & vbCrLf & "x2 = " & x2

ElseIf D = 0 Then

x1 = -b / (2 * a)

MsgBox "方程式 " & a & "x^2 + " & b & "x + " & c & " = 0 的解為：" & vbCrLf & "重根 x = " & x1

Else

MsgBox "方程式 " & a & "x^2 + " & b & "x + " & c & " = 0 沒有實數解。"

End If

End Sub

Sub RunSolver()

Call CalculateRoots(1, 1, -2)

Call CalculateRoots(1, -6, 9)

End Sub

# data[].attributes.body
Sub System_Command(a As Double, b As Double, c As Double)

Dim num1 As Double

Dim num2 As Double

Dim x1 As Double

Dim x2 As Double

num1 = b ^ 2 - 4 * a * c

num2 = Sqr(num1)

x1 = (-b + num2) / (2 * a)

x2 = (-b - num2) / (2 * a)

MsgBox "方程式的解為：" & vbCrLf & "x1 = " & x1 & vbCrLf & "x2 = " & x2

End Sub

Sub SystemCall()

Call System_Command(1, -3, 2)

Call System_Command(1, -2, 1)

End Sub

# data[].attributes.body
Sub Solution(ByVal a As Double, ByVal b As Double, ByVal c As Double)

Dim discriminant As Double

Dim x1 As Double

Dim x2 As Double

discriminant = b ^ 2 - 4 *a * c

x1 = (-b + Sqr(discriminant)) / (2 * a)

x2 = (-b - Sqr(discriminant)) / (2 * a)

MsgBox "X1 = " & x1 & ", X2 = " & x2

End Sub

Sub CallExample()

Call Solution(1, 7, 12)

End Sub

# data[].attributes.body
Sub FindAnswer(ByVal num1 As Double, ByVal num2 As Double, ByVal num3 As Double)

Dim answer1 As Double

Dim answer2 As Double

answer1 = (-1) num2 + Sqr(num2 num2 - 4 num1 num3) / (2 * num1)

answer2 = (-1) num2 - Sqr(num2 num2 - 4 num1 num3) / (2 * num1)

MsgBox "The answer1 = " & answer1 & ",answer2 =" & answer2

End Sub

Sub CallExample()

MsgBox "Hello, World!"

Call FindAnswer(1, -3, 2)

End Sub

# data[].attributes.body
sol1.

Sub add()

Dim ws1 As Worksheet, ws2 As Worksheet

Set ws2 = Worksheets.add

ws2.Name = "CarData"

ws2.Cells(1, 1).Value = "Brand"

ws2.Cells(1, 2).Value = "Color"

ws2.Range("A2:A4").Value = "Toyota"

ws2.Range("B2:B4").Value = "White"

End Sub

sol2.

Sub add()

Dim ws1 As Worksheet, ws2 As Worksheet

Set ws2 = Worksheets.add

ws2.Name = "CarData"

ws2.Cells(1, 1).Value = "Brand"

ws2.Cells(1, 2).Value = "Color"

ws2.Cells(2, 1).Value = "Toyota"

ws2.Cells(2, 2).Value = "White"

ws2.Range("A2:B2").Copy

ws2.Range("A2:B4").PasteSpecial Paste:=xlPasteValues

End Sub

# data[].attributes.body
Sub FunctionP9(ByVal num1 As Double, ByVal num2 As Double, ByVal num3 As Double)

Dim ANS1, ANS2 As Double

ANS1 = (-num2 + (num2 num2 - 4 num1 num3) ^ 0.5) / 2 num1

ANS2 = (-num2 - (num2 num2 - 4 num1 num3) ^ 0.5) / 2 num1

MsgBox "ANS:" & ANS1 & " and " & ANS2

End Sub

Sub Solve()

Call FunctionP9(1, -3, 2)

End Sub

# data[].attributes.body
Sub AddTwoNumbers(ByVal a As Double, ByVal b As Double, ByVal c As Double)

Dim x1 As Double

Dim x2 As Double

x1 = (-b + Sqr(b b - 4* a* c)) / (2 * a)

x2 = (-b - Sqr(b b - 4 *a* c)) / (2 * a)

MsgBox "X1 = " & x1 & ", X2 = " & x2

End Sub

Sub CallExample()

Call AddTwoNumbers(1, -1, -6)

End Sub

# data[].attributes.body
Sub Solution(ByVal num1 As Double, ByVal num2 As Double, ByVal num3 As Double)

Dim Ans1 As Double, Ans2 As Double

Ans1 = (-num2 + Sqr(num2 * num2 - 4 * num1 * num3)) / num1 / 2

Ans2 = (-num2 - Sqr(num2 * num2 - 4 * num1 * num3)) / num1 / 2

MsgBox "The Solutions are " & Ans1 & " and " & Ans2

End Sub

Sub CallExample()

Call Solution(1, -3, 2)

End Sub

# data[].attributes.body
Sub AddTwoNumbers(ByVal num1 As Double, ByVal num2 As Double)

Dim sum As Double

sum = num1 + num2

MsgBox "The sum of " & num1 & " and " & num2 & " is " & sum

End Sub

# data[].attributes.body
including practice1-1~1-4

# data[].attributes.body
Sub InputCarData()

Dim ws1 As Worksheet

' 新增工作表『CarData』

Set ws1 = Worksheets.Add

ws1.Name = "CarData"

' 添加標題

ws1.Cells(1, 1).Value = "Brand"

ws1.Cells(1, 2).Value = "Color"

' 輸入資料

ws1.Range("A2:A4").Value = "Toyota"

ws1.Range("B2:B4").Value = "White"

End Sub

# data[].attributes.body
Sub CreateCopyAndDelete()

Dim ws1 As Worksheet, ws2 As Worksheet

Set ws2 = Worksheets.Add

ws2.Name = "CarData"

ws2.Range("A1").Value = "Brand"

ws2.Range("B1").Value = "Color"

ws2.Range("A2:A4").Value = "Toyota"

ws2.Range("B2:B4").Value = "White"

End Sub

# data[].attributes.body
Sub CreateCopyAndDelete()

Dim ws1 As Worksheet, ws2 As Worksheet

Set ws2 = Worksheets.Add

ws2.Name = "CarData"

End Sub

Sub Range1()

Cells(1, 1).Value = "Brand"

Cells(1, 2).Value = "Color"

Range("A2:A4").Value = "Toyota"

Range("B2:B4").Value = "White"

End Sub

# data[].attributes.body
Sub CreateCopyAndDelete()

Dim ws1 As Worksheet, ws2 As Worksheet

Set ws2 = Worksheets.Add

ws2.Name = "CarData"

ws2.Cells(1, 1).Value = "Brand"

ws2.Cells(1, 2).Value = "Color"

ws2.Range("A2:A4").Value = "Toyota"

ws2.Range("B2:B4").Value = "White"

End Sub

# data[].attributes.body
Sub CreateValueAdded()

Dim ws1 As Worksheet, ws2 As Worksheet

Set ws2 = Worksheets.Add

ws2.Name = "CarData"

'

ws2.Cells(1, 1).Value = "Brand"

ws2.Cells(1, 2).Value = "Color"

ws2.Range("A2:A4").Value = "Toyota"

ws2.Range("B2:B4").Value = "White"

End Sub

# data[].attributes.body
Sub Car()

Dim ws1 As Worksheet, ws2 As Worksheet

Set ws2 = Worksheets.Add

ws2.Name = "CarData"

ws2.Cells(1, 1).Value = "Brand"

ws2.Cells(1, 2).Value = "Color"

ws2.Cells(2, 1).Value = "Toyota"

ws2.Cells(2, 2).Value = "White"

ws2.Range("A2:B2").Copy

ws2.Range("A2:A4").PasteSpecial Paste:=xlPasteValues

End Sub

# data[].attributes.body
Sub practice1()

Dim w1 As Worksheet

Set w1 = Worksheets.Add

w1.Name = "CarData"

w1.Cells(1, 1).Value = "Brand"

w1.Cells(1, 2).Value = "Color"

w1.Range("A2:A4").Value = "Toyota"

w1.Range("B2:B4").Value = "White"

End Sub

# data[].attributes.body
Sub Cardata()

Dim ws1 As Worksheet, ws2 As Worksheet

Set ws2 = Worksheets.Add

ws2.Name = "Cardata"

ws2.Cells(1, 1).Value = "Brand"

ws2.Cells(1, 2).Value = "Color"

ws2.Range("A2:A4").Value = "Toyota"

ws2.Range("B2:B4").Value = "White"

End Sub

# data[].attributes.body
Sub CarData()

'新增工作表

Worksheets.Add After:=Worksheets("工作表1")

ActiveSheet.Name = "CarData"

'添加標題

Cells(1, 1).Value = "Brand"

Cells(1, 2).Value = "Color"

'輸入資料

Range("A2:A4").Value = "Toyota"

Range("B2:B4").Value = "White"

End Sub

# data[].attributes.body
Sub CreateCopyAndDelete()Dim ws1 As Worksheet, ws2 As WorksheetSet ws2 = Worksheets.Addws2.Name = "CarData"ws2.Range("A1").Value = "Brand"ws2.Range("B1").Value = "Color"ws2.Range("A2:A4").Value = "Toyota"ws2.Range("B2:B4").Value = "White"End Sub

# data[].attributes.attachment_link.title
W03 巨集程式與資料分析應用 - 課後調查

# data[].attributes.attachment_link.description
W03 巨集程式與資料分析應用 - 課後調查