본문 바로가기
VB

[VB6.0] 계산기

by 엘딘 2022. 5. 3.
Dim op As String
Dim num1 As Double
Dim num2 As Double

// 숫자 버튼
Private Sub Command1_Click()
    text1.Text = text1.Text & 1
End sub

Private Sub Command2_Click()
    text1.Text = text1.Text & 2
End sub

Private Sub Command3_Click()
    text1.Text = text1.Text & 3
End sub

Private Sub Command4_Click()
    text1.Text = text1.Text & 4
End sub

Private Sub Command5_Click()
    text1.Text = text1.Text & 5
End sub

... 0까지

// 소수점
Private Sub Command11_Click()
    text1.Text = text1.Text & "."
End sub

// 초기화
Private Sub Command12_Click()
    text1.Text = "0"
End sub

// 더하기
Private Sub Command13_Click()
    num1 = Text1.Text
    text1.Text = ""
    op = "+"
End sub

Private Sub Command14_Click()
    num1 = Text1.Text
    text1.Text = ""
    op = "-"
End sub

Private Sub Command15_Click()
	num1 = Text1.Text
    text1.Text = ""
    op = "*"
End sub

Private Sub Command16_Click()
    num1 = Text1.Text
    text1.Text = ""
    op = "/"
End sub

// = 계산값 출력
Private Sub Command14_Click()
    num2 = Text1.Text
    if op = "+" then
    	text1.Text = num1 + num2
    elseif op = "-" then
    	text1.Text = num1 - num2
    elseif op = "*" then
    	text1.Text = num1 * num2
    elseif op = "/" then
    	text1.Text = num1 / num2
    End If
End sub

'VB' 카테고리의 다른 글

[VB.NET] 엑셀 파일 생성  (0) 2022.05.12
[VB.NET] Excel 연결  (0) 2022.05.12
[C#] 숫자를 한글로 표현  (0) 2022.05.11
[Vb6.0] Byval / Byref  (0) 2022.05.06
[VB 6.0] 스프레드와 DB 연결하기  (0) 2022.05.04

댓글