开篇:润墨网以专业的文秘视角,为您筛选了一篇CAI教学软件中数据的分割范文,如需获取更多写作素材,在线客服老师一对一协助。欢迎您的阅读与分享!
摘要: 本文使用面向对象的高级语言Visual Basic6.0设计了一套既能编辑,又能应用于教学演示的高级cai软件。使用本软件,用指定的格式输入CAI数据,并在其中设置断点;同时,用本软件进行播放,可实现模拟教学目的。本文着重论述了如何输入数据、分割数据和显示数据的算法。
Abstract:Using the advanced language Object Oriented -Visual Basic 6.0, the author developed a set of advanced CAI software, which can be used in data editing and teaching. This software can be used to input CAI data in assigned format and set breakpoints. At the mean time, it can be used to display data in order to realize the objective of simulated teaching. This article emphasizes on the algorithm of data input, data split and data display.
随着计算机的普及和网络技术的发展,计算机辅助教学(CAI)越来越受到人们的重视。但纵观目前流行的CAI软件,大多只能进行简单的放映,而不具备编辑能力,为数很少的几个能够编辑的软件,操作又很复杂,不能针对教学特点。基于此,作者设计了一个既能编辑,又能放映的CAI软件,该软件高度集成,易学易用。
1 数据的输入
数据的输入采用了类似超文本语言的方法,规定了若干关键字。如:“\”表示一个特定的指令的开始;又如:“\titl^2、光的性质^”,titl:表示后边的内容是一条标题,位于“^……^”之间的数据为标题的内容,“^”为范围限定符。
所有的符号都可以在编辑状态下的屏幕上找到。如图一是编辑状态的一角,左边 图 1 编辑状态
为文字区,右边为指令区。 Fig.1 edit status 2 数据的分割
数据的分割分为两个步骤进行:
第一步:把文章以字形为根据分解成段落。字形的标识与命令标识相关。
程序如下:
'把整个一页分成若个段落
Public Sub FunDivide(ByRef SourceStr As String, ByRef Destination As String, ByRef Position As Integer, ByRef propName As String)
Dim ControllCode As String
Dim codCommand As String
1
Dim ss As String
Dim SourceLen As Long
SourceLen = Len(SourceStr)
Destination = ""
ControllCode = Mid(SourceStr, Position, 1)
If (ControllCode = "\") Then
Position = Position + 1
codCommand = Mid(SourceStr, Position, 4)
propName = codCommand
Position = Position + 4
codCommand = Mid(SourceStr, Position, 1)
If codCommand = "^" Then
Position = Position + 1
ss = Mid(SourceStr, Position, 1)
Do While ss <> "^"
ss = Mid(SourceStr, Position, 1
If ss <> "^" Then
Destination = Destination + ss
End If
Position = Position + 1
Loop
End If
End If
End Sub
第二步:把段落分别地分成一行一行,为向标签框内填充作准备。分行的依据是除去控件和图形的区域。图形位于右上角,用一条水平线和竖直线来分界。
'分段为块
Public Sub LineDivide(ByRef afterDivide As String, ByVal Source As String, ByVal ScaleLO As Integer)
Dim LL As Integer
Dim Ls As String
Dim start As Integer
start = 1
LL = Len(Source)
Do
Ls = Mid(Source, start, ScaleLO)
start = start + ScaleLO
If afterDivide = "" Then
afterDivide = Ls
2
Else
afterDivide = afterDivide + Chr(13) + Chr(10) + Ls
End If
Loop While (start <= LL)
End Sub
这两个全局函数位于标准模块basCommFun.bas中,同时,在该模块中定义了许多全局变量和常量,用来监控程序的运行状态。如:
Option Explicit
Public jobStatus As Integer 'jobStatus=0 第一界面状态
'jobStatus=2 教学界面模式
Public Const Margin = 50
Public Const ZLF = 180 '小五号字的大小Twip
Public Const ZF = 210 '五号字的大小Twip。正常显示内容。
Public Const ZLFo = 240 '小四号字的大小Twip
Public Const ZFo = 285 '四号字的大小Twip
Public Const ZLT = 300 '小三号字的大小Twip。标题。
Public Const ZT = 315 '三号字的大小Twip
3 数据的演示
在数据显示时,首先在窗体上放置若干个标签框和四个图片框,并使他们处于不可见状态。在运行编辑时,显示用的控件都不可见;在运行演示时,编辑用的控件都不可见。通过控制变量jobStatus来实现这种功能。
显示程序如下:
Private Sub cmdPreview_Click()
Dim dspContent(2, 10) As String
Dim Counter As Integer
Dim JJ As Integer
Dim picLeftside As Integer
Dim picBottom As Integer
Dim chrNum As Integer
picLeftside = 0
picBottom = 0
Dim LsStr As String
picLeftside =
frmMainForm.Width 图 2 运行状态
picBottom = frmMainForm.Top Fig 2 run status
Counter = 0
For JJ = 0 To 3
If picFigure(JJ).Picture Then
3
With frmMainForm
.picFigure(JJ).Left = .Width - Margin ? 100 - picFigure(JJ).Width
.picFigure(JJ).Visible = True
If JJ = 0 Then
picFigure(JJ).Top = .Top + 1
picBottom = picBottom + .picFigure(JJ).Top + .picFigure(JJ).Height
Else
.picFigure(JJ).Top = .picFigure(JJ - 1).Top + .picFigure(JJ - 1).Height
picBottom = picBottom + .picFigure(JJ).Height
End If
End With
End If
picLeftside = frmMainForm.picFigure(0).Left
Next JJ
以上程序段用于计算图片框组的左边和累加起来的底边,分存储于变量picLeftSide和pciBottom中。用这两个变量在右上角上划出了一个区域,以保证文本不会显示在图形后面。
For JJ = 0 To 9
frmMainForm.lblDisplayContent(JJ).Left = 1
Next
frmMainForm.txtContent.Visible = False
frmMainForm.cmdPreview.Visible = False
frmMainForm.cmdPreviewClose.Visible = True
上面的语句用于切换到预览状态或是关闭编辑状态。
Dim LL As String
Dim start As Integer
start = 1
4 实例运行
frmMainForm.txtContent = "\titl^ 第一章 简谐振动^\text^ 物体运动时,如果离开平衡位置的位移(或角位移)按余弦函数(或正弦函数)的规律随时间变化,则这种运动称为简谐振动,简称谐振动。简谐振动是一种最简单和最基本的振动,一切复杂的振动都可以看作是由若干个简谐振动合成的结果。^\text^ 如图所示的弹簧振子,当水平放置时,弹簧为原长,物体所受的合力为零,处于平衡状态,此时物体所在的位置就是平衡位置,如果把物体略加位移后释放,这时由于弹簧被拉长或压缩,便有指向平衡位置的弹性力作用在物体上,迫使物体返回平衡位置。这样,在弹性力的作用下,物体就在其平衡位置附近作往复运动。^\text^ 据胡克定律,物体所受的弹性力与弹簧的伸长即物体相对平衡位置的位移成正比,由此可推出弹簧振子的运动是简谐振动。”
1、把文件分割成段落,并显示文本
4
LL = frmMainForm.txtContent.Text
Do While (Len(frmMainForm.txtContent.Text) > start)
Call FunDivide(LL, dspContent(1, Counter), start, dspContent(0, Counter))
Counter = Counter + 1
Loop
2、把段落分割成行
For JJ = 0 To Counter
With frmMainForm
.lblDisplayContent(JJ).Left = 1
3、计算行宽和判断字号
If dspContent(0, JJ) = "titl" Then
.lblDisplayContent(JJ).FontSize = 15
chrNum = (picLeftside - 2 * Margin - 100) / ZLT
ElseIf dspContent(0, JJ) = "text" Then
.lblDisplayContent(JJ).FontSize = 10.5
chrNum = (picLeftside - 2 * Margin - 100) / ZF
Else
End If
LsStr = ""
Call LineDivide(LsStr, dspContent(1, JJ), chrNum) ’分割成行
.lblDisplayContent(JJ).Caption = LsStr ’装载数据
If JJ > 0 Then
.lblDisplayContent(JJ).Top = .lblDisplayContent(JJ - 1).Top
+ .lblDisplayContent(JJ - 1).Height
End If
4、显示数据
.lblDisplayContent(JJ).Visible = True
End With
Next JJ
End Sub
所有的数据以页为单位存储于数据中,编辑时,通过“上一页”和“下一页”来刷新数据;同理,在播放时也通过这两种指令来刷新窗体。所不同的是编辑时可以修改数据库,而在演示时不能修改数据库。
本软件很好地解决了在VB文本框中输入文字不能设置字体,不能回车换行
的问题,并且在编辑文本和图象时能够通过程序控制,动态调整界面控件位置,实现图文混排,在实际运行中取得了较好的效果。
5
参考文献
[1] Wang Dong. Program Design With Visual Basic 6.0. Tsinghua University Press.2000
[2] Jarol S. Guide to Develop Multimedia Program With Visual Basic. Science Press