| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 495 人关注过本帖, 1 人收藏
标题:自己动手写了个“个人信息管理”的小程序,现在不知道哪里有问题,老是出错 ...
只看楼主 加入收藏
kangduty
Rank: 2
等 级:论坛游民
帖 子:8
专家分:22
注 册:2009-7-30
结帖率:100%
收藏(1)
已结贴  问题点数:20 回复次数:2 
自己动手写了个“个人信息管理”的小程序,现在不知道哪里有问题,老是出错(附源代码)
代码如下:

Dim X As Integer
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim hs As Integer
'翻到最后一页,再下翻一页,填写新记录
Private Sub CmdAdd_Click()
CmdNew.Visible = True
CmdPic.Visible = True
X = LblShow.Caption
Do While xlSheet.Cells(X, 1) <> ""
X = X + 1
Loop
LblShow.Caption = X
Txt1.Text = ""
Txt2.Text = ""
Txt3.Text = ""
PicShow = LoadPicture(Txt3.Text)
PicShow.AutoSize = True

End Sub
'删除当前记录,并跳转到前一条记录
Private Sub CmdDelete_Click()
X = LblShow.Caption
xlSheet.Rows(X).Delete
Do While xlSheet.Cells(X + 1, 1) <> ""
X = X + 1
Loop
Txt1.Text = xlSheet.Cells(X - 1, 1)
Txt2.Text = xlSheet.Cells(X - 1, 2)
Txt3.Text = xlSheet.Cells(X - 1, 3)
PicShow = LoadPicture(xlSheet.Cells(X - 1, 3))
PicShow.AutoSize = True
LblShow.Caption = X - 1
End Sub

' 查看末记录
Private Sub CmdEnd_Click()
CmdNew.Visible = False
CmdPic.Visible = False
X = LblShow.Caption
Do While xlSheet.Cells(X, 1) <> ""
X = X + 1
Loop
Txt1.Text = xlSheet.Cells(X - 1, 1)
Txt2.Text = xlSheet.Cells(X - 1, 2)
Txt3.Text = xlSheet.Cells(X - 1, 3)
PicShow = LoadPicture(xlSheet.Cells(X - 1, 3))
PicShow.AutoSize = True
LblShow.Caption = X - 1
End Sub
' 向EXCEL中写数据
Private Sub CmdNew_Click()
xlSheet.Cells(X, 1) = Txt1.Text
xlSheet.Cells(X, 2) = Txt2.Text
xlSheet.Cells(X, 3) = Txt3.Text
xlApp.Quit '退出EXCEL
Set xlApp = CreateObject("Excel.Application") '
Set xlBook = xlApp.Workbooks.Open("D:\aa.xls") '
xlApp.Visible = False '
Set xlSheet = xlBook.Worksheets(1) '重新加载EXCEL
X = LblShow.Caption
Do While xlSheet.Cells(X, 1) <> ""
X = X + 1
Loop
LblShow.Caption = X
Txt1.Text = ""
Txt2.Text = ""
Txt3.Text = ""
PicShow = LoadPicture(Txt3.Text)
PicShow.AutoSize = True
End Sub
' 打开图片路径
Private Sub CmdPic_Click()
Form1.Show
End Sub
' 向前翻页
Private Sub CmdPre_Click()
CmdNew.Visible = False
CmdPic.Visible = False
X = LblShow.Caption
X = X - 1
If X > 0 Then
Txt1.Text = xlSheet.Cells(X, 1)
Txt2.Text = xlSheet.Cells(X, 2)
Txt3.Text = xlSheet.Cells(X, 3)
PicShow = LoadPicture(xlSheet.Cells(X, 3))
PicShow.AutoSize = True
LblShow.Caption = X
Else
MsgBox "已经到第一条记录"
End If

End Sub
'退出程序
Private Sub CmdQuit_Click()
xlApp.Quit
Set xlApp = Nothing
End
End Sub
'查看记录
Private Sub CmdShow_Click()
CmdNew.Visible = False
CmdPic.Visible = False
xlApp.Quit
Set xlApp = Nothing
Call Form_Load
End Sub
'查看起始页
Private Sub CmdStart_Click()
CmdNew.Visible = False
CmdPic.Visible = False
X = LblShow.Caption
X = X - 1
If X > 0 Then
xlApp.Quit
Set xlApp = Nothing
Call Form_Load
Else
MsgBox "已经到第一条记录"
End If

End Sub
'向后翻页
Private Sub CmdSuf_Click()
CmdNew.Visible = False
CmdPic.Visible = False
X = LblShow.Caption
X = X + 1
If xlSheet.Cells(X, 1) <> "" Then
Txt1.Text = xlSheet.Cells(X, 1)
Txt2.Text = xlSheet.Cells(X, 2)
Txt3.Text = xlSheet.Cells(X, 3)
PicShow = LoadPicture(xlSheet.Cells(X, 3))
PicShow.AutoSize = True
LblShow.Caption = X
Else
MsgBox "已经到最后一条记录"
End If
End Sub
'加载数据
Private Sub Form_Load()
CmdNew.Visible = False
CmdPic.Visible = False
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("D:\aa.xls")
xlApp.Visible = False
Set xlSheet = xlBook.Worksheets(1)
Txt1.Text = xlSheet.Cells(1, 1)
Txt2.Text = xlSheet.Cells(1, 2)
Txt3.Text = xlSheet.Cells(1, 3)
PicShow = LoadPicture(xlSheet.Cells(1, 3))
PicShow.AutoSize = True
LblShow.Caption = 1
End Sub

在保存新记录时,第一条记录没有问题,第二条记录就出现要求保存为 “副本文件”了,是哪里代码出错了?

[[it] 本帖最后由 kangduty 于 2009-8-4 13:39 编辑 [/it]]

员工管理.rar (2.98 KB) 员工管理源代码

搜索更多相关主题的帖子: 个人信息管理 
2009-08-03 13:34
suxin868
Rank: 4
等 级:业余侠客
威 望:1
帖 子:145
专家分:203
注 册:2008-12-31
收藏
得分:14 
打包发上来嘛,这样怎么能找出错来啊。

--------------当你无力改变这个世界的时候,就让这个世界改变你-------------------
2009-08-04 09:48
kangduty
Rank: 2
等 级:论坛游民
帖 子:8
专家分:22
注 册:2009-7-30
收藏
得分:0 
以下是引用suxin868在2009-8-4 09:48的发言:

打包发上来嘛,这样怎么能找出错来啊。


已经放包
2009-08-04 13:40
快速回复:自己动手写了个“个人信息管理”的小程序,现在不知道哪里有问题,老是 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.092804 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved