Sep 21st, 2007, 04:09 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] Error
Hello Guys,
Can anyone help me please?
Here is the problem
Run-time error'5';
Invalid procedure call or argument
This is my code.
VB Code:
Dim FileName As String
Private Sub cmdOK_Click()
Dim MemberID As String
Dim MemberDeleted As Boolean
Dim Duplicate As Boolean
Dim Response As Integer
Dim OneMember As MemberType
If cmdOK.Caption = "Add Member" Then
If Len(txtMemberIDAdd.Text) = 6 Then
MemberID = txtMemberIDAdd.Text
Duplicate = CheckDuplicateMemberID(MemberID)
If Not Duplicate Then
If (txtSurname.Text <> "") And (txtFirstname.Text <> "") And _
(lstCategory.Text <> "") Then
OneMember.MemberID = txtMemberIDAdd.Text
OneMember.Surname = txtSurname.Text
OneMember.Firstname = txtFirstname.Text
If lstCategory.Text = "Senior" Then
OneMember.Category = "S"
Else
OneMember.Category = "J"
End If
OneMember.Deleted = "N"
Call AddMember(OneMember)
txtMemberIDAdd.Text = ""
txtSurname.Text = ""
txtFirstname.Text = ""
Else
MsgBox ("You have not filled in all details of the member")
End If
Else
MsgBox "Membership Number. " & MemberID & " has been used. Enter", _
"a diffrentone"
txtMemberIDAdd.SetFocus
End If
Else
MsgBox ("You must enter a membership number within 6 characters")
txtMemberIDAdd.SetFocus
End If
Else
MemberID = txtMemberIDDelete.Text
If MemberID = "" Then
MsgBox ("You haven't entered a membership number")
Else
Response = MsgBox("Confirm you want to delete this number?", _
vbYesNo)
If Response = 6 Then
MemberDeleted = DeleteMember(MemberID)
txtMemberIDDelete.Text = ""
If Not MemberDeleted Then
MsgBox "Member not deleted. Membership number " _
& MemberID & "does not exist"
End If
End If
End If
End If
End Sub
Private Sub Form_Load()
FileName = App.Path & "\Members.dat"
End Sub
Private Sub optAdd_Click()
fraDelete.Visible = False
fraAdd.Visible = True
cmdOK.Caption = "Add Member"
End Sub
Private Sub optDelete_Click()
fraAdd.Visible = False
fraDelete.Visible = True
cmdOK.Caption = "Delete Member"
End Sub
Private Function CheckDuplicateMemberID(ByVal MemberID As String) As _
Boolean
Dim Found As Boolean
Dim OneMember As MemberType
Found = False
Open FileName For Random As #1 Len = Len(OneMember)
Do While (Not EOF(1)) And (Found = False)
Get #1, , OneMember
If MemberID = OneMember.MemberID Then
Found = True
End If
Loop
CheckDuplicateMemberID = Found
Close #1
End Function
Private Function FindDeletedMember() As Integer
Dim Found As Boolean
Dim RecordNumber As Integer
Dim OneMemebr As MemberType
Found = False
RecordNumber = 0
Open FileName For Random As #1 Len = Len(OneMember)
Do While (Not EOF(1)) And (Found = False)
RecordNumber = RecordNumber + 1
Get #1, RecordNumber, OneMember
If OneMember.Deleted = "Y" Then
Found = True
End If
Loop
If Found Then
FindDeletedMember = RecordNumber
Else
FindDeletedMember = 0
End If
Close #1
End Function
Private Sub AddMember(ByRef OneMember As MemberType)
Dim NumberOfRecords As Integer
Dim DeleteRecordNumber As Integer
DeleteRecordNumber = FindDeletedMember
Open FileName For Random As #1 Len = Len(OneMember)
If DeletedRecordFound <> 0 Then
Put #1, DeletedRecordNumber, OneMember
Else
NumberOfRecords = LOF(1) / Len(OneMember)
Put #1, NumberOfRecords + 1, OneMember
End If
Close #1
End Sub
Private Function DeleteMember(ByVal MemberID As String) As Boolean
Dim OneMember As MemberType
Dim RecordNumber As Integer
Dim Found As Boolean
RecordNumber = 0
Found = False
Open FileName For Random As #1 Len = Len(OneMember)
Do While (Not EOF(1)) And (Not Found)
RecordNumber = RecordNumber + 1
Get #1, RecordNumber, OneMemebr
If OneMember.MemberID = MemberID Then
If OneMember.Deleted = "Y" Then
MsgBox "This number dosent exist"
Else
OneMember.Deleted = "Y"
Found = True
End If
End If
Loop
If Not Found Then
DeleteMember = False
Else
DeleteMember = True
End If
Put #1, RecordNumber, OneMemebr
Close #1
Call cmdDisplayMember_Click
End Function
The error comes up highlighted
vb Code:
Open FileName For Random As #1 Len = Len(OneMember)
Last edited by Jamie_Garland; Sep 21st, 2007 at 04:25 PM .
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
Sep 21st, 2007, 05:28 PM
#2
Thread Starter
Frenzied Member
Re: Error
Can anyone help me solve this problem please?
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
Sep 21st, 2007, 05:53 PM
#3
Re: Error
Hang on Mark I am getting on msn message me.
If a post has been helpful please rate it.
If your question has been answered, pull down the tread tools and mark it as resolved.
Sep 21st, 2007, 06:07 PM
#4
Re: Error
On what line are you getting the error?
You also could put you code in a more readable format especially if you want others to read it and help...
Sep 21st, 2007, 06:13 PM
#5
Thread Starter
Frenzied Member
Re: Error
Here is the full code and the error is on line 104 i think.
vb Code:
Dim FileName As String
Private Sub cmdOK_Click()
Dim MemberID As String
Dim MemberDeleted As Boolean
Dim Duplicate As Boolean
Dim Response As Integer
Dim OneMember As MemberType
If cmdOK.Caption = "Add Member" Then
If Len(txtMemberIDAdd.Text) = 6 Then
MemberID = txtMemberIDAdd.Text
Duplicate = CheckDuplicateMemberID(MemberID)
If Not Duplicate Then
If (txtSurname.Text <> "") And (txtFirstname.Text <> "") And _
(lstCategory.Text <> "") Then
OneMember.MemberID = txtMemberIDAdd.Text
OneMember.Surname = txtSurname.Text
OneMember.Firstname = txtFirstname.Text
If lstCategory.Text = "Senior" Then
OneMember.Category = "S"
Else
OneMember.Category = "J"
End If
OneMember.Deleted = "N"
Call AddMember(OneMember)
txtMemberIDAdd.Text = ""
txtSurname.Text = ""
txtFirstname.Text = ""
Else
MsgBox ("You have not filled in all details of the member")
End If
Else
MsgBox "Membership Number. " & MemberID & " has been used. Enter", _
"a diffrentone"
txtMemberIDAdd.SetFocus
End If
Else
MsgBox ("You must enter a membership number within 6 characters")
txtMemberIDAdd.SetFocus
End If
Else
MemberID = txtMemberIDDelete.Text
If MemberID = "" Then
MsgBox ("You haven't entered a membership number")
Else
Response = MsgBox("Confirm you want to delete this number?", _
vbYesNo)
If Response = 6 Then
MemberDeleted = DeleteMember(MemberID)
txtMemberIDDelete.Text = ""
If Not MemberDeleted Then
MsgBox "Member not deleted. Membership number " _
& MemberID & "does not exist"
End If
End If
End If
End If
End Sub
Private Sub Form_Load()
FileName = App.Path & "\Members.dat"
End Sub
Private Sub optAdd_Click()
fraDelete.Visible = False
fraAdd.Visible = True
cmdOK.Caption = "Add Member"
End Sub
Private Sub optDelete_Click()
fraAdd.Visible = False
fraDelete.Visible = True
cmdOK.Caption = "Delete Member"
End Sub
Private Function CheckDuplicateMemberID(ByVal MemberID As String) As _
Boolean
Dim Found As Boolean
Dim OneMember As MemberType
Found = False
Open FileName For Random As #1 Len = Len(OneMember)
Do While (Not EOF(1)) And (Found = False)
Get #1, , OneMember
If MemberID = OneMember.MemberID Then
Found = True
End If
Loop
CheckDuplicateMemberID = Found
Close #1
End Function
Private Function FindDeletedMember() As Integer
Dim Found As Boolean
Dim RecordNumber As Integer
Dim OneMemebr As MemberType
Found = False
RecordNumber = 0
Open FileName For Random As #1 Len = Len(OneMember)
Do While (Not EOF(1)) And (Found = False)
RecordNumber = RecordNumber + 1
Get #1, RecordNumber, OneMember
If OneMember.Deleted = "Y" Then
Found = True
End If
Loop
If Found Then
FindDeletedMember = RecordNumber
Else
FindDeletedMember = 0
End If
Close #1
End Function
Private Sub AddMember(ByRef OneMember As MemberType)
Dim NumberOfRecords As Integer
Dim DeleteRecordNumber As Integer
DeleteRecordNumber = FindDeletedMember
Open FileName For Random As #1 Len = Len(OneMember)
If DeletedRecordFound <> 0 Then
Put #1, DeletedRecordNumber, OneMember
Else
NumberOfRecords = LOF(1) / Len(OneMember)
Put #1, NumberOfRecords + 1, OneMember
End If
Close #1
End Sub
Private Function DeleteMember(ByVal MemberID As String) As Boolean
'Page 219
Dim OneMember As MemberType
Dim RecordNumber As Integer
Dim Found As Boolean
RecordNumber = 0
Found = False
Open FileName For Random As #1 Len = Len(OneMember)
Do While (Not EOF(1)) And (Not Found)
RecordNumber = RecordNumber + 1
Get #1, RecordNumber, OneMemebr
If OneMember.MemberID = MemberID Then
If OneMember.Deleted = "Y" Then
MsgBox "This number dosent exist"
Else
OneMember.Deleted = "Y"
Found = True
End If
End If
Loop
If Not Found Then
DeleteMember = False
Else
DeleteMember = True
End If
Put #1, RecordNumber, OneMemebr
Close #1
End Function
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
Sep 21st, 2007, 06:16 PM
#6
Re: Error
What do you mean "YOU THINK". Didn't you run it in the IDE and get the error? It would stop on the line in question...
Sep 21st, 2007, 06:17 PM
#7
Re: Error
I am helping him solve it. He is getting it on line 104.
If a post has been helpful please rate it.
If your question has been answered, pull down the tread tools and mark it as resolved.
Sep 21st, 2007, 06:20 PM
#8
Re: Error
OK, So why are you off line helping instead of helping him here where other can benefit
Sep 21st, 2007, 06:26 PM
#9
Re: Error
Because we are actively chatting and discussing where it would spam the board.
If a post has been helpful please rate it.
If your question has been answered, pull down the tread tools and mark it as resolved.
Sep 21st, 2007, 06:49 PM
#10
Thread Starter
Frenzied Member
Re: Error
I have attached my code so you guys can take a look.
Attached Files
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
Sep 21st, 2007, 06:53 PM
#11
Re: Error
Actually that is the least of your worries. Try putting Option Explicit in the top of all your forms/modules/classes... You will see what I mean. This program will never work properly in it's current state.
Sep 21st, 2007, 07:10 PM
#12
Thread Starter
Frenzied Member
Re: Error
Actually i got that part working now thanks
I have come across another little error when i type in the Membership Number of the persion i want to delete it lets me delete them from the prgram but when i open the data file in notpad the information is still there here is the code below for deleteing the member.
vb Code:
Private Sub cmdOK_Click()
Dim MemberID As String
Dim MemberDeleted As Boolean
Dim Duplicate As Boolean
Dim Response As Integer
Dim OneMember As MemberType
If cmdOK.Caption = "Add Member" Then
If Len(txtMemberIDAdd.Text) = 6 Then
MemberID = txtMemberIDAdd.Text
Duplicate = CheckDuplicateMemberID(MemberID)
If Not Duplicate Then
If (txtSurname.Text <> "") And (txtFirstname.Text <> "") And _
(lstCategory.Text <> "") Then
OneMember.MemberID = txtMemberIDAdd.Text
OneMember.Surname = txtSurname.Text
OneMember.Firstname = txtFirstname.Text
If lstCategory.Text = "Senior" Then
OneMember.Category = "S"
Else
OneMember.Category = "J"
End If
OneMember.Deleted = "N"
Call AddMember(OneMember)
txtMemberIDAdd.Text = ""
txtSurname.Text = ""
txtFirstname.Text = ""
Else
MsgBox ("You have not filled in all details of the member")
End If
Else
MsgBox "Membership Number. " & MemberID & " has been used. Enter", _
"a diffrentone"
txtMemberIDAdd.SetFocus
End If
Else
MsgBox ("You must enter a membership number within 6 characters")
txtMemberIDAdd.SetFocus
End If
Else
MemberID = txtMemberIDDelete.Text
If MemberID = "" Then
MsgBox ("You haven't entered a membership number")
Else
Response = MsgBox("Confirm you want to delete this number?", _
vbYesNo)
If Response = 6 Then
MemberDeleted = DeleteMember(MemberID)
txtMemberIDDelete.Text = ""
If Not MemberDeleted Then
MsgBox "Member not deleted. Membership number " _
& MemberID & " does not exist"
End If
End If
End If
End If
End Sub
and
vb Code:
Private Function DeleteMember(ByVal MemberID As String) As Boolean
Dim OneMember As MemberType
Dim RecordNumber As Integer
Dim Found As Boolean
RecordNumber = 0
Found = False
Open FileName For Random As #1 Len = Len(OneMember)
Do While (Not EOF(1)) And (Not Found)
RecordNumber = RecordNumber + 1
Get #1, RecordNumber, OneMember
If OneMember.MemberID = MemberID Then
If OneMember.Deleted = "Y" Then
MsgBox "This number dosent exist"
Else
OneMember.Deleted = "Y"
Found = True
End If
End If
Loop
If Not Found Then
DeleteMember = False
Else
DeleteMember = True
End If
Put #1, RecordNumber, OneMember
Close #1
End Function
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
Sep 21st, 2007, 07:13 PM
#13
Re: Error
Didn't you read post #11 or are you just going trial and error?
Sep 21st, 2007, 07:28 PM
#14
Thread Starter
Frenzied Member
Re: Error
Yes, I read post 11 i have addred Option Explicit to all forms but it wont delete the text from the text file can u help please?
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
Sep 21st, 2007, 07:36 PM
#15
Re: Error
You should have gotten all sorts of undefined variable errors. Did you correct those?
BTW: What do you mean "won't delete the text"?
Are you getting any errors? etc...
Sep 22nd, 2007, 04:32 AM
#16
Thread Starter
Frenzied Member
Re: Error
All errors have been sorted now.
Apart from the delete one, when i click delete memeber it deletes the member from the program and then dosent recognize it but its not been deleted from the Members.dat file.
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
Sep 22nd, 2007, 04:35 AM
#17
Re: Error
You realize you need to post the code for we have no idea what you mean...
Sep 22nd, 2007, 04:52 AM
#18
Thread Starter
Frenzied Member
Re: Error
I have attacked code its on frmMembers.
Attached Files
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
Sep 22nd, 2007, 04:57 AM
#19
Re: Error
How do you run your app???? As soon as I started it I got this error
Sub, Function, or Property not defined (Error 35)
Call cmdDisplayMember_Click
You don't run with full compile do you???? How do you expect to catch all the errors before they catch you?
Sep 22nd, 2007, 05:09 AM
#20
Thread Starter
Frenzied Member
Re: Error
I'm sorry again i have fixed the errors now everything should work sorry again.
Still need help with the delete tho.
Attached Files
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
Sep 22nd, 2007, 05:16 AM
#21
Re: Error
OK, It runs now (You still have other errors). So, what do I do with it???
Sep 22nd, 2007, 05:19 AM
#22
Thread Starter
Frenzied Member
Re: Error
You run the program, then click on Memberships, Then you fill in the information required for Membership ID put 465736 then hit save then once its saved click on the other option button and type in 465736 and hit the delete button then check the Members.dat file and you'll see that it hasnt deleted it from the file.
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
Sep 22nd, 2007, 05:23 AM
#23
Re: Error
Your code is very hard to follow without proper indenting...
Sep 22nd, 2007, 05:27 AM
#24
Thread Starter
Frenzied Member
Re: Error
Im sorry about that are you able to help with the deleteing from the file.
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
Sep 22nd, 2007, 05:36 AM
#25
Re: Error
It deletes here... Why do you think it does not get marked as delete?
You are also doing some very bad usage of file handles
Use
Code:
Dim fNum as Integer
fNum = FreeFile
to get your file handle "NEVER" hardcode the file handle... IE #1
Sep 22nd, 2007, 08:00 AM
#26
Thread Starter
Frenzied Member
Re: Error
How do i add this in to my program?
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
Sep 22nd, 2007, 02:28 PM
#27
Re: Error
You do that everywhere you open a file...
Code:
Dim fNum as Integer
fNum = FreeFile
Open yourfilename for random as #fnum
Sep 22nd, 2007, 02:58 PM
#28
Thread Starter
Frenzied Member
Re: Error
Like
vb Code:
Dim fNum as Integer
fNum = FreeFile
Open "\members.dat" for random as #fNum
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
Sep 22nd, 2007, 03:04 PM
#29
Re: Error
Yes, but I would refrain from using the actual filename there. I would use a variable and define the filename as a constant. This way if the filename should change or the location you won't have to change it several times in your app. IE...
Code:
Public Const sMemberFile = "\members.dat" ' This is declared in a module
And in your forms and/or other modules something like
Code:
Private Sub AddMember()
Dim fNum as Integer
fNum = FreeFile
Open App.Path & sMemberFile for random as #fnum
...
Close Fnum
End Sub
Sep 22nd, 2007, 03:18 PM
#30
Thread Starter
Frenzied Member
Re: Error
Can you add it to the modules and forms for me please so i can see what u mean?
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
Sep 22nd, 2007, 03:21 PM
#31
Re: Error
It is straight forward...
Sep 22nd, 2007, 03:24 PM
#32
Thread Starter
Frenzied Member
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
Sep 22nd, 2007, 03:25 PM
#33
Re: Error
I have my own work to do... You will have to at least attempt.
Sep 22nd, 2007, 03:27 PM
#34
Thread Starter
Frenzied Member
Re: Error
So do i add my other code underneath this code?. I'll get back to you later if i come across errors.
Thanks
vb code Code:
Private Sub AddMember()
Dim fNum as Integer
fNum = FreeFile
Open App.Path & sMemberFile for random as #fnum
...
Close Fnum
End Sub
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
Sep 22nd, 2007, 05:20 PM
#35
Thread Starter
Frenzied Member
Re: Error
All i need it to do is delete the text from the text file becouse the program deletes it from the file and the program dosent see it in the notepad. I have attached the code below.
Attached Files
Last edited by Jamie_Garland; Sep 22nd, 2007 at 05:24 PM .
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
Sep 22nd, 2007, 05:23 PM
#36
Re: Error
Did you write this code??? The code is clear what it does. It just marks the record deleted, it doesn't actually remove it from the file.
Sep 22nd, 2007, 05:25 PM
#37
Thread Starter
Frenzied Member
Re: Error
Yeah i need it to delete from the file if possible.
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
Sep 22nd, 2007, 05:28 PM
#38
Re: Error
Then you will have to read thru the file and write a new file and just do not include the record in question.
Sep 22nd, 2007, 05:33 PM
#39
Thread Starter
Frenzied Member
Re: Error
I think ill keep it the way ive got it actually.
Another thing I have done some code an dit dosent seem to want to copy the files can you help me please.?
vb Code:
Option Explicit
Private Sub cmdOK_Click()
Dim Index As Integer
Dim OptionChoice As Integer
For Index = 1 To 4
If optUtilities(Index).Value = True Then
OptionChoice = Index
End If
Next Index
Select Case OptionChoice
Case 1
Call BackupGamesFiles
Case 2
Call BackupMembersFile
Case 3
Call CreateCurrentGamesFile
Case 4
Call ChangeCostOfGame
End Select
End Sub
Private Sub optUtilities_Click(Index As Integer)
If Index = 4 Then
fraCosts.Visible = True
lblHelp.Visible = True
End If
End Sub
Public Sub BackupGamesFiles()
Dim Source1 As String
Dim Source2 As String
Dim Destination1 As String
Dim Destination2 As String
Source1 = App.Path & "\CurrentGames.dat"
Destination1 = "\CurrentGames.dat"
FileCopy Source1, Destination1
Source2 = App.Path & "\DailyGames.dat"
Destination2 = "\Dailygames.dat"
FileCopy Source2, Destination2
End Sub
Public Sub BackupMembersFile()
Dim Source As String
Dim Destination As String
Source = App.Path & "\Members.dat"
Destination = "\Members.dat"
FileCopy Source, Destination
End Sub
Public Sub CreateCurrentGamesFile()
Dim OneGame As GameType
Dim TableNumber As Integer
Open App.Path & "\CurrentGames.dat" For Random As #1 Len = Len(OneGame)
For TableNumber = 1 To MaxTables
OneGame.MembersID = ""
OneGame.TableID = TableNumber
OneGame.Occupied = "N"
Put #1, TableNumber, OneGame
Next TableNumber
Close #1
End Sub
Public Sub ChangeCostOfGame()
Dim FileName As String
Dim SeniorCost As String
Dim JuniorCost As String
SeniorCost = txtSeniorCost.Text
JuniorCost = txtJuniorCost.Text
If (Not IsNumeric(SeniorCost)) Or (Not IsNumeric(JuniorCost)) Then
MsgBox ("One or both of the rates are not numbers. Please re-enter")
Else
FileName = App.Path & "\Costs.txt"
Open FileName For Output As #1
Print #1, SeniorCost, JuniorCost
Close #1
End If
End Sub
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
Sep 22nd, 2007, 05:39 PM
#40
Re: Error
Didn't seem to???? Exactly what happened and where. You do have to debug the code... at least give a clue to a specific place are or aren't happening.
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width