Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro to go between EXTRA and notepad

Status
Not open for further replies.

MikeB1986

IS-IT--Management
Aug 1, 2012
1
US
Hello everyone,
First I would like to thank everyone in advance. Now onto my question. I work in the I.T. Dept of a large company, and we use attachmate extra xtreme for our backend. What I would like is a macro that could jump from extra to notepad, copy a line of text, delete the text it copied, delete the blank space it left so the next line will take its position, then jump back into extra. I know it would be better with pretty much anything other than notepad, but it was made very clear to me that I can only use what is on the PC. Also the file being native to notepad makes it easier anyways. I already have a macro that will run the rest. I just need one that will do what was previously requested. Also if it is any help the line in the notepad that will be copid is 14 characters long. Again I appreciate any help or advice on this. Thank you.
 
I'm sure there is a better way to do it, but this function takes a line number as input and returns the extracted line.

Code:
Declare Function extractline(lineNumber)

Function extractline(lineNumber)

    filename = "<filename>"

    OPEN filename For Input As #1
    
    Dim i as integer
    
    i = 0
    
'Count the number of lines
    Do while EOF(1) <> True
        Input #1, txtline
        i = i + 1
    Loop
    
    CLOSE
    
    If i < lineNumber Then
        Exit function
    End If
    
'Copy the lines into a list
    OPEN filename For Input As #1
    
    Dim lines() as String
    reDim lines(i)
    
    For j = 1 To i
        Input #1, lines(j)
    Next
    
    CLOSE
    
'Rewrite the file without the line needed
    OPEN filename For Output As #1
    
    For j = 1 To i
        If j <> lineNumber Then
            Print #1, lines(j)
        End If
    Next
    
    CLOSE
    
'Return the line extracted
    extractline = lines(lineNumber)
    
End Function

I need to copy the entire file and rewrite it because I don't know if it is possible to edit inside a txt-file.

Hope it helps.
Lakare
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top