VB编程报销计算器.docx
《VB编程报销计算器.docx》由会员分享,可在线阅读,更多相关《VB编程报销计算器.docx(14页珍藏版)》请在冰豆网上搜索。
VB编程报销计算器
VB-编程--报销计算器
————————————————————————————————作者:
————————————————————————————————日期:
报销计算器
本程序采用VB语言编写,编程软件为VS2012
本计算器是为了计算出差补助,实现以下功能
1:
能够方便的输入省会补助标准(包含:
住宿和其他补助项)_高标准、地方补助标准_低标准
2:
能够完整的输入车票信息:
车票日期时间、出发地点、目的地点、车票价格、以及乘车方式
3:
能够准确的计算出各项补助金额,以及补助总金额
4:
能够将车票按照时间顺序排序并输出到文本中,并能计算出在各地的住宿天数
具体程序及界面如下:
完整程序如下:
PublicClassForm1
Structurechepiao
DimriqAsDate
DimshijAsString
DimjiagAsSingle
DimchufdAsString
DimmuddAsString
DimshenghAsBoolean
DimjiaotfsAsString
DimtiansAsInteger
EndStructure
Privatecp(200)Aschepiao
PrivateCcpqAsSingle,CcphAsSingle,CcpfAsSingle,CzsAsInteger,CqtAsInteger
PrivatezAsInteger,qAsInteger
PrivateiAsInteger
PrivateSubForm1_Load(senderAsObject,eAsEventArgs)HandlesMyBase.Load
Czs=0'为全局数据赋初始值
Cqt=0
Ccpq=0
Ccph=0
Ccpf=0
i=0
EndSub
'读取车票信息并对出行方式车票价格求和
PrivateSubButton1_Click(senderAsObject,eAsEventArgs)HandlesSR.Click
Ifcfsj.Text<>""Then
If(Int(cfsj.Text)/100)>24Or(Int(cfsj.Text)Mod100)>=60Then
MsgBox("输入的时间不正确,请重新输入")
ExitSub
EndIf
EndIf
cp(i).riq=Date1.Value'读取车票时间信息
Ifcfsj.Text<>""Thencp(i).shij=cfsj.Text
cp(i).chufd=cfdd.Text'读取车票地址信息
cp(i).mudd=mddd.Text
cp(i).shengh=sh.Checked'记录车票目的地是否为省会
Ifshbz1.Text=""Orshbz2.Text=""Then
MsgBox("请将省会补助标准正确填写完整,没有填0")'检查补助标准是否填写正确
ExitSub
EndIf
Ifdfbz1.Text=""Ordfbz2.Text=""Then
MsgBox("请将地方补助标准正确填写完整,没有填0")
ExitSub
EndIf
Ifcpjg1.Text=""Then
MsgBox("请输入车票价格,点击确定继续")
ExitSub
Else
cp(i).jiag=cpjg1.Text'判断是否为第一天出行
Ifhc.CheckedThen'判断车票类型,并对相应车票求和
Ccph=Ccph+cp(i).jiag
cp(i).jiaotfs="火车"
ElseIfqc.CheckedThen
Ccpq=Ccpq+cp(i).jiag
cp(i).jiaotfs="汽车"
Else
Ccpf=Ccpf+cp(i).jiag
cp(i).jiaotfs="服务车"
EndIf
EndIf
GroupBox1.Enabled=False'保证第一次正确输入后标准不能更改
i=i+1
Textqc.Text=Ccpq'输出各项费用
Texthc.Text=Ccph
Textglf.Text=Ccpf
MsgBox("输入成功,点击确定继续")
Label12.Text=i&"张"
cpjg1.Focus()'车票价格输入框获得焦点
cpjg1.Text=""
EndSub
PrivateSubJS_Click(senderAsObject,eAsEventArgs)HandlesJS.Click
DimmAsInteger,nAsInteger
DimzAsInteger,qAsInteger
DimepAschepiao
DimjiaozAsInteger
jiaoz=0
Ifi=0Then
MsgBox("没有数据可供计算,请输入数据后再尝试计算")
ExitSub
EndIf
Czs=0
Cqt=0
Form=0Toi-2'对车票按时间排序
Forn=m+1Toi-1
IfDateDiff(DateInterval.Day,cp(m).riq,cp(n).riq)<0Then
ep=cp(m)
cp(m)=cp(n)
cp(n)=ep
ElseIfDateDiff(DateInterval.Day,cp(m).riq,cp(n).riq)=0Andcp(m).shij>cp(n).shijThen
ep=cp(m)
cp(m)=cp(n)
cp(n)=ep
EndIf
Next
Next
Form=1Toi-1
n=DateDiff(DateInterval.Day,cp(m-1).riq,cp(m).riq)
Ifcp(m-1).shenghAndn<>0Thenjiaoz=jiaoz+1
cp(m-1).tians=n
Ifcp(m-1).shenghThen'判断补助标准
z=shbz1.Text
q=shbz2.Text
Else
z=dfbz1.Text
q=dfbz2.Text
EndIf
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
EndSub
'数据输出到文本中
PrivateSubshuchu_Click(senderAsObject,eAsEventArgs)Handlesshuchu.Click
DimnAsInteger,mAsInteger
DimpathAsString
DimriqiAsString
Ifi=0Then
MsgBox("没有数据可供输出,请输入数据后再尝试输出")
ExitSub
EndIf
SaveFileDialog1.ShowDialog()'打开保存对话框
path=SaveFileDialog1.FileName
'OpenFileDialog1.ShowDialog()
'path=OpenFileDialog1.FileName()
Forn=0Toi-1
Form=1To(10-Len(cp(n).chufd)*2)\2'将出发地点标准还为10个字符
cp(n).chufd=""&cp(n).chufd&""
Next
Form=1To(10-Len(cp(n).mudd)*2)\2'将目的地点标准还为10个字符
cp(n).mudd=""&cp(n).mudd&""
Next
Form=1To(8-Len(cp(n).jiaotfs)*2)\2'将交通方式标准化为8个字符
cp(n).jiaotfs=""&cp(n).jiaotfs&""
Next
Next
My.Computer.FileSystem.WriteAllText(path,"日期时间出发地点目的地点交通方式价格住宿天数"&vbNewLine,True)
Forn=0Toi-1'输出车票明细
riqi=Format(cp(n).riq,"yyyyMMdd")
My.Computer.FileSystem.WriteAllText(path,riqi,True)
Ifcp(n).shij=""Then'将时间标准化为6个字符长度
My.Computer.FileSystem.WriteAllText(path,""&"",True)
ElseIfcp(n).shij\1000=0Then
My.Computer.FileSystem.WriteAllText(path,""&cp(n).shij\100&":
"&cp(n).shijMod100&"",True)
Else
My.Computer.FileSystem.WriteAllText(path,""&cp(n).shij\100&":
"&cp(n).shijMod100,True)
EndIf
My.Computer.FileSystem.WriteAllText(path,""&cp(n).chufd,True)
My.Computer.FileSystem.WriteAllText(path,""&cp(n).mudd,True)
My.Computer.FileSystem.WriteAllText(path,""&cp(n).jiaotfs,True)
Ifcp(n).jiagMod1=0Then'将车票价格标准化为5个字符并输出
Ifcp(n).jiag\10=0Then
My.Computer.FileSystem.WriteAllText(path,""&""&cp(n).jiag&"",True)
ElseIfcp(n).jiag\100=0Then
My.Computer.FileSystem.WriteAllText(path,""&""&cp(n).jiag&"",True)
ElseIfcp(n).jiag\1000=0Then
My.Computer.FileSystem.WriteAllText(path,""&""&cp(n).jiag&"",True)
ElseIfcp(n).jiag\10000=0Then
My.Computer.FileSystem.WriteAllText(path,""&cp(n).jiag&"",True)
Else
My.Computer.FileSystem.WriteAllText(path,""&cp(n).jiag,True)
EndIf
Else
Ifcp(n).jiag\10=0Then
My.Computer.FileSystem.WriteAllText(path,""&""&cp(n).jiag&"",True)
ElseIfcp(n).jiag\100=0Then
My.Computer.FileSystem.WriteAllText(path,""&cp(n).jiag&"",True)
'ElseIfcp(n).jiag\1000=0Then
'My.Computer.FileSystem.WriteAllText(path,""&cp(n).jiag,True)
Else
My.Computer.FileSystem.WriteAllText(path,""&cp(n).jiag,True)
EndIf
EndIf
My.Computer.FileSystem.WriteAllText(path,""&cp(n).tians&vbNewLine,True)
Next
'输出汇总数据
My.Computer.FileSystem.WriteAllText(path,vbNewLine,True)
IfCcpqThenMy.Computer.FileSystem.WriteAllText(path,"汽车票:
"&Str(Ccpq)&"元"&vbNewLine,True)
IfCcphThenMy.Computer.FileSystem.WriteAllText(path,"火车票:
"&Str(Ccph)&"元"&vbNewLine,True)
IfCcpfThenMy.Computer.FileSystem.WriteAllText(path,"过路费:
"&Str(Ccpf)&"元"&vbNewLine,True)
IfCzsThenMy.Computer.FileSystem.WriteAllText(path,"住宿补贴:
"&Str(Czs)&"元"&vbNewLine,True)
IfCqtThenMy.Computer.FileSystem.WriteAllText(path,"其他补助:
"&Str(Cqt)&"元"&vbNewLine,True)
IfInt(Textqb.Text)ThenMy.Computer.FileSystem.WriteAllText(path,"费用总和:
"&""&Textqb.Text&"元"&vbNewLine,True)
Shell("notepad.exe"&path)
EndSub
'清除数据
PrivateSubqingchu_Click(senderAsObject,eAsEventArgs)Handlesqingchu.Click
Ifi=0Then
MsgBox("没有车票可供清除")
ExitSub
EndIf
Czs=0
Cqt=0
i=i-1
Ifcp(i).jiaotfs="汽车"ThenCcpq=Ccpq-cp(i).jiag
Ifcp(i).jiaotfs="火车"ThenCcph=Ccph-cp(i).jiag
Ifcp(i).jiaotfs="服务车"ThenCcpf=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"
EndSub
'出发地与目的地地址交换
PrivateSubLabel11_Click(senderAsObject,eAsEventArgs)HandlesLabel11.Click
DimddjhAsString
ddjh=cfdd.Text
cfdd.Text=mddd.Text
mddd.Text=ddjh
Ifsh.CheckedThen
sh.Checked=Notsh.Checked
fsh.Checked=Notfsh.Checked
Else
fsh.Checked=Notfsh.Checked
sh.Checked=Notsh.Checked
EndIf
EndSub
'防止输入非法字符
PrivateSubshbz1_KeyPress(senderAsObject,eAsKeyPressEventArgs)Handlesshbz1.KeyPress
IfAsc(e.KeyChar)=8OrAsc(e.KeyChar)=46ThenExitSub
IfAsc(e.KeyChar)=13Thenshbz2.Focus()
IfAsc(e.KeyChar)<=47OrAsc(e.KeyChar)>=58Thene.KeyChar=""
EndSub
'防止输入非法字符
PrivateSubshbz2_KeyPress(senderAsObject,eAsKeyPressEventArgs)Handlesshbz2.KeyPress
IfAsc(e.KeyChar)=8OrAsc(e.KeyChar)=46ThenExitSub
IfAsc(e.KeyChar)=13Thendfbz1.Focus()
IfAsc(e.KeyChar)<=47OrAsc(e.KeyChar)>=58Thene.KeyChar=""
EndSub
'防止输入非法字符
PrivateSubdfbz1_KeyPress(senderAsObject,eAsKeyPressEventArgs)Handlesdfbz1.KeyPress
IfAsc(e.KeyChar)=8OrAsc(e.KeyChar)=46ThenExitSub
IfAsc(e.KeyChar)=13Thendfbz2.Focus()
IfAsc(e.KeyChar)<=47OrAsc(e.KeyChar)>=58Thene.KeyChar=""
EndSub
'防止输入非法字符
PrivateSubdfbz2_KeyPress(senderAsObject,eAsKeyPressEventArgs)Handlesdfbz2.KeyPress
IfAsc(e.KeyChar)=8OrAsc(e.KeyChar)=46ThenExitSub
IfAsc(e.KeyChar)=13ThenDate1.Focus()
IfAsc(e.KeyChar)<=47OrAsc(e.KeyChar)>=58Thene.KeyChar=""
EndSub
'防止输入非法字符
PrivateSubcfsj_KeyPress(senderAsObject,eAsKeyPressEventArgs)Handlescfsj.KeyPress
IfAsc(e.KeyChar)=8ThenExitSub
IfAsc(e.KeyChar)=13Thencpjg1.Focus()
IfAsc(e.KeyChar)<=47OrAsc(e.KeyChar)>=58Thene.KeyChar=""
EndSub
'防止输入非法字符
PrivateSubcpjg1_KeyPress(senderAsObject,eAsKeyPressEventArgs)Handlescpjg1.KeyPress
IfAsc(e.KeyChar)=8OrAsc(e.KeyChar)=46ThenExitSub
IfAsc(e.KeyChar)=13Thencfdd.Focus()
IfAsc(e.KeyChar)<=47OrAsc(e.KeyChar)>=58Thene.KeyChar=""
EndSub
PrivateSubcfdd_KeyPress(senderAsObject,eAsKeyPressEventArgs)Handlescfdd.KeyPress
IfAsc(e.KeyChar)=13Thenmddd.Focus()
EndSub
PrivateSubmddd_KeyPress(senderAsObject,eAsKeyPressEventArgs)Handlesmddd.KeyPress
IfAsc(e.KeyChar)=13ThenSR.Focus()
EndSub
EndClass