用VB写个小程序

用VB写个小程序,第1张

Private Sub form_click()

MeShow

m = 10

n = 1

Print Int(Rnd (m - n - 1) + n + 1)

End Sub

第二题

Private Sub Form_Load()

Timer1Enabled = True

Timer1Interval = 1000

End Sub

Private Sub Timer1_Timer()

Cls

Print Format(Now, "long date") & " " & Time

End Sub

'用法:: AA "1234"

Function AA(ByVal x As String) As String

Dim ns As Integer

ns = Len(x)

Dim n() As String

Dim w() As Integer

ReDim n(ns)

ReDim w(ns)

Dim i As Integer

For i = 1 To ns

n(i) = Mid(x, ns - i + 1, 1)

Next

Dim str As String

BB n, w, 0, str

MsgBox str

Open "c:\1txt" For Output As #1 ''输出文件句自己改

Print #1, str

Close #1

End Function

Function BB(ByRef n() As String, w() As Integer, ByVal k As Integer, s As String)

Dim i As Integer, j As Integer

Dim b As Boolean

For i = 1 To UBound(n)

b = False

For j = 1 To k

If i = w(j) Then

b = True

Exit For

End If

Next

If Not b And k + 1 <= UBound(n) Then

w(k + 1) = i

BB n, w, k + 1, s

End If

Next

If UBound(w) = k Then

For i = 1 To UBound(w)

s = s & n(w(i))

Next

s = s & vbCrLf

Exit Function

End If

End Function

需要两个函数,一个因子和计算,一个因子和输出。程序窗体放置一个文本框,设置其MultiLine为True。源程序如下:

Option Explicit

Dim I As Long, J As Long, X As Long

Private Sub Form_Load()

MeShow

For I = 1 To 10000

DoEvents

X = Yzh(I)

If X <= 10000 And I < X Then

If Yzh(X) = I Then

Text1 = Text1 & "(" & I & "," & X & ")" & Chr(13) & Chr(10)

YzhOut (I)

YzhOut (X)

End If

End If

Next

Text1 = Text1 & "计算完成"

End Sub

Private Function Yzh(N As Long) As Long

Yzh = 0

For J = 1 To N / 2

If N Mod J = 0 Then Yzh = Yzh + J

Next

End Function

Private Function YzhOut(N As Long) As Long

Dim Yzh As Long

Text1 = Text1 & N & "=1"

Yzh = 1

For J = 2 To N / 2

If N Mod J = 0 Then

Text1 = Text1 & "+" & J

Yzh = Yzh + J

End If

Next

Text1 = Text1 & "=" & Yzh & Chr(13) & Chr(10)

End Function

程序计算结果,有5组亲密数对,程序输出是:

(220,284)

220=1+2+4+5+10+11+20+22+44+55+110=284

284=1+2+4+71+142=220

(1184,1210)

1184=1+2+4+8+16+32+37+74+148+296+592=1210

1210=1+2+5+10+11+22+55+110+121+242+605=1184

(2620,2924)

2620=1+2+4+5+10+20+131+262+524+655+1310=2924

2924=1+2+4+17+34+43+68+86+172+731+1462=2620

(5020,5564)

5020=1+2+4+5+10+20+251+502+1004+1255+2510=5564

5564=1+2+4+13+26+52+107+214+428+1391+2782=5020

(6232,6368)

6232=1+2+4+8+19+38+41+76+82+152+164+328+779+1558+3116=6368

6368=1+2+4+8+16+32+199+398+796+1592+3184=6232

计算完成

Option Explicit

Private Sub Form_Load()

    Randomize

    Label1Caption = Int((Rnd  (999999 - 100000 + 1)) + 100000)    '生成100000-999999之间的随机数

    Timer1Interval = 1000  '一秒一次

    Timer1Enabled = True

End Sub

Private Sub Timer1_Timer()

    Static n As Integer

    n = n + 1

    If n = 60 Then      '一秒一次,累加到60此即60秒

        n = 0

        Randomize

        Label1Caption = Int((Rnd  (999999 - 100000 + 1)) + 100000)

    End If

End Sub

有问题请追问,,加油!

form1上放置Command1,Timer1,Picture1(装入一个)

Dim MoveStep As Integer

Private Sub Command1_Click()

Timer1Enabled = False

End Sub

Private Sub Form_Load()

MoveStep = 100

End Sub

Private Sub Timer1_Timer()

If Picture1Left + Picture1Width + 30 > Form1Width Then

MoveStep = -100

End If

If Picture1Left < 0 Then

MoveStep = 100

End If

Picture1Left = Picture1Left + MoveStep

End Sub

以上就是关于用VB写个小程序全部的内容,包括:用VB写个小程序、如何用VB编写一个生成文本的小程序、请用vb编写一个找出10000以内的亲密数对的小程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/9873845.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-02
下一篇 2023-05-02

发表评论

登录后才能评论

评论列表(0条)

保存