请教用vb编写一个小程序、谢谢各位了

请教用vb编写一个小程序、谢谢各位了,第1张

Private Sub Command1_Click()

Dim r As Single, y As Integer

r = 13

Do While r <= 20

r = r 101

y = y + 1

Loop

Print "我国现有人口13亿,年增长率为1%," & y & "年后增加到20亿"

End Sub

在窗体上放两个命令按钮,command1 和command2一个计时器timer1

程序运行,单击开始每两秒输出一次shishu的值。当shishu的值达到9时输出“条件已成立”。代码如下:

Dim shishu As Integer

Private Sub Command1_Click()

Timer1Interval = 2000

End Sub

Private Sub Command2_Click()

End

End Sub

Private Sub Form_Load()

Command1Caption = "开始"

Command2Caption = "退出"

shishu = 1

End Sub

Private Sub Timer1_Timer()

Form1Cls

Print shishu

shishu = shishu + 1

If shishu = 9 Then

Print "条件已成立。"

Timer1Interval = 0

End If

End Sub

'添加一个名为label1的标签控件,并将其index设为0;再添加一个名为command1的按钮控件

Dim a(1 To 9) As Boolean

Dim win As Boolean, begin As Boolean, haveload As Boolean, start As BooleanPrivate Sub Command1_Click()

start = True: begin = False

For i = 1 To 9

a(i) = False

Next i

Form_Load

End SubPrivate Sub Form_Load()

a(9) = True

Label1(0)Visible = False

MeHeight = 4400

MeWidth = 4000

Scale (0, 0)-(3, 33)

If haveload = False Then

haveload = True: start = True

Command1Top = 3: Command1Left = 2

Command1Width = 1: Command1Height = 03

Command1Caption = "开始"

For i = 1 To 9

Load Label1(i)

Next i

End If

For i = 1 To 9

Label1(i)Height = 1

Label1(i)Width = 1

Label1(i)Visible = True

Label1(i)Top = (i - 1) \ 3

Label1(i)Left = (i - 1) Mod 3

Label1(i)Caption = Str(i)

Label1(i)BackColor = QBColor(i)

Label1(i)FontBold = True

Label1(i)FontSize = 40

Next i

Label1(9)Caption = "": Label1(9)BackColor = vbWhite

Randomize

For i = 1 To 500

r% = Int(9 Rnd) + 1

Call Label1_Click(r)

Next i

begin = True

End SubPrivate Sub Label1_Click(index As Integer)

Dim x1 As Integer, y1 As Integer

If start = True Then

If a(index) = False Then

x1 = (index - 1) Mod 3: y1 = (index - 1) \ 3

If x1 - 1 > -02 Then

If a(x1 + y1 3) = True Then Call yidong(x1 + y1 3, index)

End If

If x1 + 1 < 22 Then

If a(x1 + y1 3 + 2) = True Then Call yidong(x1 + y1 3 + 2, index)

End If

If y1 - 1 > -02 Then

If a(x1 + 1 + (y1 - 1) 3) = True Then Call yidong(x1 + (y1 - 1) 3 + 1, index)

End If

If y1 + 1 < 22 Then

If a(x1 + 1 + (y1 + 1) 3) = True Then Call yidong(x1 + 1 + (y1 + 1) 3, index)

End If

End If

win = True

For i = 1 To 8

If Val(Label1(i)Caption) <> i Then win = False

Next i

If win = True And begin = True Then MsgBox ("恭喜你成功了"): begin = False: start = False

End If

End Sub

Sub yidong(x, index)

Label1(0)Caption = Label1(index)Caption

Label1(index)Caption = Label1(x)Caption

Label1(x)Caption = Label1(0)Caption

a(index) = True: a(x) = False

Label1(0)BackColor = Label1(index)BackColor

Label1(index)BackColor = Label1(x)BackColor

Label1(x)BackColor = Label1(0)BackColor

End Sub

Public x As Boolean

Public oper As Integer

