Results 1 to 3 of 3

Thread: Files Help (PLEASE HELP VERY VERY URGENT)

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2005
    Location
    Toronto, Canada
    Posts
    357

    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...

    DONT MIND THE COMMENTS... THE AREN'T RELATED

    VB Code:
    1. Private Sub cmdDelete_Click()
    2.         strName = ""
    3.         strCompany = ""
    4.         strMobile = ""
    5.         strHome = ""
    6.         strAddress = ""
    7.         strEmail = ""
    8.         Dim strWName() As String
    9.         Dim strWHome() As String
    10.         Dim strWMobile() As String
    11.         Dim strWCompany() As String
    12.         Dim strWEmail() As String
    13.         Dim strWAddress() As String
    14.         Dim intCount As Integer
    15.         Dim strNCheck As String
    16.         strNCheck = cboTitle.Text
    17.         ' If all the data is in correct format, then writes to the file
    18.         Dim intFile As Integer
    19.         Dim intArray As Integer
    20.         intFile = FreeFile
    21.         Dim strPath As String
    22.         strPath = App.Path & "\Books1.appt"
    23.         ' Opens the original file and inputs all the data same as lblDayNum_Click(Index As Integer) except all data _
    24.         is inputted
    25.         Open strPath For Input Lock Write As #intFile
    26.             Do While Not EOF(intFile)
    27.             Input #intFile, strName, strHome, strMobile, strCompany, strEmail, strAddress
    28.                 If strName <> strNCheck Then
    29.                         MsgBox strName
    30.                                 intArray = intArray + 1
    31.                                 If intArray = 1 Then
    32.                                     ReDim strWName(1) As String
    33.                                     ReDim strWHome(1) As String
    34.                                     ReDim intWMobile(1) As String
    35.                                     ReDim intWCompany(1) As String
    36.                                     ReDim intWEmail(1) As String
    37.                                     ReDim intWAddress(1) As String
    38.                                 Else
    39.                                     ReDim strWName(intArray) As String
    40.                                     ReDim strWHome(intArray) As String
    41.                                     ReDim intWMobile(intArray) As String
    42.                                     ReDim intWCompany(intArray) As String
    43.                                     ReDim intWEmail(intArray) As String
    44.                                     ReDim intWAddress(intArray) As String
    45.                                 End If
    46.                                 strWName(intArray) = strName
    47.                                 strWHome(intArray) = strHome
    48.                                 intWMobile(intArray) = strMobile
    49.                                 intWCompany(intArray) = strCompany
    50.                                 intWEmail(intArray) = strEmail
    51.                                 intWAddress(intArray) = strAddress
    52.                     End If
    53.             Loop
    54.         Close #intFile
    55.         intFile = FreeFile
    56.         ' Opens a temporary file
    57.         Open "temps.appt" For Output As #intFile
    58.             For intCount = 1 To intArray
    59.                 If strName = strNCheck Then
    60.                     Write #intFile, strName, strHome, strMobile, strCompany, strEmail, strAddress
    61.                 End If
    62.             Next intCount
    63.         ' Deletes the original file and renames the temporary file as the original file
    64.         Kill strPath
    65.         On Error Resume Next
    66.         Kill "Books1.appt"
    67.         Close #intFile
    68.         Name "temps.appt" As "Books1.appt"
    69.     cboTitle.Text = ""
    70.     txtMobile.Text = ""
    71.     txtHome.Text = ""
    72.     txtEmail.Text = ""
    73.     txtAddress.Text = ""
    74.     txtCompany.Text = ""
    75. End Sub
    Hey... If you found this post helpful please rate it.

  2. #2
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    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...
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width