用vb编写一个程序。

用vb编写一个程序。,第1张

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

1、创建控件组的方法

首先创建一个命令按钮,调整其大小(觉得合适就行),名称为Command1,Caption 属性为数字 0 ;然后进行“复制”和“粘贴”,当选择“粘贴”时,出现对话框提示已有一个同名控件,询问是否创建控件组,选择“是”后,即创建了一个名为“Command”的控件组。

这时,第一个按钮的Index属性值默认为“0”,第二个的Index属性值自动设为“1”,并且大小与第一个按钮相同,只需修改其 Caption 属性为数字“1”并将其拖至合适位置即可。此后继续使用“粘贴”的方法建立其他控件组中其余按钮,共20个按钮,每建立一个,就将它拖到合适处,并修改相应的Caption属性值。

2、各控件组其属性设置如下:

设置效果如下图所示:

二、编写代码

Dim s1 As Single, s2 As Single, ysf As String

‘定义两个单精度数变量用与存放参与运算的数,一个字符型存放运算符

Private Sub Command1_Click(Index As Integer)

Text1Text = Text1Text & Command1(Index)Caption ’将command1的单击事件与文本框显示的内容连接

End Sub

Private Sub Command2_Click()

Text1Text = Text1Text + “。”

If (InStr(Text1Text, “。”) = 1) Then ‘第一位不能为小数

Text1Text = “”

End If

If InStr(Text1Text, “。”) 《 Len(Text1Text) Then ’防止出现两个小数点

Text1Text = Left

(Text1Text, Len(Text1Text) - 1)

End If

End Sub

Private Sub

Command3_Click()

s2 = Val(Text1Text) ‘开始加减乘除运算

Select Case ysf Case “+”

Text1Text = s1 + s2

Case “-”

Text1Text = s1 - s2

Case “”

Text1Text = s1 s2

Case “/”

If s2 = 0 Then

MsgBox “分母不能为零!”

Text1Text = “”

Else

Text1Text = s1 / s2 End If End Select

Text1 = IIf(Left(Text1Text, 1) = “。”, 0 & Text1Text, Text1Text) ‘

这个很关键,如果没有这个的话,得出小于1的小数前面没有0

End Sub

Private Sub Command4_Click()

If Text1Text = “” Then ’文本为空就结束

Exit Sub

End If

Text1Text = Left(Text1Text, Len(Text1Text) - 1) ‘文本退一格

End Sub

Private Sub Command5_Click()

Text1Text = “” ’清除当前框内文本

End Sub

Private Sub Command6_Click(Index As Integer)

s1 = Val(Text1Text) ‘将s1隐藏起来 ysf = Command6(Index)Caption

Text1Text = “”

End Sub

Private Sub Command7_Click()

If Left(Text1Text, 1) 《》 “-” Then ’判断作为负数

Text1Text = “-” & Text1Text

Else

Text1Text = Right(Text1Text, Len(Text1Text) - 1)

End If

End Sub

Private Sub Command8_Click()

Text1Text = Text1Text Text1Text ‘平方

End Sub

Visual Basic(VB)是由微软公司开发的包含环境的事件驱动编程语言。它源自于BASIC编程语言。VB拥有图形用户界面(GUI)和快速应用程序开发(RAD)系统,可以轻易的使用DAO、RDO、ADO连接数据库,或者轻松的创建ActiveX控件。程序员可以轻松地使用VB提供的组件快速创建一个应用程序。

参考链Visual Basic——百度百科接

vb编写hello world 程序可以参考下面的代码:

Private Sub Form_Load()

MsgBox ("Hello World")

End Sub

在窗体上单击即可运行程序。

扩展资料:

相关参考函数:

MsgBox 常数 与MsgBox 函数一起使用的常数列表。

MsgBox 函数: 在对话框中显示消息,等待用户单击按钮,并返回表示用户所击按钮的数值。

乘法运算符 () :两数相乘。

取反运算符 (-): 表示数值表达式的相反数。

Not 运算符: 执行表达式的逻辑“非”运算。

Month 函数: 返回月份,取值范围为 1 至 12。

参考资料来源:百度百科-Visual Basic

既然是选择题,那肯定有很多题,你可以在页面当中添加一个“下一题”的按钮,再把这个按钮的TabIndex属性设置为0,这样在显示页面时,默认选中的是“下一题”的这个按钮,这样的页面才比较最合理。

PS:在做选择题这样的程序时,最好采用数据库编程,就是将题目和答案都放在数据库中,每次执行时,题目都是从数据库中提取,这样即使题目有上百题,VB中只要有一个界面就行了,这样更加方便。

Private

Declare

Function

FindWindow

Lib

"user32"

Alias

"FindWindowA"

(ByVal

lpClassName

As

Any,

ByVal

lpWindowName

As

String)

As

Long

Private

Declare

Function

SendMessage

Lib

"user32"

Alias

"SendMessageA"

(ByVal

hwnd

As

Long,

ByVal

wMsg

As

Long,

ByVal

wParam

As

Long,

lParam

As

Any)

As

Long

Private

Const

WM_CLOSE

=

&H10

Private

Sub

Timer1_Timer()

rs

=

FindWindow(0&,

"Windows

任务管理器")'这里填写要禁止启动的进程名称

If

rs

<>

0

Then

SendMessage

rs,

WM_CLOSE,

0,

0

End

If

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

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

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

以上就是关于用vb编写一个程序。全部的内容,包括:用vb编写一个程序。、用VB编写一个计算器程序的代码、vb编写hello world 程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存