Public z As String

Public result As String

Private Sub Command1_Click(Index As Integer)

If x Then

Text1Text = ""

x = False

Text1Text = Text1Text + CStr(Index + 1)

Else

Text1Text = Text1Text + CStr(Index + 1)

End If

End Sub

Private Sub Command2_Click()

x = True

oper = Int(Text1Text)

z = "/"

End Sub

Private Sub Command3_Click()

x = True

oper = Int(Text1Text)

z = "-"

End Sub

Private Sub Command4_Click()

x = True

oper = Int(Text1Text)

z = "+"

End Sub

Private Sub Command5_Click()

x = True

oper = Int(Text1Text)

z = ""

End Sub

Private Sub Command7_Click()

Select Case z

Case "/"

result = CStr(oper / Int(Text1Text))

Case "-"

result = CStr(oper - Int(Text1Text))

Case ""

result = CStr(oper Int(Text1Text))

Case "+"

result = CStr(oper + Int(Text1Text))

End Select

Text1Text = result

End Sub

Private Sub Command8_Click()

Text1Text = ""

End Sub

简单的计算器程序自己添加控件

给你个计算器的代码

一个单选按钮组,里面有4个单选按钮

3个文本框

1个命令按钮

代码如下

Private Sub Command1_Click()

Dim a, b, r As Double

Dim x As Integer

a = Val(Text1Text)

b = Val(Text2Text)

r = 0

If (Option1(0)Value) Then

r = a + b

ElseIf (Option1(1)Value) Then

r = a - b

ElseIf (Option1(2)Value) Then

r = a b

ElseIf (Option1(3)Value) Then

r = a / b

End If

Text3 = r

End Sub

Private Sub Form_Load()

Option1(0)Value = True

End Sub

不好意思,老是粘贴错,再改一下,源代码我调试好了以后给你粘贴错了,这段代码我没有调试,不过应该可以的,你试试,不可以的话给我追问,我调试

你在vb的安装路径下新建一个text1txt,用来输入学生成绩和姓名,一个text2txt,用来保存结果。注意text1txt格式是这样的,

张3,10

李四,30

王二,40

private sub cmd_click()

dim scount as integer'用来存储学生的个数

scount=inputbox("请输入学生的个数")

dim a() as integer'用来存储文件里的所有数据

redim a(1 to 2scount)

open apppath&"\"&"text1txt" for input as#1

for i=1 to 2scount

input#1,a(i)

next i

close#1

dim b() as integer'用来存储学生成绩

redim b(1 to scount)

dim c() as integer'用来存储学生姓名

redim c(1 to scount)

for i=1 to scount'读入学生成绩

b(i)=a(2I)

next i

for i=1 to scount'读入学生姓名

c(i)=a(1+2(i-1))

next i

for i=1 to scount-1'给成绩排序

max=b(i)

for j=i+1 to scount

if b(j)>max then

max=b(j)

p=j

temp=b(i)

b(i)=b(p)

b(p)=temp

end if

next j

next i

for i=1 to scount

for j=1 to scount

if b(i)=a(2j) then

c(i)=a(2j)

end if

next j

next i

open apppath&"\"&"text2text" for append as#1

for i=1 to scount

print#1,c(i),b(i)

next i

close#1

end sub

你分析一下我下面的代码,相信你会很快解决问题的!

Dim Zf As Integer

Dim An As Integer

Private Sub Command1_Click()

Dim Dcf As Integer

An = An + 1

Dcf = InputBox("请输入本次得分数:")

Zf = Zf + Dcf

Print "第" & An & "次按按钮后总分为:" & Zf

End Sub

以上就是关于请教用vb编写一个小程序、谢谢各位了全部的内容,包括:请教用vb编写一个小程序、谢谢各位了、自己拿来练手的一个VB小程序~、求一个VB的经典小程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

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

原文地址: https://outofmemory.cn/zz/10128617.html

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

发表评论

登录后才能评论

评论列表(0条)

保存