Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim e As Integer
Dim f As Integer
Dim x As Integer
x = Val(Text1)
List1Clear
For a = IIf(Val(Text2) = 0, 1, Val(Text2)) To IIf(Val(Text2) = 0, 28, Val(Text2))
For b = IIf(Val(Text3) = 0, a + 1, Val(Text3)) To IIf(Val(Text3) = 0, 29, Val(Text3))
For c = IIf(Val(Text4) = 0, b + 1, Val(Text4)) To IIf(Val(Text4) = 0, 30, Val(Text4))
For d = IIf(Val(Text5) = 0, c + 1, Val(Text5)) To IIf(Val(Text5) = 0, 31, Val(Text5))
For e = IIf(Val(Text6) = 0, d + 1, Val(Text6)) To IIf(Val(Text6) = 0, 32, Val(Text6))
For f = IIf(Val(Text7) = 0, e + 1, Val(Text7)) To IIf(Val(Text7) = 0, 33, Val(Text7))
DoEvents
If a + b + c + d + e + f = x Then List1AddItem Str(a) + Str(b) + Str(c) + Str(d) + Str(e) + Str(f)
Next f
Next e
Next d
Next c
Next b
Next a
End Sub
Private Sub Command2_Click()
Dim Tmp As String
ClipboardClear
For i = 0 To List1ListCount - 1
Tmp = Tmp + List1List(i) + vbCrLf
Next
ClipboardSetText Tmp
End Sub
Private Sub List1_DblClick()
ClipboardClear
ClipboardSetText List1Text
End SubPrivate Sub Command1_Click()
MeCls
Dim N As Integer, i As Integer
N = InputBox("n=", , 9)
For i = 1 To 2 N - 1
If i <= N Then
Print Space(N - i) + String(2 i - 1, CStr(i))
Else
Print Space(N - (2 N - i)) + String(2 (2 N - i) - 1, CStr(2 N - i))
End If
Next i
End SubVisual
Basic程序设计主要采用的是基于对象(主要是COM和ActiveX)和基于事件处理的可视化编程工具。在VB的IDE中通过可视化设计和布局窗口界面,并处理对象的事件代码。
VB可以编写任意Windows平台上的应用程序,但不包括Win32
Console
Application,到了NET以后就例外了。
总的来说,VB的特点是简单易学、入门简单、 *** 作方面、开发速度快等等。将下列代码复制到一个文本文件,并将文本文件命名为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
i1打开软件,将出现新建工程对话框。这里有很多选项。对新手来说,最常用就标准EXE和V
2出来的界面即为所见所得界面设计。在General下面有许多控件,可以任意放置到Form1
3双击Form1 对话框即可进入程序设计界面。在Form列表框中为工程用到的函数,
4如下以制作个时钟为例,往Form1对话框中增加时间控件(timer)及文本框控件(
5设置timer控件Interval属性。此为多少毫秒触发。要看到秒变,所以设置为1Dim 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
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)