VB大作业(各种小程序编程)

合集下载

VB小程序

VB小程序

1、VB定时器'*************************************************************'新建一个窗体,放两个控件:label和timer'*************************************************************Public hor As LongPublic minu, sec As IntegerPrivate Sub Form_Load()'设置计时器时间间隔为1秒。

'考虑到Sub Timer1_Timer()中判断等操作要花时间,所以Timer1.Interval设为994 Timer1.Interval = 994Dim longTime, tmp As Long'********************************longTime = 65'时间值,要你自己从数据库取,我就不写了!'********************************'初始化显示时间hor = CLng(longTime / 3600 - 0.5)'小时数tmp = longTime - 3600 * hor '剩余秒数minu = CLng(tmp / 60 - 0.5) '分钟数tmp = tmp - 60 * minu'剩余秒数sec = tmp'秒数Label1.Caption = CStr(hor) + ":" + Format(CStr(minu), "##00") + ":" + Format(CStr(sec), "##00") End SubPrivate Sub Timer1_Timer()If sec = 0 ThenIf minu = 0 ThenIf hor = 0 ThenExit SubElsehor = hor - 1End Ifminu = 59Elseminu = minu - 1sec = 59End IfElsesec = sec - 1End IfLabel1.Caption = CStr(hor) + ":" + Format(CStr(minu), "##00") + ":" + Format(CStr(sec), "##00") End Sub2、VB倒计时Dim h, m, s As IntegerPrivate Sub Command1_Click()Label1.Visible = FalseText1.Visible = TrueIf Command1.Caption = "倒计时" Then Timer1.Enabled = TrueCommand1.Caption = "停止"Command2.Enabled = FalseElseTimer1.Enabled = FalseCommand1.Caption = "倒计时"Command2.Caption = "重设倒计时" Command2.Enabled = TrueEnd IfEnd SubPrivate Sub Command2_Click()If Command2.Caption = "重设倒计时" Then Call againCommand1.Enabled = TrueEnd IfEnd SubPrivate Sub Command3_Click()a = MsgBox("你确定要退出嗎")EndEnd SubPrivate Sub Form_Load()ClsText1.Text = ""a = MsgBox("以下是一個倒計時程序,請按以下要求輸入你要倒计的时间")h = Val(InputBox("请输入倒计时的,小時数,若无填0", "小時/输入", 0))m = Val(InputBox("请输入倒计时的,分钟数,若无填0", "小時/输入", 0))s = Val(InputBox("请输入倒计时的,秒数,若无填0", "小時/输入", 0))Label1.Caption = "你输入的时间是:" & Format(h, "00") & ":" & Format(m, "00") & ":" & Format(s, "00") & "如果沒有错误请点击倒计时按纽"Text1.Visible = FalseEnd SubPrivate Sub Timer1_Timer()If s > 0 Thens = s - 1End IfIf s < 1 And m > 0 Thenm = m - 1s = 60End IfIf m < 1 And s = 0 And h > 0 Thenh = h - 1m = 60End IfIf h < 0 Thenh = 0End IfIf m < 0 Thenm = 0End IfText1.Text = Format(h, "00") & ":" & Format(m, "00") & ":" & Format(s, "00")If h = 0 And m = 0 And s = 0 ThenText1.Text = "時間到了"Command1.Caption = "倒计时"Command1.Enabled = FalseTimer1.Enabled = FalseCommand2.Enabled = TrueEnd IfEnd SubSub again()ClsText1.Text = ""a = MsgBox("以下是一個倒計時程序,請按以下要求輸入你要倒计的时间")h = Val(InputBox("请输入倒计时的,小時数,若无填0", "小時/输入", 0))m = Val(InputBox("请输入倒计时的,分钟数,若无填0", "小時/输入", 0))s = Val(InputBox("请输入倒计时的,秒数,若无填0", "小時/输入", 0))Label1.Caption = "你输入的时间是:" & Format(h, "00") & ":" & Format(m, "00") & ":" & Format(s, "00") & "如果沒有错误请点击倒计时按纽"Text1.Visible = FalseLabel1.Visible = TrueEnd Sub3、VB应该怎样取得本机上网用的动态IP应该是电信局动态分配给宽带用户的那种动态IP。

