24. februar 2004 - 08:48Der er
2 kommentarer og 2 løsninger
VB til matematiske beregnere!
Jeg skal bruge nogle matematiske beregnere i Vb, altså sådan noget somme at gange to tal, dividere, addere, subtrahere og lign, skal bruges i VB script. jeg skal ydermere bruge en lommeregner i Vb!
<!--TOOLBAR_START--> <!--TOOLBAR_EXEMPT--> <!--TOOLBAR_END--> <CENTER> <HR> <FONT FACE="Verdana, Arial, Helvetica" SIZE=2> <FONT SIZE=5><B>VBScript Calculator</B></FONT> <HR NOSHADE SIZE=1> <FONT SIZE=3> <!-- global default --> <SCRIPT LANGUAGE="VBScript"> <!-- ' Module-level variables Dim Accum ' Previous number (operand) awaiting operation Dim FlagNewNum ' Flag to indicate a new number (operand) is being entered Dim PendingOp ' Pending operation waiting for completion of second operand
Sub NumPressed(Byval Num) If FlagNewNum Then Document.Keypad.Readout.Value = Num FlagNewNum = False Else If Document.Keypad.Readout.Value = "0" Then Document.Keypad.Readout.Value = CStr(Num) Else Document.Keypad.ReadOut.Value= Document.Keypad.ReadOut.Value & CStr(Num) End If End If End Sub
Sub Decimal_onClick() Dim curReadout curReadOut = Document.Keypad.ReadOut.Value If FlagNewNum Then curReadOut = "0." FlagNewNum = False Else If InStr(curReadOut, ".") = 0 Then curReadOut = curReadOut & "." End If End If Document.Keypad.ReadOut.Value = curReadOut End Sub
Sub Plus_onClick() Operation "+" End Sub
Sub Minus_onClick() Operation "-" End Sub
Sub Multiply_onClick() Operation "*" End Sub
Sub Divide_OnClick() Operation "/" End Sub
Sub Operation(Byval Op) Dim Readout ReadOut = Document.Keypad.ReadOut.Value If FlagNewNum and PendingOp <> "=" Then ' User is hitting op keys repeatedly, so don't do anything Else FlagNewNum = True Select Case PendingOp Case "+" Accum = CDbl(Accum) + CDbl(ReadOut) Case "-" Accum = CDbl(Accum) - CDbl(ReadOut) Case "/" Accum = CDbl(Accum) / CDbl(ReadOut) Case "*" Accum = CDbl(Accum) * CDbl(ReadOut) Case Else Accum = ReadOut End Select Document.Keypad.ReadOut.Value = Accum PendingOp = Op End If End Sub
Sub ClearEntry_onClick() ' Remove current number and reset state Document.Keypad.ReadOut.Value = "0" FlagNewNum = True End Sub
Sub Clear_onClick() ' Clear accumulator and pending operation, and clear display Accum = 0 PendingOp = "" ClearEntry_onClick End Sub
Sub Neg_onClick() Document.Keypad.ReadOut.Value = CDbl(Document.Keypad.ReadOut.Value) * -1 End Sub
Sub Percent_onClick() Document.Keypad.ReadOut.Value = (CDbl(Document.Keypad.ReadOut.Value) / 100) * Accum End Sub
Sub Equals_OnClick() Operation "=" End Sub --> </SCRIPT> <form action="" Name="Keypad"> <TABLE> <B> <TABLE BORDER=2 WIDTH=50 HEIGHT=60 CELLPADDING=1 CELLSPACING=5> <CAPTION ALIGN=top> <p>
If len(lngAdd) > 0 Then Err = 0 lngAdd = Clng(lngAdd) lngC = Clng(Trim(Document.cal.txtDisplay.Value)) If err <> 0 Then Document.cal.txtDisplay.Value = "ERROR" Else Document.cal.txtDisplay.Value = lngAdd + lngC End If End If
If len(lngDiv) > 0 Then Err = 0 lngDiv = Clng(lngDiv) lngC = Clng(Trim(Document.cal.txtDisplay.Value)) If err <> 0 Then Document.cal.txtDisplay.Value = "ERROR" Else Document.cal.txtDisplay.Value = lngDiv / lngC End If End If
If len(lngMul) > 0 Then Err = 0 lngMul = Clng(lngMul) lngC = Clng(Trim(Document.cal.txtDisplay.Value)) If err <> 0 Then Document.cal.txtDisplay.Value = "ERROR" Else Document.cal.txtDisplay.Value = lngMul * lngC End If End If
If len(lngSub) > 0 Then Err = 0 lngSub = Clng(lngSub) lngC = Clng(Trim(Document.cal.txtDisplay.Value)) If err <> 0 Then Document.cal.txtDisplay.Value = "ERROR" Else Document.cal.txtDisplay.Value = lngSub - lngC End If End If
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.