Jump to content

Recommended Posts

Posted

I want to read from a notepad line

for example if this was a notepas and I want get username6 and password6 how can I do that?

username1 | password1

username2 | password2

username3 | password3

username4 | password4

username5 | password5

username6 | password6

username7 | password7

username8 | password8

Posted

An example:

If WinExists("[Class:Notepad]", "") Then
    Local $Text = ControlGetText("[Class:Notepad]", "", "Edit1")
    Local $iLineNum = 6
    Local $username6 = "username6"
    Local $sLine = StringRegExpReplace($Text, "(\V+\v+){" & ($iLineNum - 1) & "}(\V+)(?s).+$", "\2")
    Local $aLine = StringSplit($sLine, " | ", 3)
    MsgBox(0, "Results", 'Given Line "' & $iLineNum & '";  Gets ' & 'User Name: "' & $aLine[0] & '";   Password: "' & $aLine[1] & '"' & @LF & _
            " Or" & @LF & _
            'Given User Name:  "' & $username6 & '";  Gets Password: "' & StringRegExpReplace($Text, "(?s)(?:.*)" & $username6 & "\h*\|\h*(\V+).+$", "\1") & '"' & @LF)
Else
    MsgBox(0, "Error", "Notepad does not exist")
EndIf
Posted

 

An example:

If WinExists("[Class:Notepad]", "") Then
    Local $Text = ControlGetText("[Class:Notepad]", "", "Edit1")
    Local $iLineNum = 6
    Local $username6 = "username6"
    Local $sLine = StringRegExpReplace($Text, "(\V+\v+){" & ($iLineNum - 1) & "}(\V+)(?s).+$", "\2")
    Local $aLine = StringSplit($sLine, " | ", 3)
    MsgBox(0, "Results", 'Given Line "' & $iLineNum & '";  Gets ' & 'User Name: "' & $aLine[0] & '";   Password: "' & $aLine[1] & '"' & @LF & _
            " Or" & @LF & _
            'Given User Name:  "' & $username6 & '";  Gets Password: "' & StringRegExpReplace($Text, "(?s)(?:.*)" & $username6 & "\h*\|\h*(\V+).+$", "\1") & '"' & @LF)
Else
    MsgBox(0, "Error", "Notepad does not exist")
EndIf

so how do open the notepad file, for example: this is the location: C:Usersname pcDesktopautoitproject

Posted
notepad.exe C:\Users\name pc\Desktop\autoit\project

like this?:

If WinExists("[Class:notepad.exe C:\Users\name pc\Desktop\autoit\project]", "") Then
    Local $Text = ControlGetText("[Class:Notepad]", "", "Edit1")
    Local $iLineNum = 6
    Local $username6 = "username6"
    Local $sLine = StringRegExpReplace($Text, "(\V+\v+){" & ($iLineNum - 1) & "}(\V+)(?s).+$", "\2")
    Local $aLine = StringSplit($sLine, " | ", 3)
    MsgBox(0, "Results", 'Given Line "' & $iLineNum & '";  Gets ' & 'User Name: "' & $aLine[0] & '";   Password: "' & $aLine[1] & '"' & @LF & _
            " Or" & @LF & _
            'Given User Name:  "' & $username6 & '";  Gets Password: "' & StringRegExpReplace($Text, "(?s)(?:.*)" & $username6 & "\h*\|\h*(\V+).+$", "\1") & '"' & @LF)
Else
    MsgBox(0, "Error", "Notepad does not exist")
EndIf
Posted

Hello Arclite,

It sounds like you want to read from a text file, not from Notepad itself.  In which case, you don't need to open Notepad, or refer to any windows.

Instead, have a look at FileReadLine.  Once you have a grip on that, check out StringSplit or even _FileReadToArray in order to achieve what you're trying to do.

I could write the function for you, but it would be better if you studied the help file and learned how to use this tool for yourself.

Best of luck,

Val.

  • 1 month later...
Posted

Sry for everyone and sry for the original topic maker (Arclite86), but i do not wanted to make a new topic for my question, cause it is similar for this.

My question is, how do i can get how many lines a file have?

I can real lines with FileReadLine it is no problem, but i dont wana get that data. For this function, i need only the number of lines in the file. I was searching in help file, but i could not find the solution.

Probably i am just lame, and approach it from wrong direction.

I tried to put it in a loop... but after i made the loop i mess up it with wrong order. :D

So i get back nothing, just errors :)

Sry for my bad English, and double sry, but I am learning AutoIT language by myself. :)

[u]Tricky[/u]

You can't teach a man anything, you can only help him, find it within himself. (Galileo Galilei)

Posted

Ahh forget... I was the lame. Found my solution in another topic.

_FileCountLines

probably what i need. (somehow i did not saw this order in help list)

Lame Tricky :)

Sry for my bad English, and double sry, but I am learning AutoIT language by myself. :)

[u]Tricky[/u]

You can't teach a man anything, you can only help him, find it within himself. (Galileo Galilei)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...