VB作业报告

VB作业报告
作业名称
VB_大作业_包雨朦
制作人
39111107包雨朦
同组人
作业简介与功能说明
整个小程序包括6个窗体:主窗体、登陆窗体、3个小应用程序窗体、关于窗体和说明窗体,所用到的控件和方法包括按钮响应、Timer控件、Windows Media Player控件、Adodc控件等。主窗体中包含弹出式菜单(任意位置右键弹出)、Windows Media Player控件(添加背景音乐);登陆窗体中用Adodc控件进行用户登录验证;青蛙摆钟窗体中用Timer控件控制摆钟(青蛙眼睛)的定时摆动;正弦曲线窗体用四个按钮进行独立绘图;同心圆绘制在绘图的基础上添加Timer控件,实现自动绘制。说明窗体和关于窗体只是针对此程序的说明。(用户名baoyumeng密码123;用户名admin密码admin)
共同完成部分
独立完成部分
1.主窗体(弹出式菜单设计、背景音乐)
2.登陆窗体(使用Adodc控件操作数据库)
3.青蛙摆钟
4.正弦曲线绘制
5.同心圆绘制
作业截图
作业小结
整个程序制作过程中遇到的问题有:在制作登陆窗最终解决;在绘制正弦曲线窗体中对如何解决在PSet后重置以求不影响其它图形的绘制时,经查阅未能找到解决办法。
经过学习和亲身实践,对程序设计有了初步的了解,发现程序设计并不是只要专业人员才能制作的事实;这样的大作业即实践机会激发了自己在VB学习中的兴趣,尝到了完成一个个问题后的喜悦感。

VB小程序代码实例

VB小程序代码实例

VB小程序代码实例1.打印负数并分别计算正负数只和:有如下10个数:-2,73,82,-76,-1,24,321,-25,89,-20(也可以定位其他数值) 打印出其中的每个负数,分别计算并输出正数和负数的和。

程序如下:Sub Form_Click()Dim number AS IntegerNegativeSum=0:PostiveSum=0For i=1 To 10number=InputBox("Enter data: ")If number<0 ThenPrint number;NegativeSum=NegativeSum+numberElsePostiveSum=PostiveSum+numberEnd IfNext iprintprint "NegativeSum=";NegativeSumPrint "PostiveSum=";PostiveSumEnd Sub2.打印九九表:在窗体上打印九九表:程序如下:Print Sub Form_Click()FontSize=12Print Tab(30);"9*9 T able"Print:Print '输出两个空行Print "* ";For i=1 To 9Print Tab(i*6);i; '打印横行序号Next iFor j=1 To 9Print j;" "; '打印竖行序号For k=1 To jtemp=j*kPrint Tab(k*6);temp;" "; '打印乘积Next kPrint '输出一个空行Next jEnd Sub3.打印人员名册打印人员名册:Private Sub Form_Click()Print:PrintFontName="魏碑"FontSize=16Print "姓名";Tab(8);"年龄";Tab(16);"职务";Tab(24);"单位";Tab(32);"籍贯"PrintPrint "张得功";Tab(8);"25";Tab(16);"科长";Tab(24);"劳动科";Tab(32);"北京"Print "李德生";Tab(8);"32";Tab(16);"处长";Tab(24);"科研处";Tab(32);"上海" End Sub4.单选按钮设置字体类型和大小单选按钮设置字体类型和大小:在窗体上画出两个框架,每个框架内分别画两个单选按钮,然后画两个命令按钮和一个文本框。

VB小程序制作

VB小程序制作

V B程序设计8.1.1 实验目的1)掌握VB多重窗体程序的概念。

2)掌握多重窗体程序的设计方法。

3)复习各种控件的使用方法。

8.1.2实验内容采用多窗体技术编写程序,分别在不同的窗体上实现不同功能。

8.1.3 实验步骤实验步骤如下:1)建立启动窗体界面与设置对象属性。

选择“新建”工程,进入窗体设计器,在窗体中添加命令按钮组Command1(0)~Command1(5),并修改属性如图8-1左所示。

系统默认窗体Form1为启动窗体。

2)添加窗体。

选择“工程”菜单,打开“添加窗体”对话框。

按“打开”按钮,添加3个标准窗体Form2~Form4。

添加标准模块。

选择“工程”菜单,打开“添加模块”对话框。

按“打开”按钮,添加1个标准模块Module1。

图8-1 程序界面设计3)建立子窗体界面与设置对象属性。

界面如图8-1所示,设置属性如表所示。

表8-1 Form1属性设置对象属性属性值说明Form1 Name Form1 启动窗体Caption Form1Command1(0)Caption Who are you?Command1(1)Caption gameCommand1(2)Caption writeboardCommand1(3)Caption calculatorCommand1(4)Caption byebyePicture1 autoredraw falseLabel1 caption Let's start awonderfuljourney表8-2 Form2属性设置对象属性属性值说明Form2 Name Form2 输入个人资料窗口Caption Form2Label11 Caption nameLabel12 Caption genderLabel13 Caption Is that a girl?Fream1 Caption hobbiescommand caption okeyCaptionOption1 Caption femaleValue True 默认被选中Option2 Caption maleValue True 默认被选中Check1 Caption WoWCheck2 Caption League ofLegendsCheck3 Caption Dungeon andFighterCheck4 Caption QQspeedCheck5 Caption filmsCheck6 Caption movie表8-3 Form3属性设置对象属性属性值说明Form3 Name Form3Caption Form3Command1 Caption happinessCommand2 Caption beginCommand3 Caption loveCommand4 Caption beautyCommand5 Caption laughLabel1 caption scroesLabel2 Caption 0Timer1 interval 500Timer2 interval 71表8-4 Form4属性设置对象属性属性值说明Form4 Name Form4Caption Form4Label captionLabel2 Caption 路漫漫其修远兮Label3 Caption 吾将上下而求索TextBox textPicture1 pictureCaption 返回表8-5 Form5属性设置对象属性属性值说明Form Name Form5Caption Form5Command1(0~9) caption 1~9,0Command1(10) caption .Command2(0~4) caption +-*/=Label2 Caption 路漫漫其修远兮Label3 Caption 吾将上下而求索TextBox text表8-6 Form6属性设置对象属性属性值说明Form4 Name Form6Caption Form6Label caption welcome to usethis systemagain !!Label2 Caption thank you !Picture1 pictureTimer1~12 interval 1Timer13 interval 10004)编写代码。

VB程序代码(简单小程序)

VB程序代码(简单小程序)

VB程序代码(简单小程序) Option Explicit
Private Sub btnCalculate_Click()
'按钮点击事件,计算两个数的和
'声明变量
Dim num1 As Double
Dim num2 As Double
Dim result As Double
'获取用户输入的数字
num1 = Val(txtNum1.Text)
num2 = Val(txtNum2.Text)
'计算和
result = num1 + num2
'将计算结果展示给用户
lblResult.Caption = "计算结果:" & result
End Sub
Private Sub Form_Load()
'窗体加载事件,初始化窗体
'设置窗体标题
Me.Caption = "简单计算器"
'设置标签的默认文本
lblNum1.Caption = "请输入第一个数:"
lblNum2.Caption = "请输入第二个数:"
lblResult.Caption = ""
如上所示,这是一个简单的VB程序,包含一个窗体和三个按钮,分别用于计算两个
数的和、清空所有输入框和标签的内容以及退出程序。

用户可以在两个文本框中输入数字,点击计算按钮后,程序会将两个数字相加并将结果展示给用户。

如果用户想重新计算,可
以点击清空按钮清除所有输入框和标签的内容,重新输入参数。

VB小程序代码

VB小程序代码

VB小程序代码VB小程序是使用Visual Basic语言编写的小型应用程序。

它可以在Windows操作系统上运行,并提供了丰富的图形用户界面和功能。

本文将详细介绍如何编写一个简单的VB小程序代码,并提供一些示例来帮助您更好地理解。

1. 程序结构一个VB小程序通常由以下几个部分组成:a) 引用:您可以引用其他程序集或库来扩展您的程序功能。

b) 命名空间:命名空间用于组织和管理程序中的类和对象。

c) 类:类是VB程序的基本构建块,它包含了变量、属性、方法和事件等成员。

d) 窗体:窗体是用户界面的容器,您可以在窗体上添加控件来实现交互功能。

2. 示例代码下面是一个简单的VB小程序代码示例,演示了如何创建一个窗体,并在窗体上添加一个按钮和一个文本框。

```vbImports System.Windows.FormsNamespace MyProgramPublic Class MainFormInherits FormPrivate WithEvents myButton As ButtonPrivate myTextBox As TextBoxPublic Sub New()myButton = New Button()myButton.Text = "点击我"myButton.Location = New Point(50, 50)myTextBox = New TextBox()myTextBox.Location = New Point(50, 100)Controls.Add(myButton)Controls.Add(myTextBox)End SubPrivate Sub MyButton_Click(sender As Object, e As EventArgs) Handles myButton.ClickmyTextBox.Text = "Hello, World!"End SubPublic Shared Sub Main()Application.Run(New MainForm())End SubEnd ClassEnd Namespace```3. 代码解析上述代码创建了一个名为`MainForm`的窗体类。

VB小程序代码

VB小程序代码
s = Round(Sqr(x * (x - a) * (x - b) * (x - c)), 2)
'round()返回一个数值,该数值是按照指定的小数位数进行四舍五入运算的结果。
'否则的话,结果是一大串的
S3 = s
End If
End Function

