急求!课程设计用VB程序做一个简单的计算器,我看老师讲的时候代码特别长,但是看着挺简单,都是最常见的

我学的是VS,大概的思想都是差不多的,你自己好好看看…… 有些小问题相信你能解决的

DimstrAAsString

DimstrBAsString

Dimdec1stNumberAsDecimal

Dimdec2ndNumberAsDecimal

DimdecResultAsDecimal

DimstrOprationAsString

PrivateSubForm1_Load(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesMyBase.Load

strB="0"

lbl1.Text=strB

strA=lbl1.Text

EndSub

PrivateSubbtn1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)Handlesbtn1.Click

IfstrB="0"Then

strB=btn1.Text

Else

Try

strB=strA&btn1.Text

Catch

EndTry

EndIf

lbl1.Text=strB

strA=lbl1.Text

EndSub

PrivateSubbtn2_Click(ByValsenderAsObject,ByValeAsSystem.EventArgs)Handlesbtn2.Click

IfstrB="0"Then

strB=btn2.Text

Else

Try

strB=strA&btn2.Text

Catch

EndTry

EndIf

lbl1.Text=strB

strA=lbl1.Text

EndSub

............."以此类推做0-9"

PrivateSubbtnPoint_Click(ByValsenderAsObject,ByValeAsSystem.EventArgs)HandlesbtnPoint.Click

Try

strB=strA&btnPoint.Text

Catch

EndTry

lbl1.Text=strB

strA=lbl1.Text

btnPoint.Enabled=False

EndSub

PrivateSubbtnAdd_Click(ByValsenderAsObject,ByValeAsSystem.EventArgs)HandlesbtnAdd.Click

dec1stNumber=CType(strA,Decimal)

strB="0"

strOpration="+"

btnPoint.Enabled=True

EndSub

PrivateSubbtnDivide_Click(ByValsenderAsObject,ByValeAsSystem.EventArgs)HandlesbtnDevide.Click

dec1stNumber=CType(strA,Decimal)

strB="0"

strOpration="/"

btnPoint.Enabled=True

EndSub

PrivateSubbtnMinus_Click(ByValsenderAsObject,ByValeAsSystem.EventArgs)HandlesbtnMinus.Click

dec1stNumber=CType(strA,Decimal)

strB="0"

strOpration="-"

btnPoint.Enabled=True

EndSub

PrivateSubbtnTime_Click(ByValsenderAsObject,ByValeAsSystem.EventArgs)HandlesbtnTime.Click

dec1stNumber=CType(strA,Decimal)

strB="0"

strOpration="*"

btnPoint.Enabled=True

EndSub

PrivateSubbtnEqual_Click(ByValsenderAsObject,ByValeAsSystem.EventArgs)HandlesbtnEque.Click

dec2ndNumber=CType(strA,Decimal)

SelectCasestrOpration

CaseIs="+"

decResult=dec1stNumber+dec2ndNumber

CaseIs="-"

decResult=dec1stNumber-dec2ndNumber

CaseIs="/"

decResult=dec1stNumber/dec2ndNumber

CaseIs="*"

decResult=dec1stNumber*dec2ndNumber

EndSelect

lbl1.Text=decResult

strA=lbl1.Text

IfdecResult<0Then

btnPoint.Enabled=False

EndIf

EndSub

EndClass

这个应该是最简明的一个,供你参考一下……

Private Sub Command1_Click()

Dim x%, y%, c$, z%

x = (Text1.Text)

y = (Text2.Text)

c = (Text3.Text)

Select Case c

Case "+"

z = x + y

Case "-"

z = x - y

Case "*"

z = x * y

Case "/"

z = x / y

End Select

Text4.Text = z