我在英国的AS Level学习计算,我们使用的语言是VB6。
我正在完成必须在2014年12月18日完成的作业。
该项目是针对一个假设情况,即跑步俱乐部需要软件来执行以下操作: - 添加会员 - 查看会员 - 编辑会员信息 - 搜索会员 - 删除会员 - 为会员添加培训信息 - 查看培训信息 - 比较培训信息 - 根据
训练的小时数自动选择一组跑步者这是我的问题表单代码:
Option Explicit
Private Sub CmdExitFromSelectTeam_Click()
Unload Me
End Sub
Private Sub SelectTeam()
Dim TrainingChannel As Integer
Dim Training As TrainingRecord
Dim MemberChannel As Integer
Dim Member As MemberRecord
Dim MemberRecordPointer As Integer
Dim TotalHoursTrained As Single
Dim TrainingRecordPointer As Integer
Dim FoundAtLeastOneRecord
FoundAtLeastOneRecord = False
MemberChannel = FreeFile
Open MemberFile For Random As MemberChannel Len = MemberLength
MemberRecordPointer = 1
Get MemberChannel, MemberRecordPointer, Member
Do While Not EOF(MemberChannel)
TotalHoursTrained = 0
TrainingRecordPointer = 1
TrainingChannel = FreeFile
Open TrainingFile For Random As TrainingChannel Len = TrainingLength
Get TrainingChannel, MemberRecordPointer, Training
Do While Not EOF(TrainingChannel)
If Member.ID = Training.MemberID Then
TotalHoursTrained = Round(TotalHoursTrained, 1) + Round(Training.TimeTaken, 1)
End If
TrainingRecordPointer = TrainingRecordPointer + 1 (*)
Get TrainingChannel, MemberRecordPointer, Training
Loop
Close TrainingChannel
LstTeamSelectDisplayTeam.AddItem TotalHoursTrained, 1
LstTeamSelectDisplayTeam.AddItem Member.ID, 2
LstTeamSelectDisplayTeam.AddItem Member.Forename, 3
LstTeamSelectDisplayTeam.AddItem Member.Surname, 4
MemberRecordPointer = MemberRecordPointer + 1
Get MemberChannel, MemberRecordPointer, Member
Loop
Close MemberChannel
End Sub
Private Sub Form_Load()
SelectTeam
End Sub
在运行时加载此表单(FrmSelectTeam.frm)时,标有(*)的行将突出显示为调试行。
我不知道问题是什么,我很感激能得到的所有帮助,所以提前谢谢!!!
詹姆斯
答案 0 :(得分:4)
在VB6中,Integer数据类型的最大值为32767.在(*)语句中显然超出了该限制。您可以通过将其声明为long来将其更改为32位整数:
Dim TrainingRecordPointer As Long
答案 1 :(得分:0)
@ xpda的回答几乎肯定是正确的。
这样的错误的一个方便的调试技巧是稍微修改你的代码,如下所示:
Open MemberFile For Random As MemberChannel Len = MemberLength
MemberRecordPointer = 1
Get MemberChannel, MemberRecordPointer, Member
Do While Not EOF(MemberChannel)
TotalHoursTrained = 0
TrainingRecordPointer = 1
TrainingChannel = FreeFile
Open TrainingFile For Random As TrainingChannel Len = TrainingLength
Get TrainingChannel, MemberRecordPointer, Training
Do While Not EOF(TrainingChannel)
If Member.ID = Training.MemberID Then
TotalHoursTrained = Round(TotalHoursTrained, 1) + Round(Training.TimeTaken, 1)
End If
If TrainingRecordPointer > 32750 Then
Debug.Print TrainingRecordPointer
End If
TrainingRecordPointer = TrainingRecordPointer + 1
Get TrainingChannel, MemberRecordPointer, Training
Loop
Close TrainingChannel
LstTeamSelectDisplayTeam.AddItem TotalHoursTrained, 1
LstTeamSelectDisplayTeam.AddItem Member.ID, 2
LstTeamSelectDisplayTeam.AddItem Member.Forename, 3
LstTeamSelectDisplayTeam.AddItem Member.Surname, 4
MemberRecordPointer = MemberRecordPointer + 1
Get MemberChannel, MemberRecordPointer, Member
Loop
Close MemberChannel
或者,您可以在添加的If-Then中添加断点,然后逐步使用调试器。
答案 2 :(得分:0)
嗯,谢谢你的反馈,但究竟是什么原因(信不信由你)是简单的人为错误;我把" Get TrainingChannel,MemberRecordPointer,Training"而不是"获取TrainingChannel,TrainingRecordPointer,Training"
令人讨厌的是,这样简单的事情可能会导致如此大的问题。
但是再次感谢!!