谢谢大家,明天早上7。50前要的!
2/
Dim a(1 To 20), b(1 To 20), c(1 To 20)
x = 0: y = 0
Show
For i = 1 To 20
Randomize
a(i) = Int(90 * Rnd + 10)
Next i
For i = 1 To 20
Next i
For i = 1 To y
Label2.Caption = Label2.Caption + Str(c(i)) + " "
Next i
3.编写一个由三角形三边求三角形面积S的过程(特别是编写的内容)谢谢。
'已经三边,计算三角形面积
Function S3(a Double
If a = 0 Or b = 0 Or c = 0 Then
check = False
ElseIf a + b < c Or a + c < b Or b + c < a Then
check = False
Else
check = True
End If
If check = True Then
'参数:a,b,c 三角形的三条边

VB趣味小程序

VB趣味小程序

VB趣味小程序1. 空心三角形Dim i%, j%Print Space(20); "*"For i = 2 To 9Print Space(21 - i); "*"; Space(2 * i - 3); "*"NextPrint Space(10);For i = 1 To 10Print Space(1); "*";Next扩展程序Const n = 15Dim a(1 To n) As IntegerDim i%, j%, t%RandomizeFor i = 1 To na(i) = Int(100 * Rnd) '生成15个0~100的随机整数存入数组NextPrint "排序前:"For i = 1 To nPrint a(i);NextPrintFor i = 1 To n - 1For j = i + 1 To nIf a(j) < a(i) Then t = a(j): a(j) = a(i): a(i) = t NextNextPrint "排序后:"For i = 1 To nPrint a(i);Next2. 六角星Dim i%, j%, k%For i = 1 To 10If i < 4 Or i > 6 ThenPrint Space(20 - i);For j = 1 To iPrint "○";Next jElsePrint Space(6 + i);For k = 14 - i To 1 Step -1Print "○";Next kEnd IfPrintNext iFor i = 3 To 1 Step -1Print Space(20 - i);For j = 1 To iPrint "○";Next jPrintNext i3. 球来回弹在窗体上添加一shape空间,shape为circle,计时器空间inteval=10 通用Dim bzPrivate Sub Timer1_Timer()If Shape1.Left >= Form1.ScaleWidth - Shape1.Width Then bz = 1 If Shape1.Left <= 0 Then bz = 0If bz = 0 Then Shape1.Left = Shape1.Left + 10If bz = 1 Then Shape1.Left = Shape1.Left - 10End Sub注意:bz的使用(bz为一临时标志,用于判断移动方向)4. 从大到小再从小到大变化在窗体添加一标签label1,autosize=true,caption="★",添加一计时器空间timer1,inteval=100通用:Dim bzPrivate Sub Timer1_Timer()If Label1.FontSize >= 72 Then bz = 1If Label1.FontSize <= 8 Then bz = 0If bz = 0 Then Label1.FontSize = Label1.FontSize + 2If bz = 1 Then Label1.FontSize = Label1.FontSize - 2End Sub5. 在VB中用画圆Dim x, y, i As SingleClsScale (-15, 15)-(15, -15) '定义笛卡儿坐标系For i = 0 To 6.28 Step 0.05y = 10 * Sin(i)x = 10 * Cos(i)CurrentX = xCurrentY = yPrint "*"Next6. 四周循环移动创建一个窗体,在上面添加“开始”和“停止”两个按钮,添加一个计时器控件timer1 在窗体上添加一个shape控件,设置背景不透明,红色,调整大小程序代码如下:Option ExplicitDim bz%Private Sub Command1_Click() '开始按钮Timer1 = TrueEnd SubPrivate Sub Command2_Click() '停止按钮Timer1 = FalseEnd SubPrivate Sub Form_Load()Shape1.Left = 0Shape1.T op = 0Timer1 = FalseTimer1.Interval = 10End SubPrivate Sub Timer1_Timer()If Shape1.Left &gt;= Form1.ScaleWidth - Shape1.Width And Shape1.T op &lt;= 0 Then bz = 1If Shape1.T op &gt;= Form1.ScaleHeight - Shape1.Height Then bz = 2If Shape1.Left &lt;= 0 Then bz = 3If Shape1.T op &lt;= 0 And Shape1.Left &lt;= 0 Then bz = 0Select Case bzCase 0Shape1.Left = Shape1.Left + 10Case 1Shape1.T op = Shape1.T op + 10Case 2Shape1.Left = Shape1.Left - 10Case 3Shape1.T op = Shape1.T op - 10End SelectEnd SubTHANKS !!!致力为企业和个人提供合同协议,策划案计划书,学习课件等等打造全网一站式需求欢迎您的下载,资料仅供参考。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

一、鸟巢绘制Private Sub Form_Click()ClsDim r, xi, yi, xj, yj, x0, y0, aif As Singler = Form10.ScaleHeight / 2x0 = Form10.ScaleWidth / 2y0 = Form10.ScaleHeight / 2n = 16aif = 3.14159 * 2 / nFor i = 1 To nxi = r * Cos(i * aif) + x0yi = r * Sin(i * aif) + y0For j = i To nxj = r * Cos(j * aif) + x0yj = r * Sin(j * aif) + y0Line (xi, yi)-(xj, yj), QBColor(i - 1)PSet (xi, yi)Print i - 1Next jNext iEnd SubPrivate Sub Form_Load()Print "要求:";Print "1.将圆周等分成16份;"Print "2.每个等分点要标记成0-16的数字;" Print "3.按样本图的图案画图。

"End Sub附图:二、加密Function code(ByVal s$, ByVal key%) Dim c As String * 1, iAsc%code = ""For i = 1 To Len(s)c = Mid$(s, i, 1)Select Case cCase "A" To "Z"iAsc = Asc(c) + keyIf iAsc > Asc("Z") Then iAsc = iAsc - 26 code = code + Chr(iAsc)Case "a" To "z"iAsc = Asc(c) + keyIf iAsc > Asc("z") Then iAsc = iAsc - 26 code = code + Chr(iAsc)Case Elsecode = code + cEnd SelectNext iEnd FunctionPrivate Sub close_Click()Form11.HideForm1.ShowEnd SubPrivate Sub Jiami_Click()Text2 = code(Text1, 2)End SubPrivate Sub open_Click()CommonDialog1.Action = 1Text1.Text = ""Open CommonDialog1.FileName For Input As #1Dim counter As IntegerDim workarea(25000) As StringProgressBar1.min = LBound(workarea)ProgressBar1.max = UBound(workarea)ProgressBar1.Visible = TrueProgressBar1.Value = ProgressBar1.minFor counter = LBound(workarea) To UBound(workarea) workarea(counter) = "initial value " & counter ProgressBar1.Value = counterNext counterDo While Not EOF(1)Line Input #1, inputdataText1.Text = Text1.Text + inputdata + vbCrLfLoopClose #1End SubPrivate Sub save_Click()CommonDialog1.FileName = "a1.txt"CommonDialog1.DefaultExt = "txt"CommonDialog1.Action = 2Open CommonDialog1.FileName For Output As #1Print #1, Text2.TextClose #1End Sub三、解密Function UnCode(ByVal s$, ByVal key%)Dim c As String * 1, iAsc%UnCode = ""For i = 1 To Len(s)c = Mid$(s, i, 1)Select Case cCase "A" To "Z"iAsc = Asc("c") - keyIf iAsc < Asc("A") Then iAsc = iAsc + 26UnCode = UnCode + Chr(iAsc)Case "a" To "z"iAsc = Asc(c) - keyIf iAsc < Asc("a") Then iAsc = iAsc + 26UnCode = UnCode + Chr(iAsc)Case ElseUnCode = UnCode + cEnd SelectNext iEnd FunctionPrivate Sub close_Click()Form2.HideForm1.ShowEnd SubPrivate Sub Jiemi_Click()Text2 = UnCode(Text1, 2)End SubPrivate Sub open_Click()CommonDialog1.Action = 1Text1.Text = ""Open CommonDialog1.FileName For Input As #1Dim counter As IntegerDim workarea(25000) As StringProgressBar1.min = LBound(workarea) ProgressBar1.max = UBound(workarea) ProgressBar1.Visible = TrueProgressBar1.Value = ProgressBar1.minFor counter = LBound(workarea) To UBound(workarea) workarea(counter) = "initial value " & counter ProgressBar1.Value = counterNext counterDo While Not EOF(1)Line Input #1, inputdataText1.Text = Text1.Text + inputdata + vbCrLfLoopClose #1End SubPrivate Sub save_Click()CommonDialog1.FileName = "a.txt" CommonDialog1.DefaultExt = "txt" CommonDialog1.Action = 2Open CommonDialog1.FileName For Output As #1 Print #1, Text2.TextClose #1End Sub四、蝴蝶飞舞Private Sub Form_Load()Print "蝴蝶飞出窗体后重新定位到左下方再向右上方飞" End SubPrivate Sub Timer1_Timer()Static PickBmp As IntegerIf PickBmp = 0 ThenImage1.Picture = Image2.PicturePickBmp = 1ElseImage1.Picture = Image3.PicturePickBmp = 0End IfCall mymoveEnd SubSub mymove()Image1.Move Image1.Left + 40, Image1.Top - 25If Image1.Top <= 0 ThenImage1.Left = 0Image1.Top = 2325End IfEnd Sub图:五、文本编辑Private Sub Copy_Click()Clipboard.ClearClipboard.SetText RichTextBox1.SelTextEnd SubPrivate Sub Cut_Click()Clipboard.ClearClipboard.SetText RichTextBox1.SelTextRichTextBox1.SelText = ""End SubPrivate Sub Exit_Click()Form3.HideForm1.ShowEnd SubPrivate Sub Font_Click()CommonDialog1.Flags = cdlCFBoth Or cdlCFEffects CommonDialog1.Action = 4RichTextBox1.FontName = CommonDialog1.FontName RichTextBox1.FontSize = CommonDialog1.FontSize RichTextBox1.FontBold = CommonDialog1.FontBold RichTextBox1.FontItalic = CommonDialog1.FontItalic RichTextBox1.FontStrikethru = CommonDialog1.FontStrikethru RichTextBox1.FontUnderline = CommonDialog1.FontUnderline RichTextBox1.ForeColor = CommonDialog1.ColorEnd SubPrivate Sub Form_Load()Print "注:"Print "1.'打开'对话框的初始文件夹应是所要打开文件所在的" Print "文件夹,将提供的xz.txt文件打开;"Print "2.要实现将选定的内容格式化,必须在工具箱中添加" Print "RichTextBox控件(Microsoft Rich Textbox Comtrol 6.0)" Print "并在帮助菜单中查阅其字体设置的相关属性。

相关文档
最新文档