Private Sub Command1_Click() '窗体上放一个按钮,点击,就可以在窗体上打印结果
Dim SuShu(3) As Integer, i1 As Integer, i2 As Integer, i3 As Integer, i4 As Integer, i5 As Integer, c1 As Long, c2 As Long, Ji1 As Long, Ji2 As Long, Ji3 As Long
MeAutoRedraw = True
SuShu(0) = 2: SuShu(1) = 3: SuShu(1) = 5: SuShu(3) = 7
For i1 = 0 To 3
For i2 = 0 To 3
For i3 = 0 To 3
c1 = SuShu(i1) 100 + SuShu(i2) 10 + SuShu(i3)
For i4 = 0 To 3
For i5 = 0 To 3
c2 = SuShu(i4) 10 + SuShu(i5)
Ji1 = c1 SuShu(i5)
Ji2 = c1 SuShu(i4)
Ji3 = Ji1 + Ji2 10
If Ji1 > 1000 And Ji2 > 1000 And Ji3 > 10000 Then
If IsQuanSuShu(Ji1) And IsQuanSuShu(Ji2) And IsQuanSuShu(Ji3) Then '如果是,输出结果
Print " " & CStr(c1) & vbNewLine & " X " & CStr(c2) & vbNewLine & "--------"
Print " " & CStr(Ji1) & vbNewLine & " " & CStr(Ji2) & vbNewLine & "--------" & vbNewLine & " " & CStr(Ji3)
End If
End If
Next
Next
Next
Next
Next
End Sub
Private Function IsQuanSuShu(ByVal n As Long) As Boolean '每一位是否全部是2,3,5,7
Dim k As Integer
Do While n > 0
k = n Mod 10
If k <> 2 And k <> 3 And k <> 5 And k <> 7 Then Exit Function
n = n \ 10
Loop
IsQuanSuShu = True
End Function
1开机自启动:只要把程序快捷方式放到文件夹“C:\Documents and Settings\用户名\「开始」菜单\程序\启动\”就行了。
2启动后能自动最小化:我在程序中设置为最小化到系统托盘区的。
3关闭某123exe进程:关闭进程可以使用这个语句Call Shell("cmdexe /c taskkill /im 123exe /f", vbHide)。启动则用这个语句Call Shell("123exe", vbHide)'启动程序123exe,最好写成全路径,如:D:\123\123exe
在窗体上添加两个Timer控件
代码如下:
Option Explicit
Private Const MAX_TOOLTIP As Integer = 64
Private Const NIF_ICON = &H2
Private Const NIF_MESSAGE = &H1
Private Const NIF_TIP = &H4
Private Const NIM_ADD = &H0 '添加图标到任务栏提示区
Private Const NIM_MODIFY = &H1 '修改系统状态栏中的图标
Private Const NIM_DELETE = &H2 '删除系统状态栏中的图标
Private Const WM_USER = &H400
Private Const WM_MOUSEMOVE = &H200
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202
Private Const WM_LBUTTONDBLCLK = &H203
Private Const WM_RBUTTONDOWN = &H204
Private Const WM_RBUTTONUP = &H205
Private Const WM_RBUTTONDBLCLK = &H206
Private Type NOTIFYICONDATA
cbSize As Long '需填入NOTIFYICONDATA数据结构的长度
hwnd As Long '设置成窗口的句柄
uID As Long '为图标所设置的ID值
uFlags As Long '设置uCallbackMessage,hIcon,szTip是否有效
uCallbackMessage As Long '消息编号
hIcon As Long '显示在状态栏上的图标
szTip As String MAX_TOOLTIP '提示信息
End Type
Private Declare Function Shell_NotifyIcon Lib "shell32dll" Alias "Shell_NotifyIconA" _
(ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
'返回值 Long,非零表示成功,零表示失败
Private nfIconData As NOTIFYICONDATA
Dim T1 As Long, nT1 As Long
Dim T2 As Long, nT2 As Long
Private Sub Form_Load()
'设置系统托盘区图标的属性
nfIconDatahwnd = Mehwnd
nfIconDatauID = MeIcon
nfIconDatauFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
nfIconDatauCallbackMessage = WM_MOUSEMOVE
nfIconDatahIcon = MeIconHandle
nfIconDataszTip = "123" & vbNullChar
nfIconDatacbSize = Len(nfIconData)
'添加系统托盘区图标
Call Shell_NotifyIcon(NIM_ADD, nfIconData)
T1 = 0: nT1 = 3600 8
T2 = 0: nT2 = 60
Timer1Interval = 1000
Timer2Interval = 1000
Timer1Enabled = True
Timer2Enabled = False
MeHide
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim lMsg As Single
'获得鼠标在系统托盘区的事件,鼠标左键双击
lMsg = X / ScreenTwipsPerPixelX
If lMsg = WM_LBUTTONDBLCLK Then Unload Me
End Sub
Private Sub Form_Unload(Cancel As Integer)
'去掉系统托盘区的图标
Call Shell_NotifyIcon(NIM_DELETE, nfIconData)
End Sub
Private Sub Timer1_Timer()
T1 = T1 + 1
If T1 >= nT1 Then
T1 = 0
'关掉进程程序名为123exe的程序
Call Shell("cmdexe /c taskkill /im 123exe /f", vbHide)
Timer1Enabled = False
Timer2Enabled = True
End If
End Sub
Private Sub Timer2_Timer()
T2 = T2 + 1
If T2 >= nT2 Then
T2 = 0
'启动程序123exe,最好写成全路径,如:D:\123\123exe
Call Shell("123exe", vbHide)
Timer2Enabled = False
Timer1Enabled = True
End If
End Sub
创建picture 控件数组,三个command
Private Sub Command1_Click()Call ch(True, False, False, True, True, True, True)
End Sub
Private Sub Command2_Click()
Call ch(True, False, False, False, True, True, True)
End Sub
Private Sub Command3_Click()
Call ch(False, False, False, False, False, False, False)
End Sub
Private Sub Form_Load()
Command1Caption = "E"
Command2Caption = "F"
Command3Caption = "还原"
End Sub
Sub ch(a0 As Boolean, a1 As Boolean, a2 As Boolean, a3 As Boolean, a4 As Boolean, a5 As Boolean, a6 As Boolean)
Dim i As Integer
Picture1(0)Visible = a0
Picture1(1)Visible = a1
Picture1(2)Visible = a2
Picture1(3)Visible = a3
Picture1(4)Visible = a4
Picture1(5)Visible = a5
Picture1(6)Visible = a6
End Sub
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
在窗体中建立一个文本框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
Visual Basic (VB) 程序开发的步骤如下:
定义需求:明确程序的目的和功能,为下一步的设计制定蓝图。
设计:制定程序的流程图和界面设计。
创建项目:使用 Visual Studio 创建一个新的 Visual Basic 项目,并选择合适的模板。
编写代码:编写程序的主要代码逻辑。
测试:使用 Visual Studio 内置的调试功能对程序进行测试,确保程序功能正常。
部署:将程序打包成安装程序或发布为独立的可执行文件,供用户使用。
维护:定期对程序进行更新和维护,以保证其正常运行。
请注意,上述步骤是一般的程序开发步骤,对于具体项目,步骤可能会有所不同。
分类: 电脑/网络 >> 程序设计 >> 其他编程语言
解析:
其实比较简单啦,用一个窗体就可以实现啦!
我自己写的,你可以看看
Option Explicit
Dim strNumber As String
Dim strPoint As String
Dim dblNum1 As Double
Dim intOperator As Integer
'清除结果
Private Sub cmdGT_Click()
txtDisplayText = "0"
strNumber = ""
strPoint = ""
intOperator = 7
End Sub
'输入数字
Private Sub cmdNumber_Click(Index As Integer)
strNumber = strNumber & cmdNumber(Index)Caption
txtDisplayText = strNumber & strPoint
End Sub
Private Sub cmdOnOff_Click()
End
End Sub
'运算过程
Private Sub cmdOperator_Click(Index As Integer)
Dim dblnum2 As Double
'是第一次单击运算符时,将输入的值先赋给第一个数,否则赋值给第二个数进行运算
If intOperator = 7 Then
dblNum1 = CDbl(txtDisplayText)
Else
dblnum2 = CDbl(Val(txtDisplayText))
'根据输入的符号进行运算
'求普通运算
Select Case intOperator
Case 0
dblNum1 = dblNum1 + dblnum2
Case 1
dblNum1 = dblNum1 - dblnum2
Case 2
dblNum1 = dblNum1 dblnum2
Case 3
If dblnum2 <> 0 Then
dblNum1 = dblNum1 / dblnum2
Else
MsgBox "除数不能为“0”!请重新输入除数。", vbOKOnly + vbInformation, "除零错误"
Index = intOperator
End If
Case 6
dblNum1 = dblNum1 dblnum2 / 100
End Select
End If
'取得当前输入的运算符,以做下次运算
intOperator = Index
strNumber = ""
txtDisplay = CStr(dblNum1)
'判断是否为文本框中的数字加点
If Not txtDisplay Like "" Then
txtDisplayText = txtDisplayText & ""
End If
End Sub
Private Sub cmdOtherOper_Click(Index As Integer)
Dim dblNum As Double
'求平方根,平方,
dblNum = CDbl(Val(txtDisplayText))
Select Case Index
Case 0
'验证数据是否有效
If dblNum >= 0 Then
txtDisplayText = CStr(Sqr(dblNum))
Else
MsgBox "负数不能开平方根!", _
vbOKOnly + vbCritical, "开平方根错误"
End If
Case 1
txtDisplayText = CStr(dblNum ^ 2)
End Select
'判断是否为文本框中的数字加点
If Not txtDisplay Like "" Then
txtDisplayText = txtDisplayText & ""
End If
End Sub
Private Sub cmdPoint_Click()
strNumber = strNumber & strPoint
strPoint = ""
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'使被按下的数字键的对应按钮取得焦点
Select Case KeyCode
Case 48 To 57
cmdNumber(KeyCode - 48)SetFocus
Case 96 To 105
cmdNumber(KeyCode - 96)SetFocus
Case Else
'使按下的符号键对应的按钮取得焦点
If KeyCode = 107 Or (Shift = vbShiftMask And KeyCode = 187) Then
cmdOperator(0)SetFocus
cmdOperator_Click (0)
ElseIf KeyCode = 109 Or KeyCode = 189 Then
cmdOperator(1)SetFocus
cmdOperator_Click (1)
ElseIf KeyCode = 106 Or (Shift = vbShiftMask And KeyCode = 56) Then
cmdOperator(2)SetFocus
cmdOperator_Click (2)
ElseIf KeyCode = 111 Or KeyCode = 191 Then
cmdOperator(3)SetFocus
cmdOperator_Click (3)
ElseIf KeyCode = 13 Then
cmdOperator(7)SetFocus
cmdOperator_Click (7)
ElseIf KeyCode = 8 Then
cmdGTSetFocus
Call cmdGT_Click
End If
End Select
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
'将合法的数据输入到文本框
Select Case KeyAscii
Case 48 To 58
'调用数字键点击处理程序
cmdNumber_Click KeyAscii - 48
KeyAscii = 0
Case 46
'调用小数点输入
cmdPoint_Click
KeyAscii = 0
Case 13
'当敲击回车时,不能触发Form的 KeyUp 事件,因此在这里设置文本框的焦点
txtDisplaySetFocus
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
txtDisplaySetFocus
End Sub
Private Sub Form_Load()
strNumber = ""
strPoint = ""
intOperator = 7
End Sub
以上就是关于用vb编写程序全部的内容,包括:用vb编写程序、用vb编写一个程序。、急!用VB编写一个程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)