help..where have i gone wrong in this code?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: help..where have i gone wrong in this code?

  1. #1
    Phil Weber Guest

    Re: help..where have i gone wrong in this code?

    > Dim changedfile As Integer
    > tchangedfile = FreeFile
    > Open "c:\ammended..txt" For Output As changedfile
    > Print #changedfile, changedstring
    > Close changedfile


    Jaffer: Was the code you posted cut-and-pasted from your application? If so,
    the problem may be that your output file handle is named "changedfile", but
    you're assigning the result of FreeFile to a variable named "tchangedfile".
    Also, I'm not sure what effect, if any, having two periods in the file name
    "c:\ammended..txt" might have.

    A couple of suggestions: make sure you have "Option Explicit" specified at
    the top of your module; this will catch any errors caused by misspelled
    variable names. Also, when you post code to a newsgroup, always
    cut-and-paste actual code from your project, to eliminate the possibility of
    transcription errors.
    ---
    Phil Weber



  2. #2
    jaffer Guest

    help..where have i gone wrong in this code?

    hi,
    I am trying to create a code that will edit a line in my text file. The
    logic i have used it to get the whole file in a string, use replace to make
    the changes to the point which i want to edit. The changes then are stored
    in a new string, which uses output to another file. I have written the code,
    but need your help, coz the changed string is not gettting written in the
    file..here is the code..

    Dim FF As Long
    Dim Quote1 As Long
    Dim Quote2 As Long
    Dim Position As Long
    Static FileContents As String


    FF = FreeFile
    Open "c:\original.txt" For Input As #FF
    FileContents = vbNewLine & Input(LOF(FF), #FF)
    Close #FF


    Position = InStr(FileContents, vbNewLine & Text1.Text)
    Quote1 = InStr(Position, FileContents, """")
    Quote2 = InStr(Quote1 + 1, FileContents, vbCrLf)
    linestring = Mid$(FileContents, Quote1, _
    Quote2 - Quote1)
    changedstring = Replace(FileContents, linestring, "GOOGLE")

    Dim changedfile As Integer
    tchangedfile = FreeFile
    Open "c:\ammended..txt" For Output As changedfile
    Print #changedfile, changedstring
    Close changedfile

    Any idea why wouldnt the file ammended.txt be created?..its not giving me
    any errors as well.....The file original.txt is in the folowing format

    abc password="abc", lastname = "xyz"
    jay password="txw" lastname="donald"

    The string linestring containts each line in the file.

    Any idea, pls help...thanks!




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center