|
|
先来个加法运算的
VERSION 5.00
Begin VB.Form Form1
Caption = "Maths Demo--http://www.huoniao.com "
ClientHeight = 5115
ClientLeft = 60
ClientTop = 345
ClientWidth = 8025
LinkTopic = "Form1"
ScaleHeight = 5115
ScaleWidth = 8025
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command5
Caption = "Run"
Height = 975
Left = 6360
TabIndex = 9
Top = 3330
Width = 1245
End
Begin VB.CommandButton Command4
Caption = "÷"
Enabled = 0 'False
Height = 525
Left = 6360
TabIndex = 8
Top = 2550
Width = 1245
End
Begin VB.CommandButton Command2
Caption = "×"
Enabled = 0 'False
Height = 525
Left = 6360
TabIndex = 7
Top = 1950
Width = 1245
End
Begin VB.CommandButton Command1
Caption = "-"
Enabled = 0 'False
Height = 525
Left = 6360
TabIndex = 6
Top = 1350
Width = 1245
End
Begin VB.ComboBox Combo1
Height = 300
ItemData = "Form1.frx":0000
Left = 3030
List = "Form1.frx":0010
Style = 2 'Dropdown List
TabIndex = 4
Top = 450
Width = 555
End
Begin VB.CommandButton Command3
Caption = "+"
Enabled = 0 'False
Height = 525
Left = 6360
TabIndex = 3
Top = 750
Width = 1245
End
Begin VB.TextBox Text3
Height = 3465
Left = 330
MultiLine = -1 'True
TabIndex = 2
Top = 840
Width = 5985
End
Begin VB.TextBox Text2
Height = 300
Left = 3690
TabIndex = 1
Text = $"Form1.frx":0024
Top = 450
Width = 2625
End
Begin VB.TextBox Text1
Height = 300
Left = 330
TabIndex = 0
Text = "1231111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
Top = 450
Width = 2595
End
Begin VB.Label Label2
Caption = "Label2"
Height = 315
Left = 330
TabIndex = 10
Top = 4380
Width = 5955
End
Begin VB.Label Label1
Caption = "本演示可以进行近21亿位整数的运算,本人很菜,只能写写这样的东东^_^"
Height = 315
Left = 300
TabIndex = 5
Top = 60
Width = 6045
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub Command5_Click()
Dim strSTemp1 As String, strSTemp2 As String
Dim i As Long, j As Long
i = timeGetTime()
If Combo1.Text = "+" Then
Text3 = mAddition(Text1, Text2)
ElseIf Combo1.Text = "-" Then
MsgBox "缺少功能!", vbExclamation
ElseIf Combo1.Text = "×" Then
ElseIf Combo1.Text = "÷" Then
MsgBox "缺少功能!", vbExclamation
Else
MsgBox "尚未指定运算符!", vbExclamation
Exit Sub
End If
j = timeGetTime
i = j - i
Label2.Caption = "您使用了" & Combo1.Text & "法运算, 共用时: " & i & " 毫秒"
End Sub
'====================================================
Attribute VB_Name = "mdlDeclare"
Option Explicit
Public Declare Function timeGetTime Lib "winmm.dll" () As Long
'n位数运算模拟过程——加法
Function mAddition(ByVal atExpLeft As String, ByVal atExpRight As String) As String
'--------------------左数值 右数值
'A+B ==> 123456789 + 1234567890 ==> 00123456789 + 01234567890 ==> 01358024679
Dim maxLen As Long '估计总长度
Dim alLen As Long, arLen As Long '各数的长度
Dim atTemp() As Integer '临时数组
Dim i As Long, j As Long 'j为字符串左边非0的字符串长度
Dim atCarry As String, atValue As String '进位的值,临时的和
Dim atValLeft As Integer, atValRight As Integer '分解后的单个数值
Dim atStr As String
alLen = Len(atExpLeft): arLen = Len(atExpRight)
If alLen >= arLen Then
maxLen = alLen + 1
Else
maxLen = arLen + 1
End If
atExpLeft = mMidString(atExpLeft, maxLen, alLen)
atExpRight = mMidString(atExpRight, maxLen, arLen)
ReDim atTemp(1 To 2)
atCarry = "0"
atValue = "0"
For i = maxLen To 1 Step -1
atValLeft = CInt(Mid(atExpLeft, i, 1))
atValRight = CInt(Mid(atExpRight, i, 1))
atValue = Format(CStr(atValLeft + atValRight + CInt(atCarry)), "00")
atCarry = CInt(Mid(CStr(atValue), 1, 1))
atValue = CInt(Mid(CStr(atValue), 2, 1))
mAddition = atValue & mAddition
Next
For i = 1 To maxLen
atStr = Mid(mAddition, i, 1)
If Not atStr = "0" Then
j = maxLen - i + 1
Exit For
End If
Next i
mAddition = Right(mAddition, j)
Exit Function
err:
MsgBox "Error Code"
Exit Function
End Function
小小代码,请勿见笑
大家跟贴,谢谢
希望各位别提供程序资源下载,
让大家看代码动手实现
老是down->unzip->open->run 无聊 |
|