Jump to content

Recommended Posts

Posted

Hello! I have a "syntax error" but I can't understand where is it. Can you help me with this?

There is two text files. I want to write three lines of the first file in each line of the second file. Then, if the first file has 600 lines, the second file should have 200 lines.

I hope I have explained well what I want.

#include <File.au3>
Local $sFile1
$sFile1 = "File1.txt"
Local $sFile2
$sFile2 = "File2.txt"
Local $sThreeLinesIntoOne
FileOpen($sFile1,0)
FileOpen($sFile2,2)
For $i In ( _FileCountLines($sFile1) / 3 )
   For $a = ( ( $i - 1 ) * 3 ) + 1 ) To ( $i * 3 )
   $sThreeLinesIntoOne = $sThreeLinesIntoOne & FileReadLine($sFile1, $a)
   Next
FileWriteLine($sFile2, $sThreeLinesIntoOne)
Next
FileClose($sFile2)
FileClose($sFile1)

AutoIt returns:

  Quote

error: syntax error
For $a = ( ( $i - 1 ) * 3 ) + 1 )

 

Posted

You missed an opening parentheses

For $a = ((( $i - 1 ) * 3 ) + 1 ) To ( $i * 3 )

 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

  Reveal hidden contents

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted (edited)
  On 10/26/2015 at 11:19 PM, BrewManNH said:

You missed an opening parentheses

For $a = ((( $i - 1 ) * 3 ) + 1 ) To ( $i * 3 )

 

hahaha I was thinking that the error should be a tiny mistake... but my brain is out for today haha Thanks!

But now I have another error:

  Quote

Variable must be of type "Object".:
For $i In ( ( _FileCountLines($sFile1) )  / 3 )

 

Edited by Rhazz
add text
Posted

I didn't found the solution... and today I'm going to get crazy... sorry for my questions >.<

  Quote

Variable must be of type "Object".:
For $i In ( (_FileCountLines($sFile1))  / 3 )
For $i In ( (_FileCountLines($sFile1))  / 3 )^ ERROR

Posted

Did you read HelpFIle TWICE , or more times ?
Why you are using   "For .. in ... next"    for   normal loop ?

 

btw.
your expression:

( (_FileCountLines($sFile1))  / 3 )

again missed one opening bracket.

( ((_FileCountLines($sFile1))  / 3 )

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 10/27/2015 at 7:26 AM, mLipok said:

Did you read HelpFIle TWICE , or more times ?
Why you are using   "For .. in ... next"    for   normal loop ?

 

btw.
your expression:

( (_FileCountLines($sFile1))  / 3 )

again missed one opening bracket.

( ((_FileCountLines($sFile1))  / 3 )

 

No, I didn't forget a parenthesis. You placed in your code four opening parentheses and three closing parentheses.

And yes, I have read the help file but I'm newbie on AutoIT, and I'm here to learn and improve my programing skill.

I haven't understood why it's wrong to use a "for" loop in my code, sorry!

  • Moderators
Posted (edited)

Rhazz,

As explained in the Help file, you should only use the "For...In...Next" type of loop when dealing with a collection (an Object or an Array). In this case you are using an integer - and so you get an error, again explained in the Help file. Do it like this:

For $i = 1 To (_FileCountLines($sFile1) / 3 )

as the "For...To...Next" loop expects number bounds.

M23

Edited by Melba23
Typo

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted
  On 10/27/2015 at 7:26 AM, mLipok said:

btw.
your expression:

( (_FileCountLines($sFile1))  / 3 )

again missed one opening bracket.

( ((_FileCountLines($sFile1))  / 3 )

 

oops.. :mad2:

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 10/27/2015 at 4:10 PM, Melba23 said:

Rhazz,

As explained in the Help file, you should only use the "For...In...Next" type of loop when dealing with a collection (an Object or an Array). In this case you are using an integer - and so you get an error, again explained in the Help file. Do it like this:

For $i = 1 To (_FileCountLines($sFile1) / 3 )

as the "For...To...Next" loop expects number bounds.

M23

Yes, I had misunderstood that part :s

With "For...To..Next" it works, thanks!

I'm reading the Help File for all of the things that I want to do haha and sometimes I make stupid mistakes xD

Posted

We learn from mistakes
It is a pity that often on their own :)

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

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
×
×
  • Create New...