vb两位数的乘法

前端之家收集整理的这篇文章主要介绍了vb两位数的乘法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

vb两位数的乘法

今天我们再次领略到了vb的神奇,我们这次和上次做的vb标题一样,但是内容却大相径庭。

Option Base 1

Private Sub Command1_Click()

Dim M As String

Dim N As String

M = Trim(Text1.Text)

N = Trim(Text2.Text)

Dim Number1() As Byte

Dim Number2() As Byte

ReDim Number1(Len(M))

ReDim Number2(Len(N))

Dim index As Byte

For index = 1 To Len(M) Step 1

Number1(index) = Mid(M,index,1)

Next index

For index = 1 To Len(N) Step 1

Number2(index) = Mid(N,1)

Next index

Dim Result() As Byte

ReDim Result(Len(M) + Len(N))

Dim MCarry As Byte

Dim ACarry As Byte

Dim Remainder As Integer

Dim i As Integer,j As Integer

Dim Mtemp As Integer,Atemp As Integer

For i = Len(N) To 1 Step -1

For j = Len(M) To 1 Step -1

Mtemp = Number1(j) * Number2(i) + MCarry

MCarry = Mtemp \ 10

Remainder = Mtemp Mod 10

Atemp = Remainder + Result(i + j) + ACarry

ACarry = Atemp \ 10

Result(i + j) = Atemp Mod 10

Next j

Result(i) = MCarry + ACarry

MCarry = 0

ACarry = 0

Next i

Dim Mstr As String

For index = 1 To Len(N) + Len(M)

Mstr = Mstr & Str(Result(index))

Next

Label3.Caption = Mstr

End Sub

体会:世上无难事,只怕有心人。它是难,但只要我们用心去学,慢慢领悟,我相信我们都可以学好它,也能够利用好它。

原文链接:https://www.f2er.com/vb/260140.html

猜你在找的VB相关文章