Files Help (PLEASE HELP VERY VERY URGENT)
Hi guys, I am using this piece of code to delete an entry from a file. The .appt extension is just there for the fun of it.... they are all just text files... However, for some reason, the file is not renamed at the end... any clue... Like... I open Books1 and a temp file... I copy the needed entries to the temp file and at the end I rename the temp file... However for some weird reason it doesn't happen and there is not file at the end... the files are all deleted... ANY CLUE??? I REALLY NEED HELP ASAP... I was just doing some last minute debugging and this issue came up... :confused:
DONT MIND THE COMMENTS... THE AREN'T RELATED
VB Code:
Private Sub cmdDelete_Click()
strName = ""
strCompany = ""
strMobile = ""
strHome = ""
strAddress = ""
strEmail = ""
Dim strWName() As String
Dim strWHome() As String
Dim strWMobile() As String
Dim strWCompany() As String
Dim strWEmail() As String
Dim strWAddress() As String
Dim intCount As Integer
Dim strNCheck As String
strNCheck = cboTitle.Text
' If all the data is in correct format, then writes to the file
Dim intFile As Integer
Dim intArray As Integer
intFile = FreeFile
Dim strPath As String
strPath = App.Path & "\Books1.appt"
' Opens the original file and inputs all the data same as lblDayNum_Click(Index As Integer) except all data _
is inputted
Open strPath For Input Lock Write As #intFile
Do While Not EOF(intFile)
Input #intFile, strName, strHome, strMobile, strCompany, strEmail, strAddress
If strName <> strNCheck Then
MsgBox strName
intArray = intArray + 1
If intArray = 1 Then
ReDim strWName(1) As String
ReDim strWHome(1) As String
ReDim intWMobile(1) As String
ReDim intWCompany(1) As String
ReDim intWEmail(1) As String
ReDim intWAddress(1) As String
Else
ReDim strWName(intArray) As String
ReDim strWHome(intArray) As String
ReDim intWMobile(intArray) As String
ReDim intWCompany(intArray) As String
ReDim intWEmail(intArray) As String
ReDim intWAddress(intArray) As String
End If
strWName(intArray) = strName
strWHome(intArray) = strHome
intWMobile(intArray) = strMobile
intWCompany(intArray) = strCompany
intWEmail(intArray) = strEmail
intWAddress(intArray) = strAddress
End If
Loop
Close #intFile
intFile = FreeFile
' Opens a temporary file
Open "temps.appt" For Output As #intFile
For intCount = 1 To intArray
If strName = strNCheck Then
Write #intFile, strName, strHome, strMobile, strCompany, strEmail, strAddress
End If
Next intCount
' Deletes the original file and renames the temporary file as the original file
Kill strPath
On Error Resume Next
Kill "Books1.appt"
Close #intFile
Name "temps.appt" As "Books1.appt"
cboTitle.Text = ""
txtMobile.Text = ""
txtHome.Text = ""
txtEmail.Text = ""
txtAddress.Text = ""
txtCompany.Text = ""
End Sub
Re: Files Help (PLEASE HELP VERY VERY URGENT)
anyway, please do not use On Error Resume Next in your code, but use an Error handler...
comment the resume next statement and check if you get any errors...
Re: Files Help (PLEASE HELP VERY VERY URGENT)
Unless you use Redim Preserve only the last bit of data you put in the array will be kept. Also unless you are using Option Base 1, all arrays start at (0) and given the other error and the fact that your loops start at 1, you wouldn't see anything.