英汉小词典课程设计VB.doc_第1页
英汉小词典课程设计VB.doc_第2页
英汉小词典课程设计VB.doc_第3页
英汉小词典课程设计VB.doc_第4页
英汉小词典课程设计VB.doc_第5页
已阅读5页,还剩14页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

上海应用技术大学课程设计报告课程名称 计算机语言程序设计课程设计 设计题目 英汉小词典课程设计VB 姓 名 陈子明 专业班级 15101003 学 号 1510100316 指导教师 熊66 日 期 2016-6-27 2016-7-8 目录1概述31.1程学设计目的31.2 程序的基本功能31.3其它功能31.4 扩展功能32课题的分析42.1.Button1查找42.2.Button添加42.3.Button3修改42.4.Button4删除42.5.Button5清除43模板格式说明53.1设计窗体如下:53.2功能模块的划分53.3各控件的属性5功能模块的说明(主要流程和代码)64课程设计总结:174.1完成情况174.2遇到的问题及解决175(附录)参考文献18概述1.1 程学设计目的本次题目的设计的操作与实践是为了使学生了解使用VB 2005程序设计方法,实现面向对象程序设计的相关理论知识和设计技巧,在一定程度上提高面向对象程序设计的综合设计能力,具体掌握的基本能力有以下几方面:l 了解一个英汉小词典开发的全过程。l 熟悉一些常用控件的使用,例如文件列表、标签、文本框、按钮、列表框等。l 熟悉一些常用控件的方法、事件的使用。l 熟悉顺序文件的读写。l 熟悉字符串的处理方法。1.2 程序的基本功能设计程序,左边列表框中的单词表由读取文件英汉小词典.txt得到,选择某单词后,会在上面的文本框中显示相应的内容,并且在右边显示相应的中文解释。1.3其它功能具有搜索、增加、修改、删除、清除等功能。若做过增加、修改、删除,应对英汉词典.txt做相应的修改。1.4 扩展功能在文本框中输入单词时,程序会及时地将已输入的字符开头的所有单词显示在列表框中,供用户浏览;优化搜索算法,方便查询。2 课题的分析2.1. Button1查找输入单词可以找到对应的中文意思2.2. Button添加添加词典中没有的英语单词及其中文意思2.3. Button3修改修改小词典中错误的单词及其中文意思2.4. Button4删除将单词从小词典中删除2.5. Button5清除将单词从输入框中清除3 3模板格式说明3.1 设计窗体如下:图1.1设计窗体3.2 功能模块的划分搜索:在程序中输入单词,可搜索到此单词的中文意思。添加:向小词典中增添没有的单词。修改:修改所选中的单词。删除:删除所选中的单词。3.3 各控件的属性控件 名称属性属性值备注Button1搜索clickForecolor:blackBackcolor: WhiteFont:宋体,9pt,用于搜索英文单词中文意思Button2Button3添加修改ClickclickForecolor: blackBackcolor: WhiteFont: 宋体,9pt,Forecolor: blackBackcolor: WhiteFont: 宋体,9pt,用于添加英文单词中文意思修改单词及其中文意思Button4删除clickForecolor: blackBackcolor: WhiteFont: 宋体,9pt,删除单词及其中文意思Button5清除clickForecolor: blackBackcolor: WhiteFont: 宋体,9pt,清除输入项单词方便下次查询Form1英汉小词典loadFont:宋体,9pt, Lable1请输入对应的单词Backcolor: WhiteForecolor: blackBoredstyle: Fixed3DFont: 宋体,9pt,Textbox1TextChangedBackcolor: White输入单词Listbox1SelectedIndexChangedclickBorderstyle :fixed3DBackcolor: WhiteForecolor: WindowText显示小词典中单词内容功能模块的说明(主要流程和代码)3.4.1 Button1 用于当在textbox1中输入一个单词时,Listbox1中该单词所在的位置能被选中,同时在Listbox2中能够显示单词的中文解释图1.2搜索Button2 用于向列表框中添加单词图1.3添加Button3 用于修改列表框中的单词图1.4修改Button4 用于删除列表框中选定的单词图1.5删除3.4.2主要功能模块流程图Button1搜索:单击搜索读取输入textbox1的单词判断输入内容是否为空是否提示textbox1重新输入用循环结构在数组中寻找该元素判断是否存在Msgbox(无此单词)在listbox1显示英文在listbox2显示中文不存在存在图2.1点击查询Button2添加:单击添加读取inputbox1的单词判断是否为空请重新输入读取inputbox1的内容是否判断是否为空请重新输入将单词添加到listbox1中是否用循环结构判断该单词是否已经存在判断是否存在textbox1.text=Word(i,0)信息提示已存在信息提示添加成功是否图2.2点击添加输入单词Button3修改:在listbox1选择修改单词修改单词判断单词是否为空提示单词不能为空修改汉语意思是否判断汉语意思是否为空将修改过的单词和意思替换原单词和意思信息提示内容不能为空是 否图2.3点击输入修改单词Button4删除:确定要删除吗是否结束程序删除成功图2.4点击删除所选单词3.4.3程序代码分析:Public Class Form1 Inherits System.Windows.Forms.Form Public filename As String = 英汉词典.txt Public myword(6500, 1) As String 调用字库 Public words As Integer = 0 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim a As String Dim b As Integer Dim i As Integer = 0 Dim n As String Dim m As String Dim stringb As Integer 定义字符串变量 TextBox1.Text = TextBox2.Text = FileOpen(1, D:1510100316陈金秋英汉词典.txt, OpenMode.Input) 利用Fileopen()函数打开文件) Do While Not EOF(1) a = LineInput(1) b = InStr(a, ) n = Microsoft.VisualBasic.Left(a, b - 1) myword(i, 0) = n ListBox1.Items.Add(n) 向列表框中添加项目 stringb = Len(a) - b m = Trim(Microsoft.VisualBasic.Right(a, stringb) myword(i, 1) = m i += 1 Loop words = i FileClose(1) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim i As Integer = -1 If TextBox1.Text = Then MessageBox.Show(不能输入空格,请重新输入) TextBox2.Text = TextBox1.Focus() Exit Sub Else For i = i + 1 To words If LCase(TextBox1.Text) = LCase(myword(i, 0) Then TextBox2.Text = Trim(myword(i, 1) 选中Listbox1中的内容,该内容在Textbox2中显示 Exit Sub End If Next MessageBox.Show( 您需要的单词不存在,请重新输入) End If End Sub Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged Try TextBox1.Text = myword(ListBox1.SelectedIndex, 0) TextBox2.Text = Trim(myword(ListBox1.SelectedIndex, 1) 在Textbox2中显示Listbox1中选中的英文 Catch ex As Exception End Try Exit Sub End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim i As Integer = 0 Dim k, m As Integer Dim enterwords, ch As String 定义字符串变过量及整形变量 enterwords = InputBox(请输入要添加的单词, 添加单词) 用Inputbox函数进行输入Do While enterwords = m = MsgBox(单词不能为空,请输入单词!, MessageBoxButtons.RetryCancel, 添加单词) If m = 4 Then enterwords = InputBox(请输入要添加的单词, 添加单词) Else Exit Sub End If Loop ch = InputBox(请输入中文意思, 添加中文) Do While ch = m = MsgBox(中文不能为空,请输入中文意思!, MessageBoxButtons.RetryCancel, 添加中文) If m = 4 Then ch = InputBox(请输入中文意思, 添加中文) Else : Exit Sub End If Loop Do While LCase(myword(i, 0) LCase(enterwords) For k = words To 0 Step -1 Next myword(k + 1, 0) = myword(k, 0) myword(k + 1, 1) = myword(k, 1) myword(0, 0) = enterwords myword(0, 1) = ch words = words + 1 FileOpen(1, filename, OpenMode.Output) Loop For i = 0 To words - 1 PrintLine(1, myword(i, 0) & & myword(i, 1) Next ListBox1.Items.Clear() FileClose(1) Form1_Load(sender, e) MessageBox.Show(添加成功) Exit Sub End If For k = words To i + 1 Step -1从项目最后往上移,腾出位置 myword(k + 1, 0) = myword(k, 0) myword(k + 1, 1) = myword(k, 1) Next k myword(i, 0) = enterwords myword(i, 1) = ch words = words + 1 FileOpen(1, filename, OpenMode.Output) For i = 0 To words - 1 Next PrintLine(1, myword(i, 0) & & myword(i, 1) 将添加的单词及中文解释添加到txt文本中显示 FileClose(1) ListBox1.Items.Clear() Form1_Load(sender, e) MessageBox.Show(添加成功) Exit Sub End SubPrivate Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim ch, enterwords As String Dim j, m As Integer If -1 = ListBox1.SelectedIndex Then MsgBox(请选择单词, , ) ListBox1.Focus() Exit Sub End If enterwords = InputBox(请修改单词, 修改单词, Trim(myword(ListBox1.SelectedIndex, 0) Do While enterwords = m = MsgBox(单词不能为空, MsgBoxStyle.RetryCancel, 修改单词) If m = 4 Then enterwords = InputBox(请修改单词, 修改单词, Trim(myword(ListBox1.SelectedIndex, 0) Else Exit Sub End If Loop ch = InputBox(请修改中文意思, 修改单词, Trim(myword(ListBox1.SelectedIndex, 1) Do While ch = m = MsgBox(中文意思不能为空, MsgBoxStyle.RetryCancel, 修改单词) If m = 4 Then ch = InputBox(请修改中文意思, 修改单词, Trim(myword(ListBox1.SelectedIndex, 1) Else Exit Sub End If Loop myword(ListBox1.SelectedIndex, 1) = ch myword(ListBox1.SelectedIndex, 0) = enterwords FileOpen(1, filename, OpenMode.Output) For j = 0 To words - 1 PrintLine(1, myword(j, 0) & & myword(j, 1) 将修改后的单词及中文解释在txt中重新显示 Next FileClose(1) MsgBox(修改成功) ListBox1.Items.Clear() Form1_Load(sender, e) End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Dim i, j, k As Integer If -1 = ListBox1.SelectedIndex Then未选中ListBox1中的任一项 MsgBox(请选择单词, , ) ListBox1.Focus() Exit Sub End If k = MsgBox(确定是否删除, MsgBoxStyle.YesNo, 提示) If k = 6 Then For i = ListBox1.SelectedIndex To words 从数组中删除数据 myword(i, 0) = myword(i + 1, 0) myword(i, 1) = myword(i + 1, 1) Next words = words - 1 FileOpen(1, filename, OpenMode.Output) 将删除的单词及中文解释从txt文本中剔除 For j = 0 To words - 1 Next PrintLine(1, myword(j, 0) & & myword(j, 1) FileClose(1) MsgBox(单词已删除) ListBox1.Items.RemoveAt(ListBox1.SelectedIndex) ListBox1.Refresh() TextBox1.Text = TextBox2.Text = Else Exit Sub End If Exit Sub End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click TextBox1.Text = TextBox2.Text = 将单词及中文解释从输入框和文本框中清除 End SubEnd Class4 课程设计总结:4.1 完成情况 课程设计结束时,所设计程序基本完成,实现了课程设计所要求的基本功能,通过此次实践我们掌握了VB 2005的基本操作,提高了我们面向对象程序设计的综合设计能力,达到了预期的目的。4.2 遇到的问题及解决 编写程序时,部分语句掌握不流畅,程序运行时出现错误。经过上网查询相关资料以及询问老师后将问题解决。5 (附录)参考文献李春葆,金晶,曾平.VB.NET2005程序设计教程. 北京:清华大学出版社,2009龚沛曾.Visual Basic.NET程序设计教程.高等教育出版社,2010孙践知.Visual Basi

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论