Jump to content
Sign in to follow this  
yucatan

Fileread?

Recommended Posts

yucatan

hi i wanne make a script thats read a notepad document and if on the first rule is "" then ........ else .......

how do i need to make it i cant figure it out:S

help me pleas

Share this post


Link to post
Share on other sites
YellowLab

Dude, if you keep asking for people to write your scripts you won't learn. Read the help files, read the FAQs on this site and try a couple of things. This is like your third post asking for people to do your work for you.


You can't see a rainbow without first experiencing the rain.

Share this post


Link to post
Share on other sites
Jos

hi i wanne make a script thats read a notepad document and if on the first rule is "" then ........ else .......

how do i need to make it i cant figure it out:S

help me pleas

zucht, wat was er zo moeilijk aan mijn antwoord in een van je vele vorige vragen.

Stop met het afvuren van nieuwe vragen totdat je ZELF eerst een poging doet om het ZELF te maken.

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
yucatan

hi i'm trying to read a file and then compare it can somebody tell me what i'm doing wrong?

$file = FileOpen("test.txt", 0)

; Check if file opened for reading OK

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

$chars = FileRead($file, 1)

If StringinStr($chars,"test") = 1

Then msgBox(4096, "ERREUR!", "er staat test")

Else msgBox(4096, "ERREUR!", "anders")

EndIf

Share this post


Link to post
Share on other sites
yucatan

hmm i dont know why jos is whining again but i did try it and i did searched but i realy cant find it i thout that a forum is for when you haveing problems with things....

Share this post


Link to post
Share on other sites
yucatan

hi can somebody tell me why i get error's what i'm doing wrong in string compare?

$file = FileOpen("test.txt", 0)

; Check if file opened for reading OK

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

$chars = FileRead($file, 1)

if StringCompare ("$chars", "test" [, 0]) = 0 Then

MsgBox(0, "er staat test")

Else

MsgBox(0, "anders")

EndIf

Share this post


Link to post
Share on other sites
Richard Robertson

"test" [, 0]

What is that supposed to be? That's not valid syntax.

Oh, and you don't access variables by using the name in strings. You would read the value of $chars by just using $chars, not "$chars".

Edited by Richard Robertson

Share this post


Link to post
Share on other sites
Jos

hmm i dont know why jos is whining again but i did try it and i did searched but i realy cant find it i thout that a forum is for when you haveing problems with things....

I am not and if you would have bothered to look at the details you could have concluded that I merged the 2 Threads.

So next time think before making stupid smart remarks.


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Jos

OK, now I am going to do a bit more whining:

Stop creating new topic about the same issue!

Next time they will be simply locked.

I have merged them again.

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
GEOSoft

When you see the square bracket used in the help file it indicates an option. They should not be included in the line.

if StringCompare ($chars, "test" , 0) = 0

In the case of StringCompare, 0 is the default so it's not required at all. The line above is the same as

if StringCompare ($chars, "test") = 0

On top of all that I have a hunch that what you are looking for is more along the lines of StringInStr()

If StringInStr($chars, "test") Then


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
yucatan

hi

i have tryid it with If StringInStr($chars, "test") Then but when i use Else then i get syntax error's why is that

and he always say there is not standing test but i'm sure that in that document is writen test.... how is this possebel ?

FileChangeDir (@DesktopDir)

$file = FileOpen("test.bat", 0)

$chars = FileRead($file, 1)

if StringCompare ($chars, "test") = 0 Then MsgBox(0, "Error", "er staat test")

this is the code now

i'm sure that in test.bat is standing test but it dont say er staat test

why it dont work i just am searching and searching i cant find it:(

Edited by yucatan

Share this post


Link to post
Share on other sites
MHz

You cannot put statements on the same line as "Else" as to why you are getting a syntax error.

This example may help you to understand.

; Check that working directory changes to @DesktopDir
If FileChangeDir(@DesktopDir) Then
    ; Open a file handle for read
    $handle = FileOpen('test.bat', 0)
    ; Check if the handle is valid
    If $handle <> -1 Then
        ; Read the complete file
        $text = FileRead($handle)
        ; Find "test" with $text
        if StringInStr($text, "test") Then
            ; Show Msgbox if StringInStr returns not 0
            MsgBox(0, '', '"test" found')
        Else
            ; Show Msgbox if StringInStr returns 0
            MsgBox(0, '', '"test" not found')
        EndIf
        ; Close the file handle
        FileClose($handle)
    EndIf
EndIf

Have a look in the help file contents for "If...ElseIf...Else...EndIf" for syntax that is valid.

:D

Share this post


Link to post
Share on other sites
Swift

And like he said. Use

or
tags please.

Example:

Using code:  [Code]

Now watch:

Hey...

And AutoIt:
[AutoIt]Hey!

Share this post


Link to post
Share on other sites
therks

Swift, I have a feeling your post didn't come out quite like you intended it to.

For anyone, if you ever want to show someone how to use the [code] or [autoit] tags, just put an empty bold (or strike, italics, etc) tag inside the tag, like this: [[b][/b]code]. This will print: [code].

Share this post


Link to post
Share on other sites
Brenda1

yoo have to do a loop, for read all the document, it can be like this:

While 1
$LineRead = FileReadLine($file)
            If @error = -1 Then ExitLoop
            $array = StringSplit($LineRead, ";")
            If $Variable = $array[1] then; put the position you want to compare
                                                 [conditions]
                                                  endif

Wend

don't forget to open the file first, in a read mode.

Share this post


Link to post
Share on other sites
GEOSoft

You are aware that FileReadLine() is the slowest possible method of reading a file, are you not? Better to read the file to an array than to do that.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
Brenda1

You are aware that FileReadLine() is the slowest possible method of reading a file, are you not? Better to read the file to an array than to do that.

it is up to the file you want to read...

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×