VB小程序
使用VB设计一个简单的小程序计算圆的面积
使用VB设计一个简单的小程序计算圆的面积下面是一个使用VB设计的简单程序,用于计算圆的面积:
Private Sub CalculateArea_Click
Dim radius As Double
Dim area As Double
'获取用户输入的半径值
radius = CDbl(InputBox("请输入圆的半径:"))
area = Math.PI * radius * radius
'显示计算结果
MsgBox "圆的面积为:" & area
End Sub
然后,程序使用Math.PI常量和半径值来计算圆的面积,将结果保存到area变量中。
最后,通过MsgBox函数将面积值以提示框的形式显示出来。
需要注意的是,Math.PI是VB中定义的一个常量,它表示圆周率的值。
对于这个简单的程序,可能描述不到1200字以上。
但是,可以在设计程序时添加更多的功能和逻辑,以丰富程序的功能和交互性。
例如,可以添加错误处理来处理用户输入错误的情况,或者可以添加对输入值的验证,确保输入的是有效的半径值等等。
另外,可以通过添加更多控件和功能,如文本框、滑动条等,来实现更复杂的计算功能。
例如,可以添加一个滑动条控件来调整半径值,实时显示面积的变化。
希望以上内容对您有所帮助。
如果您有其他问题,欢迎继续提问。
VB小程序制作
VB小程序制作VB小程序是使用Visual Basic编程语言开发的一种小型应用程序。
它可以在Windows操作系统上运行,并且具有用户友好的界面和丰富的功能。
下面是VB小程序制作的标准格式文本:1. 简介VB小程序是一种基于Visual Basic编程语言开发的小型应用程序。
它可以在Windows操作系统上运行,并且具有用户友好的界面和丰富的功能。
VB小程序可以用于各种用途,如数据处理、图形界面设计、游戏开发等。
2. 功能需求根据具体的需求,确定VB小程序的功能需求。
例如,如果是一个数据处理程序,需要实现数据的输入、处理和输出功能;如果是一个图形界面设计程序,需要提供丰富的界面组件和设计工具;如果是一个游戏开发程序,需要提供游戏引擎和相关的开发工具等。
3. 界面设计根据VB小程序的功能需求,设计用户界面。
界面设计应该简洁、直观,并且符合用户的使用习惯。
可以使用VB的界面设计工具,如窗体设计器、控件工具箱等,来设计和布局界面。
4. 数据处理和逻辑实现根据功能需求,编写VB代码来实现数据处理和逻辑功能。
可以使用VB的编程语法和函数库,如条件语句、循环语句、数组、字符串处理等,来实现程序的功能。
同时,可以利用VB的数据库连接和操作功能,来实现数据的读取、存储和查询等功能。
5. 错误处理和调试在开发过程中,需要注意错误处理和调试。
可以使用VB的调试工具,如断点调试、变量监视等,来定位和解决程序中的错误。
同时,可以使用错误处理机制,如异常捕获和处理,来处理程序运行中可能出现的异常情况。
6. 测试和优化完成VB小程序的开发后,进行测试和优化。
可以使用测试用例来验证程序的功能和性能。
如果发现问题或性能瓶颈,可以对程序进行优化,如改进算法、减少资源占用等,以提升程序的质量和性能。
7. 打包和发布完成测试和优化后,对VB小程序进行打包和发布。
可以使用VB的发布工具,将程序打包成可执行文件或安装程序,方便用户安装和使用。
vb小程序设计实例
VB小程序设计实例引言VB(Visual Basic)是一种广泛应用于Windows平台的编程语言,它具有简单易学的特点,因此非常适合初学者入门。
本文将以一个实际的VB小程序设计实例为例,介绍如何使用VB语言进行简单的程序开发。
项目背景我们的目标是创建一个简单的VB小程序,用于管理学生信息。
该程序将允许用户添加、删除和修改学生的基本信息,例如姓名、年龄和班级。
此外,用户还可以根据特定条件检索学生信息,并显示学生列表。
设计步骤1. 创建VB项目首先,打开Visual Studio并选择“创建新项目”,然后选择“Visual Basic”作为项目类型。
接下来,选择“Windows Forms应用程序”作为模板,并给项目命名。
点击“确定”按钮以创建新的VB项目。
2. 设计用户界面在VB中,用户界面是通过拖放控件来创建的。
在“工具箱”中选择所需的控件,例如按钮、文本框和标签,并将它们放置在窗体上。
使用控件的属性面板可以更改它们的外观和行为。
3. 编写代码现在,我们需要为各个控件添加相应的事件处理程序。
例如,当用户点击一个按钮时,我们需要执行特定的操作。
首先,选择要添加事件处理程序的控件,然后在属性面板中找到“事件”部分。
在相应的事件上双击以创建并打开处理程序。
4. 实现学生信息管理功能在代码中,我们需要定义学生类和学生信息管理类。
学生类包含学生的属性,例如姓名、年龄和班级。
学生信息管理类包含对学生信息进行增删改查的方法。
我们可以使用集合类来存储学生对象,并使用LINQ进行查询操作。
在事件处理程序中调用适当的方法以实现相应的功能。
5. 运行和测试程序在完成代码的编写之后,我们可以点击“运行”按钮来启动程序。
通过与程序交互,测试各个功能是否按预期工作。
如果发现问题,可以调试程序并对代码进行调整。
6. 部署和发布程序一旦我们满意了程序的功能和性能,我们可以将程序部署和发布给其他人使用。
在Visual Studio中,选择“生成”菜单并点击“发布”选项。
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小程序是使用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小游戏简介VB小游戏是一款基于Visual Basic(VB)编程语言的游戏开发平台。
它提供了一系列的工具和框架,让开发者能够快速地创建各种类型的小游戏。
这些游戏可以运行在Windows操作系统上,并且具有良好的用户界面和交互性。
安装和设置安装Visual Studio要开始使用VB小游戏,首先需要安装Visual Studio开发环境。
Visual Studio 是一款强大的集成开发环境,支持多种编程语言,包括Visual Basic。
可以从Visual Studio官方网站上下载并安装该软件。
创建新项目安装完成后,打开Visual Studio并选择“新建项目”。
在项目模板中选择“Windows Forms App (.NET Framework)”模板,并为项目指定名称和存储位置。
点击“确定”按钮后,Visual Studio会自动生成一个新的VB游戏项目,并打开项目的主窗体。
添加游戏界面在VB小游戏中,游戏界面通常由一个或多个窗体组成。
可以通过使用Windows Forms Designer来设计游戏界面。
可以在工具箱中找到各种控件(例如按钮、标签、文本框等),并将其拖放到窗体上。
还可以设置控件的属性来定义其外观和行为。
添加游戏逻辑除了游戏界面外,还需要在VB小游戏中添加游戏的逻辑和交互性。
可以在窗体的代码文件中编写代码,来定义游戏逻辑和处理用户输入。
可以使用Visual Basic的各种语法和库函数来实现所需的功能,例如处理键盘事件、更新游戏状态、计算分数等。
编程示例以下是一个简单的VB小游戏示例,名为“猜数字”。
游戏要求玩家猜一个预先设定的数字,直到猜中为止。
```vb Public Class Form1 Dim targetNumber As Integer Dim tries As IntegerPrivate Sub Form1_Load(sender As Object, e As EventArgs) Handles MyB ase.LoadRandomize()targetNumber = CInt(Int((100 * Rnd()) + 1))tries = 0End SubPrivate Sub btnGuess_Click(sender As Object, e As EventArgs) Handles bt nGuess.ClickDim guess As Integer = CInt(txtGuess.Text)tries += 1If guess = targetNumber ThenMessageBox.Show(\。
VB小程序制作
VB程序设计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 a wonderfuljourney表8-2 Form2属性设置对象属性属性值说明Form2 Name Form2 输入个人资料窗口Caption Form2Label11 Caption nameLabel12 Caption genderLabel13 Caption Is that a girl?Fream1 Caption hobbiescommand caption okey表8—3 Form3属性设置表8-4 Form4属性设置表8-5 Form5属性设置表8-6 Form6属性设置4)编写代码。
用vb做一个程序,表达自己的爱意
用Vb做一个小程序,情人节那天向“她(他)”表白吧!!!首先,你得打开vb这个软件,会有如下这么一个对话框
就选择第一个,然后进入,出现如下的界面
然后再选择红线处的工具
点击后,在如下界面拖画出一个文本框
然后再选择工具栏上的这个工具,点击后,同上一样,在界面上拖画,画两个
然后再在“标题栏名为Form1”这个窗体上双击鼠标左键,出现一个输入代码的框框
在里面输入
LABEL1.caption=”“
Command1.caption=”确定”
Command2.caption=”退出”
然后,点击关闭
再在界面上双击command1,进入后,在中中间输入LABEL1.caption=”I Love You”
然后,点击关闭
再在界面上双击command2,进入后,在中间输入end。
随后,在点击这个按钮
最后,要把这个保存,点击“文件”下的“生成工程1.exe”,然后保存在桌面即可。
当情人节当天,你就可以把这个小程序发给你心爱的她(他),让她(他)感动,感动吧!注:这中间的标点符号,均为英文状态下输入的
小女落樱。
vba小程序实例
vba小程序实例VBA小程序实例VBA(Visual Basic for Applications)是一种用于宏编程的编程语言,常用于Microsoft Office软件中。
通过编写VBA小程序,我们可以实现自动化处理数据、操作软件等功能。
本文将通过几个实例来展示VBA小程序的具体应用。
一、实例一:批量处理Excel表格数据假设我们需要对一个包含大量数据的Excel表格进行处理,例如筛选、排序、求和等操作。
使用VBA小程序可以大大提高工作效率。
我们打开Excel软件,按下“Alt + F11”快捷键,打开VBA编辑器。
然后在工程资源管理器中选择“插入”-“模块”,在新建的模块中编写VBA代码。
代码示例:Sub Data_Processing()' 定义变量Dim ws As WorksheetDim rng As Range' 设置工作表和数据范围Set ws = ThisWorkbook.Worksheets("Sheet1")Set rng = ws.Range("A1:E10")' 进行数据处理rng.AutoFilter Field:=1, Criteria1:=">100" ' 筛选大于100的数据' 其他数据处理操作...End Sub上述代码中,我们首先定义了两个变量ws和rng,分别表示工作表和数据范围。
然后通过设置工作表和数据范围,我们可以对指定范围内的数据进行处理。
例如,上述代码中使用了“AutoFilter”方法对第一列数据进行筛选,只显示大于100的数据。
二、实例二:自动发送邮件在日常工作中,我们经常需要发送邮件给固定的收件人。
使用VBA 小程序,我们可以编写一个自动发送邮件的程序,实现批量发送邮件的功能。
我们同样需要打开VBA编辑器。
然后在工程资源管理器中选择“插入”-“模块”,在新建的模块中编写VBA代码。
人人都会用的VB游戏小程序代码
人人都会用的VB游戏小程序代码人人都会用的 VB 游戏小程序代码3. 球来回弹在窗体上添加一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 为一临时标志,用于判断移动方向2. 六角星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 -1 Print "○ ";Next kEnd IfPrintNext iFor i = 3 To 1 Step -1 Print Space(20 - i;For j = 1 To iPrint "○ ";Next jPrintNext i1. 空心三角形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的随机整数存入数组 Next Print "排序前:"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 = tNextNextPrint "排序后:"For i = 1 To nPrint a(i;Next3. 球来回弹在窗体上添加一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(ix = 10 * Cos(iCurrentX = 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.Top = 0Timer1 = FalseTimer1.Interval = 10End SubPrivate Sub Timer1_Timer(If Shape1.Left >= Form1.ScaleWidth - Shape1.Width And Shape1.Top <= 0 Then bz = 1If Shape1.Top >= Form1.ScaleHeight - Shape1.Height Then bz = 2If Shape1.Left <= 0 Then bz = 3If Shape1.Top <= 0 And Shape1.Left <= 0 Then bz = 0Select Case bzCase 0Shape1.Left = Shape1.Left + 10Case 1Shape1.Top = Shape1.Top + 10Case 2Shape1.Left = Shape1.Left - 10Case 3Shape1.Top = Shape1.Top - 10End SelectEnd Sub。
VB小程序源代码
Private Sub Command1_Click()Clipboard.SetText Text1.SelTextEnd SubPrivate Sub Command2_Click()Text2.SelText = Clipboard.GetTextEnd Sub上海问题Private Sub Command1_Click()If Option3.Value = True ThenText1 = "You are right"ElseText1 = "You are wrong"End IfEnd Sub中心问题Private Sub Form_Resize()Command1.Left = (Form1.ScaleWidth - Command1.Width) / 2 Command1.Top = (Form1.ScaleHeight - Command1.Height) / 2 Command1.Width = 0.2 * Form1.ScaleWidthEnd Sub曲线问题Private Sub Form_Paint()Scale (0, 0)-(3000, 3000)Form1.DrawWidth = 5Form1.ForeColor = RGB(255, 0, 0)Line (0, 1500)-(3000, 1500)Line (1500, 0)-(1500, 3000)Circle (1500, 1500), 35For x = 0 To 3000y = 1500 - 200 * (Sin((x - 1500) * 3.1415926 / 180)) PSet (x, y)Next xEnd Sub查找Private Sub Command1_Click()a = InStr(1, Text1, Text2)Text1.SelStart = a - 1Text1.SelLength = Len(Text2)Text1.SetFocusPrivate Sub Text1_Change() End Sub改变字体Private Sub Check1_Click() If Check1.Value = 1 Then = "隶书" Else = "宋体" End IfEnd SubPrivate Sub Check2_Click() If Check2.Value = 1 ThenText1.Font.Bold = True ElseText1.Font.Bold = FalseEnd IfEnd SubPrivate Sub Check3_Click() If Check3.Value = 1 ThenText1.Font.Italic = True ElseText1.Font.Italic = False End IfEnd SubPrivate Sub Check4_Click() If Check4.Value = 1 ThenText1.ForeColor = vbRed ElseText1.ForeColor = vbBlueEnd IfEnd Sub同步Private Sub Text1_Change() Text2 = Text1.TextEnd SubPrivate Sub Text2_Change() Text1 = Text2.TextEnd SubSin函数Private Sub Form_Paint()Scale (0, 0)-(2000, 2000)PSet (1000, 1000)Line (1000, 0)-(950, 50)Line (1050, 50)-(1000, 0)Line (1950, 950)-(2000, 1000)Line (1950, 1050)-(2000, 1000)Line (0, 1000)-(2000, 1000)Line (1000, 0)-(1000, 2000)Circle (1000, 1000), 50For x = 0 To 2000y = 1000 - 300 * (Sin((x - 1000) * 3.1415926 / 180)) PSet (x, y)Next xEnd Sub考试程序Private Sub Command1_Click()If Option3.Value = True ThenText1 = "正确"ElseText1 = "错误"End IfEnd SubPrivate Sub Form_Load()End Sub复制粘贴查找替换Private Sub Command1_Click()Clipboard.SetText Text1.SelTextEnd SubPrivate Sub Command2_Click()Text2.SelText = Clipboard.GetTextEnd SubPrivate Sub Command3_Click()a = InStr(1, Text1, Text3)Text1.SelStart = a - 1Text1.SelLength = Len(Text3)Text1.SetFocusEnd SubPrivate Sub Command4_Click()Text1.SelText = Text4End Sub图片路径Private Sub Dir1_Change()File1.Path = Dir1.PathEnd SubPrivate Sub Drive1_Change()Dir1.Path = Drive1.DriveEnd SubPrivate Sub File1_Click()Picture1.Picture = LoadPicture(File1.Path + File1.FileName) End SubPrivate Sub Form_Load()End Sub改变字体颜色Private Sub Check1_Click()If Check1.Value = 1 Then = "隶书"Else = "宋体"End IfEnd SubPrivate Sub Check2_Click()If Check2.Value = 1 ThenText1.Font.Bold = TrueElseText1.Font.Bold = FalseEnd IfEnd SubPrivate Sub Check3_Click()If Check3.Value = 1 ThenText1.Font.Italic = TrueElseText1.Font.Italic = FalseEnd IfEnd SubPrivate Sub Check4_Click()If Check4.Value = 1 ThenText1.ForeColor = vbRedElseText1.ForeColor = vbBlackEnd IfEnd SubPrivate Sub Form_Load()End SubPrivate Sub Text1_Change()End Sub兴趣选择Private Sub Command1_Click()Text1 = ""If Check1.Value = 1 ThenText1 = Text1 & Check1.CaptionEnd IfIf Check2.Value = 1 ThenText1 = Text1 & Check2.CaptionEnd IfIf Check3.Value = 1 ThenText1 = Text1 & Check3.CaptionEnd IfIf Check4.Value = 1 ThenText1 = Text1 & Check4.CaptionEnd IfEnd SubPrivate Sub Form_Load()End Sub1.求三角形的面积代码:Option ExplicitDim a!,b!,c!r,!,s!Private Sub Command1_Click()a = InputBox("a=", "请输入a的数值")b = InputBox("b=", "请输入b的数值")c = InputBox("c=", "请输入c的数值")If a + b > c And a + c > b And b + c > a And a > 0 And b > 0 And c > 0 Then r = 1 / 2 * (a + b + c)s = Sqr(r * (r - a) * (r - b) * (r - c))Label1.Caption = "三角形的面积为" & sElseLabel2.Caption = "输入的数据不能构成三角形"End IfEnd Sub。
用VB编了一个小程序来实现电脑抽奖的小功能
用VB编了一个小程序来实现电脑抽奖的小功能,其原理如下:主要利用VB中的Rnd函数,来实现随机查找和打乱排序的功能,从而实现随机抽奖的目的。
Rnd函数的语法结构是Rnd[(number)],可选的number参数是 single或任何有效的数值表达式。
Rnd函数返回小于1但大于或等于0的值。
number 的值决定了 Rnd 生成随机数的方式。
为了生成某个范围内的随机整数,可使用以下公式:Int((upperbound - lowerbound + 1) × Rnd + lowerbound)这里,upperbound 是随机数范围的上限,而 lowerbound 则是随机数范围的下限。
另外,程序中还使用了INI文件,Windows INI文件,可解释为Windows初始化文件。
它是一种专门用来保存应用程序初始化信息和运行环境信息的文本文件。
ini文件是一种文本文件,它可以通过Notepad等文本编辑器进行编辑。
ini文件具有特定的格式。
一个INI 文件是由若干个段(section)组成的,每个段中包含若干关键字(key)及相应的值(value)。
创建应用程序自己的INI文件,通过INI文件保存应用程序的一些运行环境信息,然后在程序中读取INI文件中的设置信息并据以处理。
一旦程序的运行环境需要变更,则可以通过直接修改INI文件,或在程序中提供专门的界面间接地修改INI文件来保证程序的可用性。
源程序及注释如下:'窗体源程序Option ExplicitDim m_strNameArray() As MyNameDim m_bIsStart As BooleanDim m_nNameIndex As IntegerDim MAX_INDEX As IntegerDim m_nSelectNum As Integer'被选定数Dim nScrollStep As IntegerDim nScrollWidth As IntegerDim bScrollState As BooleanDim nEnableSecond As IntegerDim m_strTitle As StringDim m_strAppTitle As StringDim m_strScrollTitleLeft As StringDim m_strScrollTitleRight As StringPrivate Sub Command_Start_Stop_Click()If m_bIsStart = True Then'按停止钮m_bIsStart = FalseCommand_Start_Stop.Caption =“开始"Label_FlashName.Visible = TrueTimer_FlashName.Enabled = TrueTimer_ScrollName.Enabled = FalseLabel_FlashName =m_strNameArray(m_nNameIndex).strName +“中奖了!"m_strNameArray(m_nNameIndex).bIsSelect = Truem_nSelectNum = m_nSelectNum + 1Dim Temp As MyNameTemp =m_strNameArray(MAX_INDEX)m_str Name Array(MAX-INDEX) = m_strNameArray(m_nNameIndex) m_strNameArray(m_nNameIndex) =TempMAX_INDEX = MAX_INDEX - 1If MAX_INDEX = 0 ThenMsgBox “非常感谢您使用本软件"End IfElse '按开始钮m_bIsStart = TrueCommand_Start_Stop.Caption = “停止" Command_Start_Stop.Enabled = False Timer_ScrollName.Enabled = TrueTimer_FlashName.Enabled = FalseLabel_FlashName.Caption = “"End IfEnd SubPrivate Sub Form_Load()Form_Bouns.ScaleMode = 3m_nNameIndex = 0m_bIsStart = FalseTimer_ScrollName.Enabled = TrueTimer_ScrollTitle.Enabled = True Label_FlashName.Visible = FalseLabel_ScrollName.Caption = “" nEnableSecond = 0'定义起始秒数ReDimNameArray'获得文本中的名字和打乱名字顺序nScrollStep = 5 '设定滚动字的步长nScrollWidth = Label_Congruation.Left'设定title的移动宽度bScrollState = False'设定缺省的开始滚动方向为向左m_nSelectNum = 0'初始化被选定数为0Init'初始化本程序的界面End SubPrivate Sub Timer_FlashName_Timer() '闪动中奖者姓名If Label_FlashName.Visible = True ThenLabel_FlashName.Visible = FalseElseLabel_FlashName.Visible = TrueEnd IfEnd SubPrivate Sub Timer_ScrollName_Timer() '滚动出现名字If m_bIsStart = True ThenIf m_nNameIndex >= MAX_INDEX Thenm_nNameIndex = 0End Ifm_nNameIndex =m_nNameIndex + 1If m_strNameArray(m_nNameIndex).bIsSelect = True Then If m_nNameIndex <MAX-INDEX Thenm_nNameIndex =m_nNameIndex + 1Elsem_nNameIndex = 0End IfEnd IfLabel_ScrollName.Caption = m_strNameArray(m_nNameIndex).strName'End IfEnd IfEnd SubPrivate Sub Timer_ScrollTitle_Timer() '滚动“恭喜发财"字样If bScrollState = False Then '向左滚nScrollStep = 10Label_Congruation.Caption = m_strScrollTitleLeftIf nScrollWidth > 0 ThennScrollWidth =nScrollWidth - nScrollStepElsebScrollState = TrueEnd IfElse '向右滚nScrollStep = -10Label_Congruation.Caption =m_strScrollTitleRightIf nScrollWidth < Form_Bouns.ScaleWidth - Label_Congruation.Width Then nScrollWidth =nScrollWidth - nScrollStepElsebScrollState = FalseEnd IfEnd IfLabel_Congruation.Left = nScrollWidth'以下为8秒钟内使“停止"按钮有效If nEnableSecond <= 49 ThenIf m_bIsStart = True ThennEnableSecond =nEnableSecond + 1End IfElseIf m_bIsStart = True ThenCommand_Start_Stop.Enabled = TruenEnableSecond = 0End IfEnd IfEnd Sub'动态定义数组Private Sub ReDimNameArray()Dim strMaxIndex As StringDim nIndex As IntegerDim bIsBegin As BooleanbIsBegin = FalsenIndex = 0Open App.Path +“\name.txt" For Input As #1 '读文件Do Until EOF(1)If bIsBegin = False ThenLine Input #1, strMaxIndexnMaxIndex = Val(strMaxIndex)MAX_INDEX = nMaxIndex - 1ReDim m_strNameArray(0 To nMaxIndex - 1)bIsBegin = TrueElseLine Input #1, m_strNameArray(nIndex).strNamem_strNameArray(nIndex).bIsSelect = FalsenIndex = nIndex + 1End IfLoop'以下为打乱人员顺序10次Dim i As IntegerDim j As IntegerDim Temp As StringFor j = 0 To 10For i = 0 To nMaxIndex - 1nRandomNum = ((nMaxIndex - 1) × Rnd) '利用Rnd函数Temp = m_strNameArray(i).strNamem_strNameArray(i).strName = m_strNameArray(nRandomNum).strNamem_strNameArray(nRandomNum).strName = TempNext iNext jEnd SubPrivate Sub Init() '读取INI文件Dim X As LongDim lpFileNameDim Temp As String × 50lpFileName = App.Path +“\Sortition.ini"X = GetPrivateProfileString(“SYSTEM",“AppTitle",“抽奖程序", Temp, Len(Temp), lpFileName)m_strAppTitle = Trim(Temp)Temp =“"X = GetPrivateProfileString(“SYSTEM", "Title", "欢迎使用抽奖程序", Temp, Len(Temp), lpFileName)m_strTitle = Trim(Temp)Temp = “"X = GetPrivateProfileString(“SYSTEM",“ScrollTitleRight", “恭喜发财!!!", Temp, Len(Temp), lpFileName) m_strScrollTitleRight = Trim(Temp)X = GetPrivateProfileString(“SYSTEM",“ScrollTitleLeft", “龙年大发!!!", Temp, Len(Temp), lpFileName)m_strScrollTitleLeft = Trim(Temp)Form_Bouns.Caption = m_strAppTitleLabel_CompanyTitle.Caption = m_strTitleEnd Sub模块源程序:'用于读取ini文件的API函数Declare Function GetPrivateProfileString Lib “kernel32" Alias “GetPrivateProfileStringA" (ByVal lpApplicationname As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As LongPublic Type MyNamestrName As StringbIsSelect As BooleanEnd Type由于程序利用的windows ini文件保存一些标题信息,因而可以方便的修改使用环境,及标题内容。
VB编写各种趣味小程序(附代码)
VB编写各种趣味小程序(附代码)一、鸟巢绘制二、加密三、解密四、蝴蝶飞舞五、文本编辑六、统计七、小球跳动八、计算器(彩票摇奖)九、学生信息录入十、矩阵转置十一、带有进度条的倒计时程序十二、加减乘除随机数题十三、计算器十四、抽奖一、鸟巢绘制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 "并在帮助菜单中查阅其字体设置的相关属性。
几个初学vb程序设计的练习小程序2
复习题4 1、简述下列程序实现的功能Private Sub Command1_Click()Text1.Text = "欢迎使用智强考勤管理系统"End SubPrivate Sub Command2_Click()EndEnd Sub2、简述下列程序实现的功能Private Sub cmdadd_Click()Text3.Text = Val(Text1.Text) * Val(Text2.Text)End SubPrivate Sub Cmdcls_Click()Text1.Text = ""Text2.Text = ""Text3.Text = ""End SubPrivate Sub Command1_Click()EndEnd Sub3、简述下列程序实现的功能Option ExplicitPrivate sngDanjia1 As SinglePrivate sngDanjia2 As SinglePrivate sngDanjia3 As SinglePrivate sngDanjia4 As SinglePrivate intShuliang1 As IntegerPrivate intShuliang2 As IntegerPrivate intShuliang3 As IntegerPrivate intShuliang4 As IntegerPrivate Sub Command1_Click()Text1.Text = "哈尔滨工业大学出版社"Text2.Text = sngDanjia1Text3.Text = "钟啸剑"Text4.Text = "ISBN:9787560517644"End SubPrivate Sub Command2_Click()Text1.Text = "科技大学出版社"Text2.Text = sngDanjia2Text3.Text = "高教指导委员会"Text4.Text = "ISBN:9787560517644"End SubPrivate Sub Command3_Click()Text1.Text = "北京邮电出版社"Text2.Text = sngDanjia3Text3.Text = "门槛工作室"Text4.Text = "ISBN:9787560517644"End SubPrivate Sub Command4_Click()Text1.Text = "电子工业出版社"Text2.Text = sngDanjia4Text3.Text = "信息产业委员会"Text4.Text = "ISBN:9787560517644"End SubPrivate Sub Command5_Click()Dim sngZongjine As SinglesngZongjine = sngDanjia1 * intShuliang1 + sngDanjia2 * intShuliang2 + sngDanjia3 * intShuliang3 + sngDanjia4 * intShuliang4Text9.Text = sngZongjineEnd SubPrivate Sub Command6_Click()Text5.Text = "0"Text6.Text = "0"Text7.Text = "0"Text8.Text = "0"Text9.Text = "0"End SubPrivate Sub Command7_Click()EndEnd SubPrivate Sub Form_Load()sngDanjia1 = 30.5sngDanjia2 = 25sngDanjia3 = 23sngDanjia4 = 20End SubPrivate Sub Text5_Change()intShuliang1 = Val(Text5.Text)End Sub4、简述下列程序实现的功能Private Sub Command1_Click()Dim m As Integer, n As Integer, r As Integerm = Val(Text1.Text)n = Val(Text2.Text)Select Case mCase ls <= 5, 10, 11If n < 20 Then r = 20 Else r = 30Case 7 To 9If n < 20 Then r = 5 Else r = 15Case Elser = 10End SelectLabel4.Caption = "所定机票的优惠率为:" & Str(r) & "%"End SubPrivate Sub Command2_Click()EndEnd Sub5、简述下列程序实现的功能Private Sub Form_Load()Combo1.AddItem "食品加工"Combo1.AddItem "食品机械"Combo1.AddItem "美术学"Combo1.AddItem "素描与写真"Combo1.AddItem "音乐欣赏"Combo1.AddItem "现代汉语"Combo1.AddItem "大学语文"Combo1.AddItem "应用文写作"Combo1.AddItem "网页设计与制作"Combo1.AddItem "计算机绘图技术"Combo1.AddItem "计算机辅助设计"Combo1.AddItem "三维动画设计"End SubPrivate Sub Command1_Click()If Combo1.ListIndex < 0 ThenMsgBox "在课程列表中必须有选中的课程项!", , "警告"ElseList1.AddItem Combo1.TextEnd IfEnd SubPrivate Sub Command2_Click()If List1.ListCount = 0 ThenMsgBox "学生所选课程别表中必须有课程项!", , "警告"ElseIf List1.ListIndex < 0 ThenMsgBox "在学生所选课程中必须有选中要删除的课程项!", , "警告" Else: List1.RemoveItem List1.ListIndexEnd IfEnd SubPrivate Sub Command3_Click()List1.ClearEnd SubPrivate Sub Command4_Click()EndEnd Sub6、简述下列程序实现的功能Private Sub Option1_Click()Text1.FontName = "宋体"End SubPrivate Sub Option2_Click()Text1.FontName = "幼圆"End SubPrivate Sub Check1_Click()Text1.FontBold = IIf(Check1.Value = 1, True, False) End SubPrivate Sub Check2_Click()Text1.FontItalic = IIf(Check1.Value = 1, True, False) End SubPrivate Sub HScroll1_Scroll()Text1.FontSize = HScroll1.ValueEnd SubPrivate Sub HScroll1_Change()Text1.FontSize = HScroll1.ValueEnd Sub7、简述下列程序实现的功能Private Sub Command1_Click()ClsLine (100, 1400)-(1000, 1400), vbRedLine (1800, 1400)-(2400, 1000), vbRed, BLine (3000, 1400)-(3600, 1000), vbRed, BFEnd SubPrivate Sub Command2_Click()Dim r As Singler = Val(InputBox("请输入半径", "输入半径", 500)) ClsCircle (1000 + r, 1400), r, vbRedCircle (1000 + 3 * r, 1400), r, QBColor(0), -0.785, -1.571 Circle (1000 + 5 * r, 1400), r, RGB(0, 0, 255), , , 0.5 End Sub8、简述下列程序实现的功能Private Sub Timer1_Timer()Image2.Picture = Picture1.PicturePicture1.Picture = Image1.PictureImage1.Picture = Image2.PictureEnd Sub9、简述下列程序实现的功能Private Sub Command1_Click()Text3.Text = Val(Text1.Text) + Val(Text2.Text)End SubPrivate Sub Command2_Click()Text3.Text = Val(Text1.Text) - Val(Text2.Text)End SubPrivate Sub Command3_Click()Text3.Text = Val(Text1.Text) * Val(Text2.Text)End SubPrivate Sub Command4_Click()Text3.Text = Val(Text1.Text) / Val(Text2.Text)End SubPrivate Sub Command5_Click()EndEnd Sub10、简述下列程序实现的功能Private Sub Command1_Click()Dim a As Single, b As Single, c As SingleDim sng1 As Single, sng2 As Singlea = CSng(Text1.Text)b = CSng(Text2.Text)c = CSng(Text3.Text)If a = 0 ThenIf b = 0 ThenText4.Text = "方程无解。
VB小程序制作
VB小程序制作VB(Visual Basic)是一种广泛使用的编程语言,它可以用于制作各种小程序。
通过VB,开辟者可以轻松地创建用户友好的界面和功能强大的应用程序。
本文将介绍VB小程序制作的基本步骤和一些实用的技巧。
1. 确定程序的目标和功能在开始制作VB小程序之前,首先需要明确程序的目标和所需的功能。
这有助于开辟者更好地规划程序的结构和设计界面。
例如,如果你想制作一个简单的计算器程序,你需要确定它需要支持哪些基本的数学运算,如加法、减法、乘法和除法。
2. 设计用户界面VB提供了丰富的工具和控件,使得设计用户界面变得轻松而有趣。
你可以使用按钮、文本框、标签等控件来创建一个直观且易于操作的界面。
在设计用户界面时,要注意布局的合理性和美观性。
保持界面简洁明了,并确保用户可以轻松地理解和使用程序。
3. 编写代码VB是一种基于事件驱动的编程语言,这意味着程序的行为和响应是由用户的操作触发的。
在编写代码之前,你需要了解一些基本的编程概念,如变量、条件语句和循环结构。
通过编写代码,你可以实现程序的各种功能,如计算、数据输入和输出等。
4. 运行和测试在完成代码编写后,你可以运行程序并进行测试。
通过测试,你可以发现和修复程序中的错误和问题。
确保程序在各种情况下都能正常运行,并提供正确的结果。
如果发现错误,你可以通过调试和修改代码来解决问题。
5. 优化和改进一旦程序正常运行,你可以考虑对其进行优化和改进。
这包括提高程序的性能、增加新的功能和改善用户体验等方面。
你可以使用一些高级的技术和技巧来实现这些目标,如使用数据结构来提高算法效率,使用图形库来增加程序的视觉效果等。
总结:VB小程序制作是一个有趣且具有挑战性的过程。
通过合理的规划、设计和编码,你可以创建出功能强大且用户友好的应用程序。
在制作VB小程序时,要保持耐心和积极的态度,并不断学习和改进自己的技能。
希翼本文的介绍对你制作VB小程序有所匡助,祝你成功!。
VB 自编小程序实验报告
VB自编小程序一、实验目的1、.掌握命令按钮、标签、Timer、Image等控件的使用方法和属性的设置。
2、掌握逻辑表达式的正确书写形式。
3、掌握单分支与双分支语句的用法,熟练掌握If……Then……ElseIf 语句的用法。
4、掌握组合框的使用。
5、掌握背景图案的设置方法。
6、独立完成一个VB程序的编辑,要求用到几种基本控件。
二、实验内容根据相关资料,查阅课本,独立完成一个VB小程序的编译,介绍如下:1、此小程序类似于QQ中的加好友程序,在回答相关问题后,允许通过。
2、其中利用组合框提供三个不同的问题,用户需要输入相关问题对应答案。
3、利用Timer控件完成对图片的切换。
4、利用图像框插入图像使界面变的漂亮。
5、通过编写程序代码实现相关功能。
三、实验仪器硬件环境:PC软件环境:操作系统Windows系列 Visual Basic 6.0四、实验原理VB程序开发原理。
五、实验步骤1、启动,建立用户界面2、设置对象属性3、编写事件代码Private Sub Form_Load()Combo1.AddItem "我最喜欢的事", 0Combo1.AddItem "芝麻开门", 1Combo1.AddItem "我的名字", 2End SubPrivate Sub Command1_Click()Dim s As IntegerIf Text1.Text = "看美女" And Combo1.Text = "我最喜欢的事" Thens = MsgBox("回答正确,已成功加为好友", 1 + vbInformation, "信息") ElseIf Text1.Text = "打个大西瓜" And Combo1.Text = "芝麻开门" Then s = MsgBox("回答正确,已成功加为好友", 1 + vbInformation, "信息") ElseIf Text1.Text = "刘志新" And Combo1.Text = "我的名字" Thens = MsgBox("回答正确,已成功加为好友", 1 + vbInformation, "信息") Elses = MsgBox("回答错误,对方不加你为好友", 5 + vbExclamation, "警告")End IfEnd SubPrivate Sub Timer1_Timer()Static PickBmp As IntegerIf PickBmp = 0 ThenImage1.Picture = Image2.PicturePickBmp = 1ElseImage1.Picture = Image3.PicturePickBmp = 0End IfEnd Sub4、程序界面程序界面如图示六、实验报告要求详述实验过程,建立完整的VB程序,实现所需功能。
VB小程序代码实例
VB小程序代码实例VB小程序是一种基于Visual Basic语言开辟的应用程序,它可以在Windows 操作系统上运行。
本文将为您提供一个VB小程序代码实例,匡助您了解如何编写和运行一个简单的VB小程序。
代码实例如下:```vbImports SystemPublic Class HelloWorldPublic Shared Sub Main()Console.WriteLine("Hello, World!")Console.ReadLine()End SubEnd Class```上述代码是一个经典的“Hello, World!”程序,它会在控制台输出一条问候语,并等待用户按下回车键。
下面是代码解释:- `Imports System`:这个语句告诉编译器我们将使用System命名空间中的类和方法。
- `Public Class HelloWorld`:这是一个公共类的声明,类名为HelloWorld。
- `Public Shared Sub Main()`:这是程序的入口点,它是一个公共静态方法,程序从这里开始执行。
- `Console.WriteLine("Hello, World!")`:这行代码会在控制台输出一条问候语。
- `Console.ReadLine()`:这行代码会等待用户按下回车键,以便程序暂停执行。
您可以将上述代码复制到一个文本编辑器中,并将文件保存为`.vb`扩展名。
然后,使用VB编译器将其编译为可执行文件,并在Windows操作系统上运行。
这个简单的VB小程序只是一个入门示例,您可以根据自己的需求和兴趣编写更复杂的VB小程序。
VB语言具有丰富的特性和功能,可以用于开辟各种类型的应用程序,包括图形用户界面(GUI)应用程序、数据库应用程序、Web应用程序等。
希翼这个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 Table”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小程序:通过枚举进程显示所有进程、隐藏进程、进程路径
VB代码VB小程序:通过枚举进程显示所有进程、隐藏进程、进程路径本小程序采用枚举进程的方法,显示所有进程,也能显示隐藏进程。
同时,能显示进程的完整路径。
有意思的是,一些已经结束的进程,同样可以显示。
以下是程序运行截图:''''以下是 VB6 代码,在 WinXP 调试通过'需在窗体放置以下 5 个控件,不必设置任何属性,全部采用默认设置:' Command1、List1、Check1、Timer1、Label1'本人原创,转载请注明来源:/100bd/blog/item/c4199fedda35ba0763d09f6b.htmlPrivate Type tyProcpID As Long: pName As String: pPath As String: pHide As StringEnd TypeDim ctP() As tyProc, ctPs As LongPrivate Declare Function EnumProcesses Lib "psapi.dll" (ByRef lpidProcess As Long, ByVal cb As Long, ByRef cbNeeded As Long) As LongPrivate Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As LongPrivate Declare Function EnumProcessModules Lib "psapi.dll" (ByVal hProcess As Long, ByRef lphModule As Long, ByVal cb As Long, ByRef lpcbNeeded As Long) As LongPrivate Declare Function GetModuleFileNameEx Lib "psapi.dll" Alias"GetModuleFileNameExA" (ByVal hProcess As Long, ByVal hModule As Long, ByVal lpFilename As String, ByVal nSize As Long) As LongPrivate Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As LongPrivate Declare Function GetProcessImageFileName Lib "psapi.dll" Alias"GetProcessImageFileNameA" (ByVal hProcess As Long, ByVal lpImageFileName As String, ByVal nSize As Long) As LongPrivate Const PROCESS_ALL_ACCESS = &H1F0FFFPrivate Const PROCESS_QUERY_INFORMATION = &H400Private Const PROCESS_VM_READ = &H10Private Const PROCESS_CREATE_PROCESS = &H80Private Const PROCESS_CREATE_THREAD = &H2Private Const PROCESS_DUP_HANDLE = &H40'Private Const PROCESS_QUERY_INFORMATION = &H400Private Const PROCESS_QUERY_LIMITED_INFORMATION = &H1000Private Const PROCESS_SET_QUOTA = &H100Private Const PROCESS_SET_INFORMATION = &H200Private Const PROCESS_SUSPEND_RESUME = &H800Private Const PROCESS_TERMINATE = &H1Private Const PROCESS_VM_OPERATION = &H8'Private Const PROCESS_VM_READ = &H10Private Const PROCESS_VM_WRITE = &H20'以下是在 NT 系统中提升当前进程权限的代码================================'系统级权限,可以:PROCESS_ALL_ACCESS OpenProcessToken、LookupPrivilegevalue、AdjustTokenPrivilegesPrivate Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As LongPrivate Declare Function GetCurrentProcess Lib "kernel32" () As LongPrivate Declare Function LookupPrivilegeValue Lib "advapi32" Alias"LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As LongPrivate Declare Function AdjustTokenPrivileges Lib "advapi32" (ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, NewState As TOKEN_Privileges, ByVal BufferLength As Long, PreviousState As TOKEN_Privileges, ReturnLength As Long) As LongPrivate Type LUIDUsedPart As LongIgnoredForNowHigh32BitPart As LongEnd TypePrivate Type TOKEN_PrivilegesPrivilegeCount As LongTheLuid As LUIDAttributes As LongEnd TypePublic Sub AdjustPrivilege()'NT系统:提升权限Dim dl As Long, CurP As Long, nToKen As Long, nLuid As LUIDDim OldTKP As TOKEN_Privileges, NewTKP As TOKEN_PrivilegesDim pName As StringConst TOKEN_Adjust_Privileges = &H20Const TOKEN_Query = &H8Const SE_Privilege_Enabled_BY_DEFAULT = &H1 '默认权限Const SE_Privilege_Enabled = &H2 '开启权限Const SE_Privilege_USED_FOR_ACCESS = &H80000000 '所有访问权限'获取当前进程的一个句柄CurP = GetCurrentProcess()'打开进程令牌:用 nToKen 获得进程访问令牌的句柄dl = OpenProcessToken(CurP, (TOKEN_Adjust_Privileges Or TOKEN_Query), nToKen)'用 nLuid 返回指定权限的 LUID 结构'权限名称:SeDebugPrivilege、SeShutdownPrivilege、SeRestorePrivilege、SeBackupPrivilege、SeUnsolicitedInputPrivilegepName = "SeDebugPrivilege"dl = LookupPrivilegeValue("", pName, nLuid)NewTKP.PrivilegeCount = 1NewTKP.TheLuid = nLuidNewTKP.Attributes = SE_Privilege_Enabled'调整令牌权限dl = AdjustTokenPrivileges(nToKen, False, NewTKP, Len(NewTKP), OldTKP, 0&) End Sub'===================Private Sub Form_Load() = "宋体": Me.Caption = "枚举进程"Command1.Caption = "刷新" = Call AdjustPrivilege '提升本进程权限Timer1.Interval = 10Check1.Caption = "自动刷新": Check1.Value = 1End SubPrivate Sub Check1_Click()Timer1.Enabled = Check1.Value = 1End SubPrivate Sub Timer1_Timer()Static S As Long, S1 As LongDim nTai As StringS1 = S1 + 1If S1 > 2 ThenS1 = 0nTai = "↖↑↗→↘↓↙←"S = S + 1If S > 8 Then S = 1Label1.Caption = Mid(nTai, S, 1) '动画显示End IfCall ShowProcEnd SubPrivate Sub Command1_Click()List1.Clear: List1.RefreshCall ShowProcEnd SubPrivate Sub Form_Resize()Dim H1 As Single, T As SingleOn Error Resume NextH1 = Me.TextHeight("A")Command1.Move H1, H1, H1 * 4, H1 * 2Label1.Move H1 * 6, H1 * 1.5, H1, H1Check1.Move H1 * 8, H1, H1 * 8, H1 * 2T = Command1.Top + Command1.Height + H1 * 0.5List1.Move 0, T, Me.ScaleWidth, Me.ScaleHeight - TEnd Sub'本人原创,转载请注明来源:/100bd/blog/item/c4199fedda35ba0763d09f6b.html Private Sub ShowProc()Dim pID(1023) As Long, Ps As Long, dwDesiredAccess As LongDim cbNeeded As Long, P As Long, hModule As LongDim hProcess As Long, nStr As String, I As LongDim IsChange As Boolean, P2() As tyProc, Ps2 As LongOn Error Resume NextdwDesiredAccess = PROCESS_QUERY_INFORMATION Or PROCESS_VM_READPs2 = ctPs: P2 = ctPctPs = 1: ReDim ctP(0 To 1)ctP(1).pName = "[System Process]"nStr = String(1024, 0)' 进程ID的数组,数组的大小,返回实际进程数组的大小If EnumProcesses(pID(0), 4& * 1024, cbNeeded) <> 0 ThenPs = cbNeeded \ 4 '进程总数For P = 0 To &HFFFF& Step 4hProcess = OpenProcess(dwDesiredAccess, 0, P) '返回指定进程的句柄If hProcess <> 0 ThenctPs = ctPs + 1: ReDim Preserve ctP(0 To ctPs)ctP(ctPs).pHide = "隐藏"For I = 0 To Ps - 1If P = pID(I) Then ctP(ctPs).pHide = "": Exit ForNext I'nStr 返回主模块全名:每个进程的第一模块即为进程主模块If EnumProcessModules(hProcess, hModule, 4&, 0&) <> 0 Then GetModuleFileNameEx hProcess, hModule, nStr, 1024Else '型如:\Device\HarddiskVolumeGetProcessImageFileName hProcess, nStr, 1024End IfCloseHandle hProcess '关闭进程的句柄With ctP(ctPs).pID = P '进程 ID.pPath = CutStr(nStr, vbNullChar) '进程路径If Left(.pPath, 4) = "\??\" Then .pPath = Mid(.pPath, 5) '去掉“\??\”.pName = CutStr(.pPath, "\", True) '进程名If P = 4 And .pName = "" Then .pName = "System"End WithEnd IfNextEnd If'List1.ClearFor P = 1 To ctPsnStr = AddSpace(P, 4) & ProcStr(ctP(P)) '合成显示条目If P > List1.ListCount ThenList1.AddItem nStr' List1.ListIndex = List1.NewIndexElseIf nStr <> List1.List(P - 1) Then List1.List(P - 1) = nStrEnd IfNext'删除多余条目For P = List1.ListCount - 1 To ctPs Step -1List1.RemoveItem PNextEnd SubPrivate Function ProcStr(P As tyProc) As StringProcStr = AddSpace(P.pID) & AddSpace(P.pHide, 6) & AddSpace(P.pName, 20) & AddSpace(P.pPath)End FunctionPrivate Function AddSpace(ByVal nStr As String, Optional ByVal S As Long) As StringIf S < 1 Then S = 6S = S - LenB(StrConv(nStr, vbFromUnicode))If S < 1 Then S = 1AddSpace = nStr & String(S, " ")End FunctionPrivate Function CutStr(nStr As String, Fu As String, Optional GetRight As Boolean) As String'GetRight=T 从右到左查找Dim S As LongIf GetRight Then ' 从右到左查找S = InStrRev(nStr, Fu)If S > 0 Then CutStr = Mid(nStr, S + 1) Else CutStr = nStrElseS = InStr(nStr, Fu)If S > 0 Then CutStr = Left(nStr, S - 1) Else CutStr = nStrEnd IfEnd Function'本人原创,转载请注明来源:/100bd/blog/item/c4199fedda35ba0763d09f6b.html查看文档来源:/100bd/item/fbd87c3004c6f5342e0f8140。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
'Windows 窗体设计器所必需的Private components As ponentModel.IContainer'注意: 以下过程是Windows 窗体设计器所必需的'可以使用Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem Friend WithEvents MenuItem5 As System.Windows.Forms.MenuItem Friend WithEvents OFD As System.Windows.Forms.OpenFileDialogFriend WithEvents SFD As System.Windows.Forms.SaveFileDialogFriend WithEvents MenuItem6 As System.Windows.Forms.MenuItem Friend WithEvents MenuItem7 As System.Windows.Forms.MenuItem Friend WithEvents MenuItem8 As System.Windows.Forms.MenuItem Friend WithEvents MenuItem11 As System.Windows.Forms.MenuItem Friend WithEvents MenuItem12 As System.Windows.Forms.MenuItem Friend WithEvents MenuItem13 As System.Windows.Forms.MenuItem Friend WithEvents MenuItem16 As System.Windows.Forms.MenuItem Friend WithEvents MenuItem17 As System.Windows.Forms.MenuItem Friend WithEvents FFD As System.Windows.Forms.FontDialogFriend WithEvents MenuItem18 As System.Windows.Forms.MenuItem Friend WithEvents MenuItem4 As System.Windows.Forms.MenuItem Friend WithEvents MenuItem9 As System.Windows.Forms.MenuItem Friend WithEvents MenuItem10 As System.Windows.Forms.MenuItem Friend WithEvents MenuItem14 As System.Windows.Forms.MenuItem Friend WithEvents MenuItem15 As System.Windows.Forms.MenuItem Friend WithEvents MenuItem19 As System.Windows.Forms.MenuItem Friend WithEvents MenuItem20 As System.Windows.Forms.MenuItem Friend WithEvents MenuItem21 As System.Windows.Forms.MenuItem Friend WithEvents ContextMenu1 As System.Windows.Forms.ContextMenu Friend WithEvents MenuItem23 As System.Windows.Forms.MenuItem Friend WithEvents MenuItem24 As System.Windows.Forms.MenuItem Friend WithEvents MenuItem25 As System.Windows.Forms.MenuItem Friend WithEvents MenuItem26 As System.Windows.Forms.MenuItem Friend WithEvents MenuItem27 As System.Windows.Forms.MenuItem Friend WithEvents MenuItem28 As System.Windows.Forms.MenuItem Friend WithEvents MenuItem29 As System.Windows.Forms.MenuItem Friend WithEvents MenuItem30 As System.Windows.Forms.MenuItem Friend WithEvents MenuItem31 As System.Windows.Forms.MenuItem Friend WithEvents MenuItem32 As System.Windows.Forms.MenuItem Friend WithEvents MenuItem33 As System.Windows.Forms.MenuItem Friend WithEvents MenuItem34 As System.Windows.Forms.MenuItemFriend WithEvents MenuItem35 As System.Windows.Forms.MenuItemFriend WithEvents MenuItem36 As System.Windows.Forms.MenuItemFriend WithEvents MenuItem38 As System.Windows.Forms.MenuItemFriend WithEvents MenuItem22 As System.Windows.Forms.MenuItemFriend WithEvents MenuItem37 As System.Windows.Forms.MenuItemFriend WithEvents MenuItem39 As System.Windows.Forms.MenuItemFriend WithEvents MenuItem40 As System.Windows.Forms.MenuItemFriend WithEvents MenuItem41 As System.Windows.Forms.MenuItemFriend WithEvents TextBox1 As System.Windows.Forms.RichTextBoxFriend WithEvents Panel1 As System.Windows.Forms.PanelFriend WithEvents Label1 As belFriend WithEvents Label2 As belFriend WithEvents ToolBar1 As System.Windows.Forms.ToolBarFriend WithEvents ToolBarButton1 As System.Windows.Forms.ToolBarButtonFriend WithEvents ToolBarButton2 As System.Windows.Forms.ToolBarButtonFriend WithEvents ToolBarButton3 As System.Windows.Forms.ToolBarButtonFriend WithEvents ToolBarButton4 As System.Windows.Forms.ToolBarButtonFriend WithEvents ToolBarButton5 As System.Windows.Forms.ToolBarButtonFriend WithEvents ToolBarButton6 As System.Windows.Forms.ToolBarButtonFriend WithEvents ToolBarButton7 As System.Windows.Forms.ToolBarButtonFriend WithEvents ImageList1 As System.Windows.Forms.ImageListFriend WithEvents ComboBox1 As boBoxFriend WithEvents ComboBox2 As boBoxFriend WithEvents ToolBarButton8 As System.Windows.Forms.ToolBarButtonFriend WithEvents ToolBar2 As System.Windows.Forms.ToolBarFriend WithEvents ToolBarButton9 As System.Windows.Forms.ToolBarButtonFriend WithEvents ToolBarButton10 As System.Windows.Forms.ToolBarButtonFriend WithEvents ToolBarButton11 As System.Windows.Forms.ToolBarButtonFriend WithEvents MenuItem42 As System.Windows.Forms.MenuItemFriend WithEvents MenuItem43 As System.Windows.Forms.MenuItemFriend WithEvents MenuItem44 As System.Windows.Forms.MenuItemFriend WithEvents Timer1 As System.Windows.Forms.Timer<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() ponents = New ponentModel.Container()Dim resources As ponentResourceManager = New ponentResourceManager(GetType(Form1))Me.MainMenu1 = New System.Windows.Forms.MainMenu(ponents)Me.MenuItem1 = New System.Windows.Forms.MenuItem()Me.MenuItem4 = New System.Windows.Forms.MenuItem()Me.MenuItem2 = New System.Windows.Forms.MenuItem()Me.MenuItem3 = New System.Windows.Forms.MenuItem()Me.MenuItem37 = New System.Windows.Forms.MenuItem()Me.MenuItem18 = New System.Windows.Forms.MenuItem()Me.MenuItem5 = New System.Windows.Forms.MenuItem()Me.MenuItem6 = New System.Windows.Forms.MenuItem() Me.MenuItem9 = New System.Windows.Forms.MenuItem() Me.MenuItem14 = New System.Windows.Forms.MenuItem() Me.MenuItem10 = New System.Windows.Forms.MenuItem() Me.MenuItem15 = New System.Windows.Forms.MenuItem() Me.MenuItem19 = New System.Windows.Forms.MenuItem() Me.MenuItem20 = New System.Windows.Forms.MenuItem() Me.MenuItem21 = New System.Windows.Forms.MenuItem() Me.MenuItem38 = New System.Windows.Forms.MenuItem() Me.MenuItem35 = New System.Windows.Forms.MenuItem() Me.MenuItem22 = New System.Windows.Forms.MenuItem() Me.MenuItem36 = New System.Windows.Forms.MenuItem() Me.MenuItem7 = New System.Windows.Forms.MenuItem() Me.MenuItem8 = New System.Windows.Forms.MenuItem() Me.MenuItem11 = New System.Windows.Forms.MenuItem() Me.MenuItem12 = New System.Windows.Forms.MenuItem() Me.MenuItem13 = New System.Windows.Forms.MenuItem() Me.MenuItem40 = New System.Windows.Forms.MenuItem() Me.MenuItem41 = New System.Windows.Forms.MenuItem() Me.MenuItem42 = New System.Windows.Forms.MenuItem() Me.MenuItem43 = New System.Windows.Forms.MenuItem() Me.MenuItem44 = New System.Windows.Forms.MenuItem() Me.MenuItem16 = New System.Windows.Forms.MenuItem() Me.MenuItem17 = New System.Windows.Forms.MenuItem() Me.MenuItem39 = New System.Windows.Forms.MenuItem() Me.OFD = New System.Windows.Forms.OpenFileDialog()Me.SFD = New System.Windows.Forms.SaveFileDialog()Me.FFD = New System.Windows.Forms.FontDialog()Me.ContextMenu1 = New System.Windows.Forms.ContextMenu() Me.MenuItem23 = New System.Windows.Forms.MenuItem() Me.MenuItem24 = New System.Windows.Forms.MenuItem() Me.MenuItem25 = New System.Windows.Forms.MenuItem() Me.MenuItem26 = New System.Windows.Forms.MenuItem() Me.MenuItem27 = New System.Windows.Forms.MenuItem() Me.MenuItem28 = New System.Windows.Forms.MenuItem() Me.MenuItem29 = New System.Windows.Forms.MenuItem() Me.MenuItem30 = New System.Windows.Forms.MenuItem() Me.MenuItem34 = New System.Windows.Forms.MenuItem() Me.MenuItem33 = New System.Windows.Forms.MenuItem() Me.MenuItem31 = New System.Windows.Forms.MenuItem() Me.MenuItem32 = New System.Windows.Forms.MenuItem() Me.TextBox1 = New System.Windows.Forms.RichTextBox()Me.Panel1 = New System.Windows.Forms.Panel()bel2 = New bel()bel1 = New bel()Me.ToolBar1 = New System.Windows.Forms.ToolBar()Me.ToolBarButton1 = New System.Windows.Forms.ToolBarButton()Me.ToolBarButton2 = New System.Windows.Forms.ToolBarButton()Me.ToolBarButton3 = New System.Windows.Forms.ToolBarButton()Me.ToolBarButton4 = New System.Windows.Forms.ToolBarButton()Me.ToolBarButton5 = New System.Windows.Forms.ToolBarButton()Me.ToolBarButton6 = New System.Windows.Forms.ToolBarButton()Me.ToolBarButton7 = New System.Windows.Forms.ToolBarButton()Me.ToolBarButton8 = New System.Windows.Forms.ToolBarButton()Me.ImageList1 = New System.Windows.Forms.ImageList(ponents)boBox1 = New boBox()boBox2 = New boBox()Me.ToolBar2 = New System.Windows.Forms.ToolBar()Me.ToolBarButton9 = New System.Windows.Forms.ToolBarButton()Me.ToolBarButton10 = New System.Windows.Forms.ToolBarButton()Me.ToolBarButton11 = New System.Windows.Forms.ToolBarButton()Me.Timer1 = New System.Windows.Forms.Timer(ponents)Me.Panel1.SuspendLayout()Me.SuspendLayout()''MainMenu1'Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1, Me.MenuItem6, Me.MenuItem11, Me.MenuItem40, Me.MenuItem42, Me.MenuItem16})''MenuItem1'Me.MenuItem1.Index = 0Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem4, Me.MenuItem2, Me.MenuItem3, Me.MenuItem37, Me.MenuItem18, Me.MenuItem5})Me.MenuItem1.Text = "文件(&F)"''MenuItem4'Me.MenuItem4.Index = 0Me.MenuItem4.Shortcut = System.Windows.Forms.Shortcut.CtrlNMe.MenuItem4.Text = "新建(&N)"''MenuItem2'Me.MenuItem2.Index = 1Me.MenuItem2.Text = "打开(&O)"''MenuItem3'Me.MenuItem3.Index = 2Me.MenuItem3.Shortcut = System.Windows.Forms.Shortcut.CtrlSMe.MenuItem3.Text = "保存(&S)"''MenuItem37'Me.MenuItem37.Index = 3Me.MenuItem37.Shortcut = System.Windows.Forms.Shortcut.CtrlShiftSMe.MenuItem37.Text = "另存为(&A)..."''MenuItem18'Me.MenuItem18.Index = 4Me.MenuItem18.Text = "-"''MenuItem5'Me.MenuItem5.Index = 5Me.MenuItem5.Shortcut = System.Windows.Forms.Shortcut.CtrlQMe.MenuItem5.Text = "退出(&X)"''MenuItem6'Me.MenuItem6.Index = 1Me.MenuItem6.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem9, Me.MenuItem14, Me.MenuItem10, Me.MenuItem15, Me.MenuItem19, Me.MenuItem20, Me.MenuItem21, Me.MenuItem38, Me.MenuItem35, Me.MenuItem22, Me.MenuItem36, Me.MenuItem7, Me.MenuItem8})Me.MenuItem6.Text = "编辑(&E)"''MenuItem9'Me.MenuItem9.Index = 0Me.MenuItem9.Shortcut = System.Windows.Forms.Shortcut.CtrlZMe.MenuItem9.Text = "撤销(&U)"''MenuItem14'Me.MenuItem14.Index = 1Me.MenuItem14.Text = "重做(&R)"''MenuItem10'Me.MenuItem10.Index = 2Me.MenuItem10.Text = "-"''MenuItem15'Me.MenuItem15.Index = 3Me.MenuItem15.Shortcut = System.Windows.Forms.Shortcut.CtrlX Me.MenuItem15.Text = "剪切(&T)"''MenuItem19'Me.MenuItem19.Index = 4Me.MenuItem19.Shortcut = System.Windows.Forms.Shortcut.CtrlC Me.MenuItem19.Text = "复制(&C)"''MenuItem20'Me.MenuItem20.Index = 5Me.MenuItem20.Shortcut = System.Windows.Forms.Shortcut.CtrlV Me.MenuItem20.Text = "粘贴(&P)"''MenuItem21'Me.MenuItem21.Index = 6Me.MenuItem21.Shortcut = System.Windows.Forms.Shortcut.Del Me.MenuItem21.Text = "删除(&L)"''MenuItem38'Me.MenuItem38.Index = 7Me.MenuItem38.Text = "-"''MenuItem35'Me.MenuItem35.Index = 8Me.MenuItem35.Shortcut = System.Windows.Forms.Shortcut.CtrlA Me.MenuItem35.Text = "全选(&A)"''MenuItem22'Me.MenuItem22.Index = 9Me.MenuItem22.Shortcut = System.Windows.Forms.Shortcut.F5Me.MenuItem22.Text = "日期和时间(&D)"''MenuItem36'Me.MenuItem36.Index = 10Me.MenuItem36.Text = "-"''MenuItem7'Me.MenuItem7.Index = 11Me.MenuItem7.Shortcut = System.Windows.Forms.Shortcut.CtrlUMe.MenuItem7.Text = "全体转为大写(&U)"''MenuItem8'Me.MenuItem8.Index = 12Me.MenuItem8.Shortcut = System.Windows.Forms.Shortcut.CtrlLMe.MenuItem8.Text = "全体转为小写(&L)"''MenuItem11'Me.MenuItem11.Index = 2Me.MenuItem11.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem12, Me.MenuItem13})Me.MenuItem11.Text = "格式(&O)"''MenuItem12'Me.MenuItem12.Checked = TrueMe.MenuItem12.Index = 0Me.MenuItem12.Text = "自动换行(&W)"''MenuItem13'Me.MenuItem13.Index = 1Me.MenuItem13.Text = "字体…(&F)"''MenuItem40'Me.MenuItem40.Index = 3Me.MenuItem40.MenuItems.AddRange(New System.Windows.Forms.MenuItem(){Me.MenuItem41})Me.MenuItem40.Text = "窗口(&W)"''MenuItem41'Me.MenuItem41.Index = 0Me.MenuItem41.Text = "字数统计"''MenuItem42'Me.MenuItem42.Index = 4Me.MenuItem42.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem43, Me.MenuItem44})Me.MenuItem42.Text = "自动化"''MenuItem43'Me.MenuItem43.Checked = TrueMe.MenuItem43.Index = 0Me.MenuItem43.Text = "自动保存"''MenuItem44'Me.MenuItem44.Index = 1Me.MenuItem44.Text = "自动保存间隔"''MenuItem16'Me.MenuItem16.Index = 5Me.MenuItem16.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem17, Me.MenuItem39})Me.MenuItem16.Text = "帮助(&H)"''MenuItem17'Me.MenuItem17.Index = 0Me.MenuItem17.Text = "关于X文本编辑器(&A)"''MenuItem39'Me.MenuItem39.Index = 1Me.MenuItem39.Text = "激活…(&K)"''OFDMe.OFD.Filter = "X文本|*.ltx|旧格式X文本|*.ytx|所有文件|*.*"''SFD'Me.SFD.DefaultExt = "*.ltx"Me.SFD.Filter = "X文本|*.ltx|所有文件|*.*"''FFD'Me.FFD.ShowApply = TrueMe.FFD.ShowColor = True''ContextMenu1'Me.ContextMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem23, Me.MenuItem24, Me.MenuItem25, Me.MenuItem26, Me.MenuItem27, Me.MenuItem28, Me.MenuItem29, Me.MenuItem30, Me.MenuItem34, Me.MenuItem33, Me.MenuItem31, Me.MenuItem32})''MenuItem23'Me.MenuItem23.Index = 0Me.MenuItem23.Text = "撤销(&U)"''MenuItem24'Me.MenuItem24.Index = 1Me.MenuItem24.Text = "重做(&R)"''MenuItem25'Me.MenuItem25.Index = 2Me.MenuItem25.Text = "-"''MenuItem26'Me.MenuItem26.Index = 3Me.MenuItem26.Text = "剪切(&T)"''MenuItem27'Me.MenuItem27.Index = 4Me.MenuItem27.Text = "复制(&C)"'MenuItem28'Me.MenuItem28.Index = 5Me.MenuItem28.Text = "粘贴(&P)"''MenuItem29'Me.MenuItem29.Index = 6Me.MenuItem29.Text = "删除(&L)"''MenuItem30'Me.MenuItem30.Index = 7Me.MenuItem30.Text = "-"''MenuItem34'Me.MenuItem34.Index = 8Me.MenuItem34.Text = "全选(&A)"''MenuItem33'Me.MenuItem33.Index = 9Me.MenuItem33.Text = "-"''MenuItem31'Me.MenuItem31.Index = 10Me.MenuItem31.Text = "全体转为大写(&U)"''MenuItem32'Me.MenuItem32.Index = 11Me.MenuItem32.Text = "全体转为小写(&L)"''TextBox1'Me.TextBox1.AcceptsTab = TrueMe.TextBox1.AllowDrop = TrueMe.TextBox1.ContextMenu = Me.ContextMenu1Me.TextBox1.Dock = System.Windows.Forms.DockStyle.BottomMe.TextBox1.Font = New System.Drawing.Font("宋体", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))Me.TextBox1.Location = New System.Drawing.Point(0, -51) = "TextBox1"Me.TextBox1.Size = New System.Drawing.Size(648, 288)Me.TextBox1.TabIndex = 1Me.TextBox1.Text = ""''Panel1'Me.Panel1.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) Me.Panel1.BackColor = System.Drawing.Color.LightGrayMe.Panel1.Controls.Add(bel2)Me.Panel1.Controls.Add(bel1)Me.Panel1.Location = New System.Drawing.Point(484, 3) = "Panel1"Me.Panel1.Size = New System.Drawing.Size(164, 24)Me.Panel1.TabIndex = 3Me.Panel1.Visible = False''Label2'bel2.BackColor = System.Drawing.Color.Transparentbel2.Location = New System.Drawing.Point(100, 0) = "Label2"bel2.Size = New System.Drawing.Size(64, 23)bel2.TabIndex = 1bel2.Text = "共0字"bel2.TextAlign = System.Drawing.ContentAlignment.MiddleRight''Label1'bel1.BackColor = System.Drawing.Color.Transparentbel1.Location = New System.Drawing.Point(0, 0) = "Label1"bel1.Size = New System.Drawing.Size(88, 23)bel1.TabIndex = 0bel1.Text = "选中0字"bel1.TextAlign = System.Drawing.ContentAlignment.MiddleRight''ToolBar1'Me.ToolBar1.Appearance = System.Windows.Forms.ToolBarAppearance.FlatMe.ToolBar1.Buttons.AddRange(New System.Windows.Forms.ToolBarButton() {Me.ToolBarButton1, Me.ToolBarButton2, Me.ToolBarButton3, Me.ToolBarButton4,Me.ToolBarButton5, Me.ToolBarButton6, Me.ToolBarButton7, Me.ToolBarButton8}) Me.ToolBar1.Dock = System.Windows.Forms.DockStyle.NoneMe.ToolBar1.DropDownArrows = TrueMe.ToolBar1.ImageList = Me.ImageList1Me.ToolBar1.Location = New System.Drawing.Point(0, 0) = "ToolBar1"Me.ToolBar1.ShowToolTips = TrueMe.ToolBar1.Size = New System.Drawing.Size(323, 28)Me.ToolBar1.TabIndex = 4''ToolBarButton1'Me.ToolBarButton1.ImageIndex = 0 = "ToolBarButton1"Me.ToolBarButton1.ToolTipText = "新建"''ToolBarButton2'Me.ToolBarButton2.ImageIndex = 2 = "ToolBarButton2"Me.ToolBarButton2.ToolTipText = "打开"''ToolBarButton3'Me.ToolBarButton3.ImageIndex = 1 = "ToolBarButton3"Me.ToolBarButton3.ToolTipText = "保存"''ToolBarButton4' = "ToolBarButton4"Me.ToolBarButton4.Style = System.Windows.Forms.ToolBarButtonStyle.Separator''ToolBarButton5'Me.ToolBarButton5.ImageIndex = 3 = "ToolBarButton5"Me.ToolBarButton5.ToolTipText = "剪切"''ToolBarButton6'Me.ToolBarButton6.ImageIndex = 4 = "ToolBarButton6"Me.ToolBarButton6.ToolTipText = "复制"''ToolBarButton7'Me.ToolBarButton7.ImageIndex = 5 = "ToolBarButton7"Me.ToolBarButton7.ToolTipText = "粘贴"''ToolBarButton8' = "ToolBarButton8"Me.ToolBarButton8.Style = System.Windows.Forms.ToolBarButtonStyle.Separator''ImageList1'Me.ImageList1.ImageStream = CType(resources.GetObject("ImageList1.ImageStream"), System.Windows.Forms.ImageListStreamer)Me.ImageList1.TransparentColor = System.Drawing.Color.TransparentMe.ImageList1.Images.SetKeyName(0, "")Me.ImageList1.Images.SetKeyName(1, "")Me.ImageList1.Images.SetKeyName(2, "")Me.ImageList1.Images.SetKeyName(3, "")Me.ImageList1.Images.SetKeyName(4, "")Me.ImageList1.Images.SetKeyName(5, "")Me.ImageList1.Images.SetKeyName(6, "")Me.ImageList1.Images.SetKeyName(7, "")Me.ImageList1.Images.SetKeyName(8, "")''ComboBox1'boBox1.Items.AddRange(New Object() {"初号", "小初", "一号", "小一", "二号", "小二", "三号", "小三", "四号", "小四", "五号", "小五", "六号", "小六", "七号", "八号", "9", "10", "12", "14", "16", "18", "20", "22", "24", "26", "28", "30", "36", "48", "72"})boBox1.Location = New System.Drawing.Point(269, 4) = "ComboBox1"boBox1.Size = New System.Drawing.Size(52, 20)boBox1.TabIndex = 6boBox1.Text = "14"''ComboBox2'boBox2.Location = New System.Drawing.Point(156, 4) = "ComboBox2"boBox2.Size = New System.Drawing.Size(109, 20)boBox2.TabIndex = 7boBox2.Text = "宋体"''ToolBar2'Me.ToolBar2.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)Me.ToolBar2.Appearance = System.Windows.Forms.ToolBarAppearance.FlatMe.ToolBar2.Buttons.AddRange(New System.Windows.Forms.ToolBarButton() {Me.ToolBarButton9, Me.ToolBarButton10, Me.ToolBarButton11})Me.ToolBar2.Dock = System.Windows.Forms.DockStyle.NoneMe.ToolBar2.DropDownArrows = TrueMe.ToolBar2.ImageList = Me.ImageList1Me.ToolBar2.Location = New System.Drawing.Point(322, 0) = "ToolBar2"Me.ToolBar2.ShowToolTips = TrueMe.ToolBar2.Size = New System.Drawing.Size(327, 28)Me.ToolBar2.TabIndex = 8''ToolBarButton9'Me.ToolBarButton9.ImageIndex = 6 = "ToolBarButton9"Me.ToolBarButton9.ToolTipText = "粗体"''ToolBarButton10'Me.ToolBarButton10.ImageIndex = 7 = "ToolBarButton10"Me.ToolBarButton10.ToolTipText = "斜体"''ToolBarButton11'Me.ToolBarButton11.ImageIndex = 8 = "ToolBarButton11"Me.ToolBarButton11.ToolTipText = "下划线"''Timer1'Me.Timer1.Enabled = TrueMe.Timer1.Interval = 600000''Form1'Me.AllowDrop = TrueMe.AutoScaleBaseSize = New System.Drawing.Size(6, 14)Me.BackColor = System.Drawing.SystemColors.ActiveBorderMe.ClientSize = New System.Drawing.Size(648, 237)Me.Controls.Add(Me.Panel1)Me.Controls.Add(Me.ToolBar2)Me.Controls.Add(boBox2)Me.Controls.Add(boBox1)Me.Controls.Add(Me.ToolBar1)Me.Controls.Add(Me.TextBox1)Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)Me.IsMdiContainer = TrueMe.Menu = Me.MainMenu1 = "Form1"Me.Text = "X文本编辑工具"Me.TransparencyKey = System.Drawing.Color.MagentaMe.Panel1.ResumeLayout(False)Me.ResumeLayout(False)Me.PerformLayout()End Sub#End RegionPrivate Sub MenuItem5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem5.ClickEndEnd SubPrivate Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.ClickOn Error Resume Nextputer.FileSystem.DeleteFile(OFD.FileName + ".utx")OFD.ShowDialog()End SubPrivate Sub OFD_FileOk(ByVal sender As System.Object, ByVal e As ponentModel.CancelEventArgs) Handles OFD.FileOkDim text As Stringtext = OFD.FileNameDim s() As String = OFD.FileName.Split("\")Dim ss() As String = s(s.Length - 1).Split(".")Me.Text = "X文本编辑工具- " & s(s.Length - 1)If ss(ss.Length - 1) = "ytx" Thenrea3(text)ElseIf ss(ss.Length - 1) = "ltx" Thenchenge2(text)Elserea4(text)End If'TextBox1.Text = rea(text)End SubPrivate Sub rea(ByVal path As String)On Error GoTo mmTextBox1.LoadFile(path)Exit Submm:MsgBox("您打开的不是标准的X文本文件!或文本为空!")End SubPrivate Sub chenge1(ByVal path As String)On Error GoTo mmmmDim a As System.IO.StreamReader = New System.IO.StreamReader(path)Dim b As String = a.ReadToEnda.Close()Dim aa As System.IO.StreamWriter = New System.IO.StreamWriter(path, False, System.Text.Encoding.UTF7)Dim i As IntegerDim d As String = ""For i = 1 To b.Length'd &= Chr(Asc(Mid(b, i, 1)) + 100) & "|"d &= Asc(Mid(b, i, 1)) + 159 & "|@@ぁっつの|"Nextaa.WriteLine(d)aa.Close()Me.Text = Split(Me.Text, "*")(0)Exit Submmmm:MsgBox("文本更新失败,请检查文件是否已损坏!")End SubPrivate Sub chenge2(ByVal path As String)On Error GoTo mmmmmDim a As System.IO.StreamReader = New System.IO.StreamReader(path, System.Text.Encoding.UTF7)Dim b As String = a.ReadToEnd'MsgBox(b)a.Close()Dim aa As System.IO.StreamWriter = New System.IO.StreamWriter(path + ".utx", False)Dim c() As String = Split(b, "|@@ぁっつの|")Dim d As String = ""For Each i As String In c'i = Asc(i)If Trim(i) <> "" Thend &= Chr(Val(i) - 159)End IfNextaa.WriteLine(d)aa.Close()rea(path + ".utx")Exit Submmmmm:MsgBox("文本更新失败,请检查文件是否已损坏!")End SubPrivate Sub rea3(ByVal path As String)On Error GoTo mmmmmDim a As System.IO.StreamReader = New System.IO.StreamReader(path, System.Text.Encoding.UTF7)Dim b As String = a.ReadToEnd'MsgBox(b)a.Close()Dim aa As System.IO.StreamWriter = New System.IO.StreamWriter(path + ".utx", False)Dim c() As String = Split(b, "|@@ぁっつの|")Dim d As String = ""For Each i As String In c'i = Asc(i)If Trim(i) <> "" Thend &= Chr(Val(i) - 159)End IfNextaa.WriteLine(d)aa.Close()TextBox1.Text = dExit Submmmmm:MsgBox("文本更新失败,请检查文件是否已损坏!")End SubPrivate Sub rea4(ByVal path As String)On Error GoTo mmmmmDim a As System.IO.StreamReader = New System.IO.StreamReader(path, System.Text.Encoding.UTF7)Dim b As String = a.ReadToEnda.Close()TextBox1.Text = bExit Submmmmm:MsgBox("文本打开失败!发生未知错误!")End SubPrivate Sub wri(ByVal path As String)On Error GoTo mmmTextBox1.SaveFile(path)chenge1(path)Me.Text = Split(Me.Text, "*")(0)Exit Submmm:MsgBox("保存失败!发生未知错误!")End SubPrivate Sub SFD_FileOk(ByVal sender As System.Object, ByVal e As ponentModel.CancelEventArgs) Handles SFD.FileOkwri(SFD.FileName)End SubPrivate Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.ClickIf Me.Text = "X文本编辑工具*" ThenSFD.ShowDialog()Elsewri(OFD.FileName)End IfEnd SubPrivate Sub MenuItem7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles MenuItem7.ClickTextBox1.Text = TextBox1.Text.ToUpper()End SubPrivate Sub MenuItem8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem8.ClickTextBox1.Text = TextBox1.Text.ToLower()End SubPrivate Sub MenuItem12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem12.ClickIf MenuItem12.Checked = True ThenMenuItem12.Checked = FalseTextBox1.WordWrap = FalseElseMenuItem12.Checked = TrueTextBox1.WordWrap = TrueEnd IfEnd SubPrivate Sub MenuItem13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem13.ClickDim se As DialogResult = FFD.ShowDialog()If se = DialogResult.OK ThenIf TextBox1.SelectedText = "" ThenTextBox1.Font = FFD.FontTextBox1.ForeColor = FFD.ColorElseTextBox1.SelectionFont = FFD.FontTextBox1.SelectionColor = FFD.ColorEnd IfEnd IfEnd SubPrivate Sub FFD_Apply(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FFD.ApplyIf TextBox1.SelectedText = "" ThenTextBox1.Font = FFD.FontTextBox1.ForeColor = FFD.ColorElseTextBox1.SelectionFont = FFD.FontTextBox1.SelectionColor = FFD.ColorEnd IfEnd Sub。