第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

怎么把算式自動(dòng)計(jì)算?

怎么把算式自動(dòng)計(jì)算?

C PHP
aluckdog 2022-08-11 11:07:24
在一個(gè)文本框text1輸入算式,比如3+6+8+104,怎么在按下按鈕后自動(dòng)計(jì)算,把結(jié)果放到另一個(gè)文本框text2
查看完整描述

2 回答

?
至尊寶的傳說

TA貢獻(xiàn)1789條經(jīng)驗(yàn) 獲得超10個(gè)贊

Private Type Parent
s As String
value As Double
End Type

Private Type Plus
s As String
value As Double
End Type

'下面是實(shí)現(xiàn)此功能的函數(shù)的定義
Public Function ValueOfExpression(ByVal Express As String) As Double
Dim Pa() As Parent, ParNum As Integer, Ps() As Plus, OperNum As Integer
Dim str0 As String

'按括號(hào)分解表達(dá)式 Express:Begin-----/*
Dim lenExp As Integer, Lenstr1 As Integer, i As Integer, j As Integer, k As Integer, str1 As String, str2 As String, intPar As Integer
Dim intStart As Integer, intEnd As Integer
lenExp = Len(Express)

For i = 1 To lenExp
If Mid(Express, i, 1) = "(" Then intPar = intPar + 1
Next

ParNum = intPar
ReDim Pa((intPar / 10 + 1) * 10)

For i = 1 To intPar
If intPar < 1 Then Exit For
For j = 1 To lenExp
If Mid(Express, j, 1) = ")" Then
str1 = Mid(Express, 1, j - 1)
Exit For
End If
Next
Lenstr1 = Len(str1)
For k = 1 To Lenstr1
If Mid(str1, Lenstr1 + 1 - k, 1) = "(" Then
Pa(i).s = Mid(str1, Lenstr1 + 2 - k)
Exit For
End If
Next
Express = Mid(Express, 1, Lenstr1 - k) & Chr(128) & CStr(i) & Mid(Express, j + 1)
lenExp = Len(Express)
Next

Pa(0).s = Express
'*/-----End

'按加減號(hào)進(jìn)一步分解:Begin-----/*
Dim n As Integer, strLeft As String
For i = 0 To ParNum
k = 0
For j = 1 To Len(Pa(i).s)
str1 = Mid(Pa(i).s, j, 1)
If str1 = "+" Or str1 = "-" Then k = k + 1
Next
If k > OperNum Then OperNum = k
Next
ReDim Ps(ParNum, OperNum)
For i = 0 To ParNum
strLeft = Pa(i).s: n = 0: str2 = ""
Do
If Len(strLeft) = 0 Then Exit Do
For j = 1 To Len(strLeft)
str1 = Mid(strLeft, j, 1)
If str1 = "+" Or str1 = "-" Then
Ps(i, n).s = str2 & Mid(strLeft, 1, j - 1)
n = n + 1
str2 = IIf(str1 = "-", str1, "")
strLeft = Mid(strLeft, j + 1)
Exit For
End If
If j = Len(strLeft) Then
Ps(i, n).s = str2 & strLeft: j = 0
Exit For
End If
Next
Loop Until j = 0
Next
'*/-----End

'計(jì)算最后分成的多個(gè)簡單表達(dá)式的值的總和,即表達(dá)式 Express 的值
Dim Total As Double, value As Double
For i = 1 To ParNum + 1
If i = ParNum + 1 Then i = 0
Total = 0
For j = 0 To OperNum
Express = Ps(i, j).s: value = 0
Dim lasti As Integer, operator As String
lenExp = Len(Express): lasti = 0: operator = ""
For k = 1 To lenExp
str0 = Mid(Express, k, 1)
If InStr("*/^", str0) > 0 Or k = lenExp Then
If k = lenExp Then k = k + 1
str1 = Mid(Express, lasti + 1, k - 1 - lasti)
Dim sign As Integer, Valstr1 As Double
If Mid(str1, 1, 1) = "-" Then
sign = -1
str1 = Mid(str1, 2)
Else
sign = 1
End If
n = InStr(1, "/sin" & Chr(128) & "/cos" & Chr(128) & "/tan" & Chr(128) & "/abs" & Chr(128) & "/atn" & Chr(128) & "/exp" & Chr(128) & "/int" & Chr(128) & "/fix" & Chr(128) & "/sgn" & Chr(128) & "/sqr" & Chr(128) & "/", "/" & Mid(str1, 1, 4) & "/")
If n > 0 Then
Valstr1 = Choose((n + 4) / 5, Sin(Pa(Val(Mid(str1, 5))).value), Cos(Pa(Val(Mid(str1, 5))).value), Tan(Pa(Val(Mid(str1, 5))).value), Abs(Pa(Val(Mid(str1, 5))).value), Atn(Pa(Val(Mid(str1, 5))).value), Exp(Pa(Val(Mid(str1, 5))).value), Int(Pa(Val(Mid(str1, 5))).value), Fix(Pa(Val(Mid(str1, 5))).value), Sgn(Pa(Val(Mid(str1, 5))).value), Sqr(Pa(Val(Mid(str1, 5))).value))
Else
n = InStr(1, "/lg" & Chr(128) & "/ln" & Chr(128) & "/", Mid(str1, 1, 3))
If n > 0 Then
Valstr1 = Choose((n + 3) / 4, Log(Pa(Val(Mid(str1, 4))).value) / Log(10), Log(Pa(Val(Mid(str1, 4))).value))
Else
If Mid(str1, 1, 1) = Chr(128) Then
Valstr1 = Pa(Val(Mid(str1, 2))).value
ElseIf Right(str1, 1) = "!" Then
If Val(str1) = 0 Then
Valstr1 = 1
Else
Valstr1 = 1
For n = 1 To Val(str1)
Valstr1 = Valstr1 * n
Next
End If
Else
Valstr1 = Val(str1)
End If
End If
End If
Valstr1 = Valstr1 * sign
Select Case operator
Case ""
value = Valstr1
Case "*"
value = value * Valstr1
Case "/"
value = value / Valstr1
Case "^"
value = value ^ Valstr1
End Select
lasti = k: operator = str0
End If
Next
Ps(i, j).value = value
Total = Total + Ps(i, j).value
Next
Pa(i).value = Total
If i = 0 Then Exit For
Next
ValueOfExpression = Pa(0).value
End Function

'使用例子:
'在Text1中輸入式子,然后:
'Text2.Text=ValueOfExpression(Text1.Text)

'該函數(shù)支持很多數(shù)學(xué)函數(shù)如sin、cos、tan等等,如:
'Print ValueOfExpression("sin(1)")
'注意后面要加括號(hào)
'該函數(shù)支持運(yùn)算符+-*/^!,還有括號(hào),^為乘冪,其優(yōu)先級(jí)與*/相同,這是使用該函數(shù)需要注意的地方;!為階乘


查看完整回答
反對 回復(fù) 2022-08-15
?
忽然笑

TA貢獻(xiàn)1806條經(jīng)驗(yàn) 獲得超5個(gè)贊

on command1_click()
計(jì)算之后
text2.text = 計(jì)算結(jié)果 ...

查看完整回答
反對 回復(fù) 2022-08-15
  • 2 回答
  • 0 關(guān)注
  • 211 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)