请高手帮忙编写以下vb程序,谢谢

2024-11-08 05:57:43
推荐回答(1个)
回答1:

1。
Private Function FindA(s As String, b As String) As Integer
Dim n As Integer
Dim intCont As Integer
n = Len(s)
For i = 1 To n
If b = Mid(s, i, 1) Then
intCont = intCont + 1
End If
Next i
FindA = intCont
End Function
Private Sub Command1_Click()
Dim s As String
s = Text1.Text
Print FindA(s, Text2.Text)
End Sub
2。
Private Function OutZ(a As Double) As String '取最小因子
Dim str As String
Dim flag As Boolean
For i = 2 To a / 2
If flag = False Then
If (a Mod i) = 0 Then
flag = True
OutZ = i
Debug.Print i
End If
End If
Next i
End Function
Private Function SS(a As Double) As Boolean '判断是否是素数
Dim b As Boolean
For i = 2 To a - 1
If (a Mod i) = 0 Then
b = True
End If
Next i
If b = True Then
SS = False
Else
SS = True
End If
End Function

Private Sub Command1_Click()
Dim a As Double
Dim n As String
Dim p As Integer
p = 0
a = Val(Text1.Text)
Do While SS(a) = False
p = p + 1
n = n & OutZ(a) & "*"
a = Int(a / Val(OutZ(a)))
If SS(a) = True Then
n = n & a
End If
Loop
If p = 0 Then
n = ""
n = "1 * " & a
End If
Text2.Text = n
End Sub

3。
Private Sub Fxpx(V As Variant)
Dim n As Integer
Dim B() As Single
n = UBound(V)
ReDim B(n) As Single
For i = 0 To n
B(n - i) = V(i)
Next i
For i = 0 To n
V(i) = B(i)
Next i
End Sub

Private Sub Command1_Click()
Dim A As Variant
A = Split(Text1.Text, ",") 'text1中输入数字,每个数字用,好分隔。
Fxpx A
For i = 0 To UBound(A)
Text2.Text = Text2.Text & A(i) & ";"
Next i

End Sub