vb可以写的程序很多,比如我学的就是用于测绘方面的
对于初学者来说,简单的啊需要了解vb的三要素“对象”“事件”“方法”
比如单机窗体加载一张作为背景:
private sub form1_()load
form1picture=loadpicture("") ,""号内为需要加载的的路径后面在加上\名格式。就可以了
end sub
再如单机命令按钮,窗体出现文字:
private sub command_()click
print"你好" '因号内为你要窗体显示的文字
end sub
'//首先你需要在Form1上面创建一个名称为Text1的TextBox
'//一个名为Command1的按钮和一个名为Command2的按钮
'//一个名为Picture1的PictureBox
'//然后再创建一个Form2,上面必须有一个名为Text1的TextBox
'//Form2上面也要有一个名为Command1的按钮和一个名为Command2的按钮
'//然后将下面的代码找对地方复制过去就行了
'//再添加一个Form3
'//关于Tab顺序的问题,你自己去调每个可 *** 作控件的TabIndex
'//Form2的TextBox需要填上完整路径比如:C:\桌面\text_XXXXtxt
'//另外如果可以能不能留下你的邮箱······ 这样发真的很麻烦···
'////////////////////////////////////////////////////////////////////////////////////////////////////////////Form1
Dim teum As String
Option Explicit
Private Sub Check1_Click(index As Integer) '//检测点击的哪一个复选框
If p = True Then
p = False
Exit Sub
End If
If Check1(index)Value = 1 Then
teum = Text1text '//记录未排序的结果
Else
Text1text = teum '//将未排序的结果返还给文本框
model = 0
End If
Select Case index
Case 1
Call click(Check1(1))
model = 1
Case 2
Call click(Check1(2))
model = 2
End Select
End Sub
Private Sub Command1_Click() '//生成乘法表(这个地方推荐你改改··· 我不知道你打算把这个打印出来的乘法表放哪里···)
If checkNumLen(Form1Text1text) = False Then
Exit Sub
End If
Load Form3
End Sub
Private Sub Command2_Click() '//打开生成文件窗口,并将其设置为模式窗口
Form2Show vbModal
End Sub
Private Sub Form_Load()
model = 0
End Sub
Private Sub Text1_Change()
Text1BackColor = vbWhite
End Sub'/////////////////////////////////////////////////////////////////////////////////////////////////////////////Form2
Option Explicit
Private Sub Command1_Click()
Dim file As String
Dim s As String
Dim txt As String
p = True
If Form1Text1text = "" Then
MsgBox "被写入的数据不能为空!", vbCritical, "提示:"
p = False
Exit Sub
ElseIf checkNumLen(Text1text) = False Then
Form1Text1BackColor = &HC0C0FF
MsgBox "被写入数据不符合条件!", vbCritical, "提示:"
p = False
Exit Sub
End If
If model = 0 Then
s = "未排序的"
ElseIf model = 1 Then
s = "从小到大排序的"
ElseIf model = 2 Then
s = "从大到小排序的"
End If
If Text1text = "" Then
MsgBox "请输入文件路径!", vbCritical, "提示:"
p = False
ElseIf Dir(Text1text) = "" Then
MsgBox Text1text & vbCrLf & "文件不存在!", vbExclamation, "提示:"
p = False
Else
file = Text1text
txt = Form1Text1text
If MsgBox("确定要写入当前数据?" & vbCrLf & "当前数据是" & s, vbExclamation + vbOKCancel, "提示:") = vbOK Then
Open file For Output As #1 '//打开目标文件,访问方式:顺序访问
Write #1, Val(txt)
Close #1 '//关闭目标文件
MsgBox "写入完毕!", vbInformation, "提示:"
End If
End If
End Sub
Private Sub Command2_Click()
Dim file As String
Dim txt As String
Dim txtread As String
If Text1text = "" Then
MsgBox "请输入文件路径!", vbCritical, "提示:"
Exit Sub
ElseIf Dir(Text1text) = "" Then
MsgBox Text1text & vbCrLf & "文件不存在!", vbExclamation, "提示:"
Exit Sub
Else
file = Text1text
txt = Form1Text1text
Open file For Input As #1 '//打开目标文件,访问方式:顺序访问
Do
Line Input #1, txtread
txt = txt & txtread
Loop Until EOF(1) = True
Close #1 '//关闭目标文件
End If
If txt = "" Then
MsgBox "文件为空!", vbExclamation, "提示:"
ElseIf IsNumeric(txt) = False Then
MsgBox "文件内包含非法字符", vbCritical, "提示:"
ElseIf Len(txt) < 3 Then
MsgBox "文件内容不足三位数字", vbCritical, "提示:"
ElseIf IsNumeric(Mid(txt, 3, 1)) = False Then
MsgBox "文件内容第3位不是数字!", vbCritical, "提示:"
Else
MsgBox "文件符合要求!", vbInformation, "提示:"
End If
End Sub'///////////////////////////////////////////////////////////////////////////////////////////////////////////////Form3
Option Explicit
Private Sub Form_Load()
Dim num As Integer
Dim i As Integer
Dim j As Integer
Dim space As String
Show
num = Val(Mid(Form1Text1text, 3, 1)) Mod 2
If num = 0 Then
For i = 1 To 9
For j = 1 To i
If j = 2 And i = 4 Or j = 2 And i = 3 Then
space = " "
Else
space = " "
End If
Print j & "×" & i & "=" & j i & space;
Next j
Next i
Else
For i = 9 To 1 Step -1
For j = 1 To i
If j = 2 And i = 4 Or j = 2 And i = 3 Then
space = " "
Else
space = " "
End If
Print j & "×" & i & "=" & j i & space;
Next j
Next i
End If
End Sub'///////////////////////////////////////////////////////////////////////////////模块文件
Option Explicit
Public p As Boolean
Public model As Integer
Public Function sort(content As String, style As Integer) '//排序函数,content 必选参数,需要排序的内容;style 必选参数,用于规定排序方式
Dim a(9) As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim t As Integer
For i = 0 To Len(content) - 1 '//给排序数组用赋值
a(i) = Val(Mid(content, i + 1, 1))
Next i
'//排序方法:选择排序
If style = 1 Then '//从小到大
For j = 0 To Len(content) - 2
For k = j + 1 To Len(content) - 1
If a(j) > a(k) Then
t = a(j)
a(j) = a(k)
a(k) = t
End If
Next k
Next j
ElseIf style = 2 Then '//从大到小
For j = 0 To Len(content) - 2
For k = j + 1 To Len(content) - 1
If a(j) < a(k) Then
t = a(j)
a(j) = a(k)
a(k) = t
End If
Next k
Next j
End If
For i = 0 To Len(content) - 1 '//排序将结果交给文本框
sort = sort & a(i)
Next i
End Function
Public Function checkNumLen(content As String) '//条件检测函数,content 必选参数,需要排序的内容
Dim i As Integer
If Len(Form1Text1text) < 8 Or Len(Form1Text1text) > 10 Then
If p = False Then
Form1Text1BackColor = &HC0C0FF
MsgBox "请输入8~10位的正整数", vbCritical, "提示:"
model = 0
Form1Text1SetFocus
p = True
For i = 1 To Form1Check1UBound
Form1Check1(i)Value = 0
Next i
p = False
End If
Else
checkNumLen = True
End If
End Function
Public Function click(Obj As Object) '//点击检测函数
Dim i As Integer
If checkNumLen(Form1Text1text) = False Then
Exit Function
Else
If ObjValue = 1 Then
For i = 1 To Form1Check1UBound
If i <> Objindex Then
Form1Check1(i)Value = 0
End If
Next i
Form1Text1text = sort(Form1Text1text, Objindex) '//调用排序函数
End If
End If
Form1Text1SetFocus
Form1Text1SelStart = Len(Form1Text1text)
End Function
用VB写一些小程序比较有意思,想一些控件,简单的MP3等。
vb是Visual Basic的简称,是由美国微软公司于1991年开发的一种可视化的、面向对象和采用事件驱动方式的结构化高级程序设计语言,可用于开发 Windows 环境下的各类应用程序。它简单易学、效率高,且功能强大可以与 Windows 专业开发工具SDK相媲美。在Visual Basic环境下,利用事件驱动的编程机制、新颖易用的可视化设计工具,使用Windows内部的广泛应用程序接口(API)函数,动态链接库(DLL)、对象的链接与嵌入(OLE)、开放式数据连接(ODBC)等技术,可以高效、快速地开发Windows环境下功能强大、图形界面丰富的应用软件系统。
也就是说,用VB编程像画图。很有意思。
以上就是关于一般用vb编写什么程序具体举几个简单的例子全部的内容,包括:一般用vb编写什么程序具体举几个简单的例子、用vs2012编写vb程序。在线等急求!!!!、用vb写什么程序有意思谢谢。等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)