
dim i as Integer,j as Integer,k as Integer
For i = 1 to 9
For j = 1 to 9
For k = 1 to 9
If i^3 + j ^3 + k^3 =i 100 + j10 + k Then
Print i 100 + j10 + k;
End If
Next k
Next j
Next i
把这段代码放在事件过程中如:Command1_Click()中,运行就能在窗体上打印出结果来
Dim sec, min, h
Private Sub Command1_Click()
Timer1Enabled = True
h = Text1Text
min = Text2Text
sec = Text3Text
Timer2Enabled = False
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_Load()
Form1BackColor = &HFFFF00
Timer1Enabled = False
Timer1Interval = 1000
Timer2Enabled = True
Timer2Interval = 1000
Text1Text = 2
Text2Text = "00"
Text3Text = "00"
Command2Caption = "退出"
Command1Caption = "开始倒计时"
End Sub
Private Sub Timer1_Timer()
If sec > 0 Then
sec = sec - 1
Else:
If (min > 0 Or h > 0) Then
sec = 59
End If
If min > 0 Then
min = min - 1
Else:
If h > 0 Then
min = 59
End If
If h > 0 Then
h = h - 1
Else: Timer1Enabled = False
CreateObject("SAPISpVoice")Speak "GAME OVER!"
Form1BackColor = &HFF
End If
End If
End If
Text1Text = h
Text2Text = min
Text3Text = sec
Label6Caption = Now
End Sub
Private Sub Timer2_Timer()
Label6Caption = Now
End Sub
用VB实现上述功能的函数是:
Function fun(m, n) As Integer
Sum = 0
For i = 1 To 100
If i Mod m = 0 Or i Mod n = 0 Then
Sum = Sum + i
End If
Next i
fun = Sum
End Function
Private Sub Command1_Click()
m = CInt(InputBox("m="))
n = CInt(InputBox("n="))
Print "100以内能被"; m; "或"; n; "整除的数的总和="; fun(m, n)
End Sub
将下列代码复制到一个文本文件,并将文本文件命名为Form1frm,然后运行(我不知道你要取消按钮的用途)
VERSION 500
Begin VBForm Form1
Caption = "Form1"
ClientHeight = 4035
ClientLeft = 60
ClientTop = 450
ClientWidth = 5310
LinkTopic = "Form1"
ScaleHeight = 4035
ScaleWidth = 5310
StartUpPosition = 3 '窗口缺省
Begin VBTextBox Text1
BeginProperty Font
Name = "宋体"
Size = 1425
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 465
Left = 1920
TabIndex = 3
Top = 240
Width = 2175
End
Begin VBCommandButton Command2
Caption = "取 消"
BeginProperty Font
Name = "宋体"
Size = 1425
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 615
Left = 3000
TabIndex = 1
Top = 2400
Width = 1455
End
Begin VBCommandButton Command1
Caption = "确 定"
Default = -1 'True
BeginProperty Font
Name = "宋体"
Size = 1425
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 615
Left = 720
TabIndex = 0
Top = 2400
Width = 1455
End
Begin VBLabel Label3
BeginProperty Font
Name = "宋体"
Size = 1425
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 1800
TabIndex = 5
Top = 1080
Width = 2295
End
Begin VBLabel Label2
Caption = "八位号"
BeginProperty Font
Name = "宋体"
Size = 1425
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 480
TabIndex = 4
Top = 1080
Width = 1215
End
Begin VBLabel Label1
Caption = "姓 名"
BeginProperty Font
Name = "宋体"
Size = 1425
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 480
TabIndex = 2
Top = 360
Width = 1215
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Private Sub Command1_Click()
If Text1 = "" Then
MsgBox "请输入名字!"
Text1SetFocus
Exit Sub
End If
Randomize
CF:
Label3 = LTrim(Str(Int(Rnd() 100000000)))
Label3 = String(8 - Len(Label3), "0") & Label3
Open "D:\花名册\花名册txt" For Input As #1
Do While Not EOF(1)
Input #1, strzc
If strzc = "" Then GoTo TG
k = Split(strzc, " ")
If k(1) = Label3 Then
Close #1
GoTo CF
End If
If k(0) = Text1 Then
w = MsgBox("输入的姓名已经存在,点“是”保存,点“否”放弃。", vbYesNo, "提示")
If w = 7 Then
Close #1
Exit Sub
End If
End If
Loop
TG:
Close #1
Open "D:\花名册\花名册txt" For Append As #1
Print #1, Text1 & " " & Label3 & " " & Format(Now, "yyyy年mm月dd日hh:nn:ss")
Close #1
Text1SelStart = 0
Text1SelLength = Len(Text1)
End Sub
Private Sub Form_Load()
If Dir(AppPath & "\MyTimeINI") = "" Then
MkDir "D:\花名册"
Open "D:\花名册\花名册txt" For Append As #1
Close #1
End If
A = WritePrivateProfileString("TIP", "START", Time$, AppPath & "\MyTimeINI")
Show
Text1SetFocus
End Sub
更多VB代码请参阅我的博客:>
在窗体中建立一个文本框text1,multiline属性为true,scrollBars属性为2-vertical
复制进如下代码:
Private
Sub
Form_Load()
Dim
a&,
b$
For
a
=
100
To
200
If
a
Mod
3
=
0
Then
b
=
b
&
Str(a)
Next
a
Text1Text
=
b
End
Sub
---------我是华丽丽的分割线--------
dim
a(1
to
10)
as
long
dim
Temp()
as
long
‘保存能被3整除的数
dim
s
as
string
dim
n
as
integer
for
i=1
to
10
a(i)=inputbox("Please
input
data!")
next
i
for
i=1
to
10
if
(a(i)
mod
2)
then
n=n+1
s=s
&
cstr(a(i))
&
","
end
if
redim
temp(n)
as
long
dim
v
v=split(s,",")
for
i=0
to
ubound(v)
temp(i)=v(i)
next
i
以上就是关于用vb编写一个程序全部的内容,包括:用vb编写一个程序、如何使用VB编写一个简单的小程序、用vb编写程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)