1、VB编程报销计算器VB-编程-报销计算器 作者: 日期: 报销计算器 本程序采用VB语言编写,编程软件为VS2012本计算器是为了计算出差补助,实现以下功能1:能够方便的输入省会补助标准(包含:住宿和其他补助项)_高标准、地方补助标准_低标准2:能够完整的输入车票信息:车票日期时间、出发地点、目的地点、车票价格、以及乘车方式3:能够准确的计算出各项补助金额,以及补助总金额4:能够将车票按照时间顺序排序并输出到文本中,并能计算出在各地的住宿天数具体程序及界面如下:完整程序如下:Public Class Form1 Structure chepiao Dim riq As Date Dim shi
2、j As String Dim jiag As Single Dim chufd As String Dim mudd As String Dim shengh As Boolean Dim jiaotfs As String Dim tians As Integer End Structure Private cp(200) As chepiao Private Ccpq As Single, Ccph As Single, Ccpf As Single, Czs As Integer, Cqt As Integer Private z As Integer, q As Integer Pr
3、ivate i As Integer Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Czs = 0 为全局数据赋初始值 Cqt = 0 Ccpq = 0 Ccph = 0 Ccpf = 0 i = 0 End Sub 读取车票信息并对出行方式车票价格求和 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles SR.Click If cfsj.Text Then If (Int(cfsj.Text) / 10
4、0) 24 Or (Int(cfsj.Text) Mod 100) = 60 Then MsgBox(输入的时间不正确,请重新输入) Exit Sub End If End If cp(i).riq = Date1.Value 读取车票时间信息 If cfsj.Text Then cp(i).shij = cfsj.Text cp(i).chufd = cfdd.Text 读取车票地址信息 cp(i).mudd = mddd.Text cp(i).shengh = sh.Checked 记录车票目的地是否为省会 If shbz1.Text = Or shbz2.Text = Then MsgB
5、ox(请将省会补助标准正确填写完整,没有填 0) 检查补助标准是否填写正确 Exit Sub End If If dfbz1.Text = Or dfbz2.Text = Then MsgBox(请将地方补助标准正确填写完整,没有填 0) Exit Sub End If If cpjg1.Text = Then MsgBox(请输入车票价格,点击确定继续) Exit Sub Else cp(i).jiag = cpjg1.Text 判断是否为第一天出行 If hc.Checked Then 判断车票类型,并对相应车票求和 Ccph = Ccph + cp(i).jiag cp(i).jiaot
6、fs = 火车 ElseIf qc.Checked Then Ccpq = Ccpq + cp(i).jiag cp(i).jiaotfs = 汽车 Else Ccpf = Ccpf + cp(i).jiag cp(i).jiaotfs = 服务车 End If End If GroupBox1.Enabled = False 保证第一次正确输入后标准不能更改 i = i + 1 Textqc.Text = Ccpq 输出各项费用 Texthc.Text = Ccph Textglf.Text = Ccpf MsgBox(输入成功,点击确定继续) Label12.Text = i & 张 cp
7、jg1.Focus() 车票价格输入框获得焦点 cpjg1.Text = End Sub Private Sub JS_Click(sender As Object, e As EventArgs) Handles JS.Click Dim m As Integer, n As Integer Dim z As Integer, q As Integer Dim ep As chepiao Dim jiaoz As Integer jiaoz = 0 If i = 0 Then MsgBox(没有数据可供计算,请输入数据后再尝试计算) Exit Sub End If Czs = 0 Cqt =
8、 0 For m = 0 To i - 2 对车票按时间排序 For n = m + 1 To i - 1 If DateDiff(DateInterval.Day, cp(m).riq, cp(n).riq) cp(n).shij Then ep = cp(m) cp(m) = cp(n) cp(n) = ep End If Next Next For m = 1 To i - 1 n = DateDiff(DateInterval.Day, cp(m - 1).riq, cp(m).riq) If cp(m - 1).shengh And n 0 Then jiaoz = jiaoz +
9、1 cp(m - 1).tians = n If cp(m - 1).shengh Then 判断补助标准 z = shbz1.Text q = shbz2.Text Else z = dfbz1.Text q = dfbz2.Text End If Czs = Czs + z * n Cqt = Cqt + q * n Next Textzs.Text = Czs Textqt.Text = Cqt - jiaoz * (Int(shbz2.Text) - Int(dfbz2.Text) Textqb.Text = Ccph + Ccpq + Ccpf + Czs + Cqt End Sub
10、 数据输出到文本中 Private Sub shuchu_Click(sender As Object, e As EventArgs) Handles shuchu.Click Dim n As Integer, m As Integer Dim path As String Dim riqi As String If i = 0 Then MsgBox(没有数据可供输出,请输入数据后再尝试输出) Exit Sub End If SaveFileDialog1.ShowDialog() 打开保存对话框 path = SaveFileDialog1.FileName OpenFileDialo
11、g1.ShowDialog() path = OpenFileDialog1.FileName() For n = 0 To i - 1 For m = 1 To (10 - Len(cp(n).chufd) * 2) 2 将出发地点标准还为10个字符 cp(n).chufd = & cp(n).chufd & Next For m = 1 To (10 - Len(cp(n).mudd) * 2) 2 将目的地点标准还为10个字符 cp(n).mudd = & cp(n).mudd & Next For m = 1 To (8 - Len(cp(n).jiaotfs) * 2) 2 将交通方
12、式标准化为8个字符 cp(n).jiaotfs = & cp(n).jiaotfs & Next Next My.Computer.FileSystem.WriteAllText(path, 日期 时间 出发地点 目的地点 交通方式 价格 住宿天数 & vbNewLine, True) For n = 0 To i - 1 输出车票明细 riqi = Format(cp(n).riq, yyyyMMdd) My.Computer.FileSystem.WriteAllText(path, riqi, True) If cp(n).shij = Then 将时间标准化为6个字符长度 My.Com
13、puter.FileSystem.WriteAllText(path, & , True) ElseIf cp(n).shij 1000 = 0 Then My.Computer.FileSystem.WriteAllText(path, & cp(n).shij 100 & : & cp(n).shij Mod 100 & , True) Else My.Computer.FileSystem.WriteAllText(path, & cp(n).shij 100 & : & cp(n).shij Mod 100, True) End If My.Computer.FileSystem.Wr
14、iteAllText(path, & cp(n).chufd, True) My.Computer.FileSystem.WriteAllText(path, & cp(n).mudd, True) My.Computer.FileSystem.WriteAllText(path, & cp(n).jiaotfs, True) If cp(n).jiag Mod 1 = 0 Then 将车票价格标准化为5个字符并输出 If cp(n).jiag 10 = 0 Then My.Computer.FileSystem.WriteAllText(path, & & cp(n).jiag & , Tr
15、ue) ElseIf cp(n).jiag 100 = 0 Then My.Computer.FileSystem.WriteAllText(path, & & cp(n).jiag & , True) ElseIf cp(n).jiag 1000 = 0 Then My.Computer.FileSystem.WriteAllText(path, & & cp(n).jiag & , True) ElseIf cp(n).jiag 10000 = 0 Then My.Computer.FileSystem.WriteAllText(path, & cp(n).jiag & , True) E
16、lse My.Computer.FileSystem.WriteAllText(path, & cp(n).jiag, True) End If Else If cp(n).jiag 10 = 0 Then My.Computer.FileSystem.WriteAllText(path, & & cp(n).jiag & , True) ElseIf cp(n).jiag 100 = 0 Then My.Computer.FileSystem.WriteAllText(path, & cp(n).jiag & , True) ElseIf cp(n).jiag 1000 = 0 Then M
17、y.Computer.FileSystem.WriteAllText(path, & cp(n).jiag, True) Else My.Computer.FileSystem.WriteAllText(path, & cp(n).jiag, True) End If End If My.Computer.FileSystem.WriteAllText(path, & cp(n).tians & vbNewLine, True) Next 输出汇总数据 My.Computer.FileSystem.WriteAllText(path, vbNewLine, True) If Ccpq Then
18、 My.Computer.FileSystem.WriteAllText(path, 汽车票: & Str(Ccpq) & 元 & vbNewLine, True) If Ccph Then My.Computer.FileSystem.WriteAllText(path, 火车票: & Str(Ccph) & 元 & vbNewLine, True) If Ccpf Then My.Computer.FileSystem.WriteAllText(path, 过路费: & Str(Ccpf) & 元 & vbNewLine, True) If Czs Then My.Computer.Fil
19、eSystem.WriteAllText(path, 住宿补贴: & Str(Czs) & 元 & vbNewLine, True) If Cqt Then My.Computer.FileSystem.WriteAllText(path, 其他补助: & Str(Cqt) & 元 & vbNewLine, True) If Int(Textqb.Text) Then My.Computer.FileSystem.WriteAllText(path, 费用总和: & & Textqb.Text & 元 & vbNewLine, True) Shell(notepad.exe & path) E
20、nd Sub 清除数据 Private Sub qingchu_Click(sender As Object, e As EventArgs) Handles qingchu.Click If i = 0 Then MsgBox(没有车票可供清除) Exit Sub End If Czs = 0 Cqt = 0 i = i - 1 If cp(i).jiaotfs = 汽车 Then Ccpq = Ccpq - cp(i).jiag If cp(i).jiaotfs = 火车 Then Ccph = Ccph - cp(i).jiag If cp(i).jiaotfs = 服务车 Then C
21、cpf = Ccpf - cp(i).jiag MsgBox(清除: & cp(i).riq & & cp(i).chufd & 到 & cp(i).mudd & & 价格: & cp(i).jiag) Label12.Text = i & 张 Textqc.Text = Ccpq Texthc.Text = Ccph Textglf.Text = Ccpf Textzs.Text = 0 Textqt.Text = 0 Textqb.Text = 0 End Sub 出发地与目的地地址交换 Private Sub Label11_Click(sender As Object, e As Ev
22、entArgs) Handles Label11.Click Dim ddjh As String ddjh = cfdd.Text cfdd.Text = mddd.Text mddd.Text = ddjh If sh.Checked Then sh.Checked = Not sh.Checked fsh.Checked = Not fsh.Checked Else fsh.Checked = Not fsh.Checked sh.Checked = Not sh.Checked End If End Sub 防止输入非法字符 Private Sub shbz1_KeyPress(sen
23、der As Object, e As KeyPressEventArgs) Handles shbz1.KeyPress If Asc(e.KeyChar) = 8 Or Asc(e.KeyChar) = 46 Then Exit Sub If Asc(e.KeyChar) = 13 Then shbz2.Focus() If Asc(e.KeyChar) = 58 Then e.KeyChar = End Sub 防止输入非法字符 Private Sub shbz2_KeyPress(sender As Object, e As KeyPressEventArgs) Handles shb
24、z2.KeyPress If Asc(e.KeyChar) = 8 Or Asc(e.KeyChar) = 46 Then Exit Sub If Asc(e.KeyChar) = 13 Then dfbz1.Focus() If Asc(e.KeyChar) = 58 Then e.KeyChar = End Sub 防止输入非法字符 Private Sub dfbz1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles dfbz1.KeyPress If Asc(e.KeyChar) = 8 Or Asc(e.KeyChar
25、) = 46 Then Exit Sub If Asc(e.KeyChar) = 13 Then dfbz2.Focus() If Asc(e.KeyChar) = 58 Then e.KeyChar = End Sub 防止输入非法字符 Private Sub dfbz2_KeyPress(sender As Object, e As KeyPressEventArgs) Handles dfbz2.KeyPress If Asc(e.KeyChar) = 8 Or Asc(e.KeyChar) = 46 Then Exit Sub If Asc(e.KeyChar) = 13 Then D
26、ate1.Focus() If Asc(e.KeyChar) = 58 Then e.KeyChar = End Sub 防止输入非法字符 Private Sub cfsj_KeyPress(sender As Object, e As KeyPressEventArgs) Handles cfsj.KeyPress If Asc(e.KeyChar) = 8 Then Exit Sub If Asc(e.KeyChar) = 13 Then cpjg1.Focus() If Asc(e.KeyChar) = 58 Then e.KeyChar = End Sub 防止输入非法字符 Priva
27、te Sub cpjg1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles cpjg1.KeyPress If Asc(e.KeyChar) = 8 Or Asc(e.KeyChar) = 46 Then Exit Sub If Asc(e.KeyChar) = 13 Then cfdd.Focus() If Asc(e.KeyChar) = 58 Then e.KeyChar = End Sub Private Sub cfdd_KeyPress(sender As Object, e As KeyPressEventArgs) Handles cfdd.KeyPress If Asc(e.KeyChar) = 13 Then mddd.Focus() End Sub Private Sub mddd_KeyPress(sender As Object, e As KeyPressEventArgs) Handles mddd.KeyPress If Asc(e.KeyChar) = 13 Then SR.Focus() End SubEnd Class
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1