face Posted January 20, 2014 Share Posted January 20, 2014 (edited) i have a script that multiplies by 3 a single column of numbers (50) in a text file. how can i make it multiply 5+ columns at the same time (in 1 file) exatly as when it multiplies 1 column? its set to multiply by 3(+1) every 50 rows. it gives an error message but it still does the multiplying. #include <File.au3> $file = @DesktopDir & "temp.txt" $file_output = @DesktopDir & "output.txt" Local $array[1] _FileReadToArray($file,$array) _FileCreate($file_output) $hOutput = FileOpen($file_output,2) $iMultiplier = 3 $iCounter = 1 While True For $i = 1 To 50 FileWriteLine($hOutput, $array[$iCounter] * $iMultiplier) $iCounter += 1 Next $iMultiplier += 3 WEnd FileClose($hOutput) temp.txt Edited January 20, 2014 by face Link to comment Share on other sites More sharing options...
BrewManNH Posted January 20, 2014 Share Posted January 20, 2014 FileReadToArray only creates a 1D array, there's no columns, so you won't be able to do what you want to do. You'd need to loop through the array, one row at a time, and StringSplit the row to get the columns of numbers. Then loop through THAT array to do the actual multiplication. Something like this might do the trick, although you lost me when you mentioned adding 3 to the multiplier, I'll leave that part to you because I have no clue what you meant. #include <File.au3> $file = @DesktopDir & "\temp.txt" $file_output = @DesktopDir & "\output.txt" Local $array[1] _FileReadToArray($file, $array) ;~ _FileCreate($file_output) <<<<<<<<<<< not needed for this because the next line will do the same thing $hOutput = FileOpen($file_output, 2) $iMultiplier = 3 Global $aTemp, $Text For $i = 1 To $array[0] $aTemp = StringSplit($array[$i], @TAB) $text = "" For $j = 1 To $aTemp[0] $text &= $aTemp[$j] * $iMultiplier & @TAB Next $text = StringTrimRight($text, 1) FileWriteLine($hOutput, $text) Next FileClose($hOutput) 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 GudeHow to ask questions the smart way! 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 Link to comment Share on other sites More sharing options...
face Posted January 20, 2014 Author Share Posted January 20, 2014 FileReadToArray only creates a 1D array, there's no columns, so you won't be able to do what you want to do. You'd need to loop through the array, one row at a time, and StringSplit the row to get the columns of numbers. Then loop through THAT array to do the actual multiplication. Something like this might do the trick, although you lost me when you mentioned adding 3 to the multiplier, I'll leave that part to you because I have no clue what you meant. #include <File.au3> $file = @DesktopDir & "\temp.txt" $file_output = @DesktopDir & "\output.txt" Local $array[1] _FileReadToArray($file, $array) ;~ _FileCreate($file_output) <<<<<<<<<<< not needed for this because the next line will do the same thing $hOutput = FileOpen($file_output, 2) $iMultiplier = 3 Global $aTemp, $Text For $i = 1 To $array[0] $aTemp = StringSplit($array[$i], @TAB) $text = "" For $j = 1 To $aTemp[0] $text &= $aTemp[$j] * $iMultiplier & @TAB Next $text = StringTrimRight($text, 1) FileWriteLine($hOutput, $text) Next FileClose($hOutput) thank you, it works well, can it be made to use this part? how can i implement this, i need it to multiply by +1 multiplier every 50 rows For $i = 1 To 50 FileWriteLine($hOutput, $array[$iCounter] * $iMultiplier) $iCounter += 1 Next $iMultiplier += 3 Link to comment Share on other sites More sharing options...
BrewManNH Posted January 20, 2014 Share Posted January 20, 2014 (edited) I wouldn't even think of putting that into any code, it's written completely wrong. What are you adding 3 to $iMultiplier for if you want it to increase by one every 50 rows? Also, lose the $iCounter variable, it's completely unnecessary. This might be closer to what you're trying to achieve. #include <File.au3> $file = @DesktopDir & "\temp.txt" $file_output = @DesktopDir & "\output.txt" Local $array[1] _FileReadToArray($file, $array) $hOutput = FileOpen($file_output, 2) $iMultiplier = 3 Global $aTemp, $Text For $i = 1 To $array[0] $aTemp = StringSplit($array[$i], @TAB) If Not Mod($i, 50) Then $iMultiplier += 1 $text = "" For $j = 1 To $aTemp[0] $text &= $aTemp[$j] * $iMultiplier & @TAB Next $text = StringTrimRight($text, 1) FileWriteLine($hOutput, $text) Next FileClose($hOutput) Edited January 20, 2014 by BrewManNH 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 GudeHow to ask questions the smart way! 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 Link to comment Share on other sites More sharing options...
face Posted January 20, 2014 Author Share Posted January 20, 2014 thanks again Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 20, 2014 Moderators Share Posted January 20, 2014 BrewManNH, FileReadToArray only creates a 1D arrayNot in the latest Beta - that version can return 2D arrays as well. But do please read the "Script-breaking changes" and look at the Help file before using it. M23 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: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
BrewManNH Posted January 20, 2014 Share Posted January 20, 2014 I never assume anyone is using the beta version, I always go on the assumption that they're using the latest production version. If something I post is only available in a beta version, I'll mention it, but assuming anything else only leads to multiple confusing posts further down the line. 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 GudeHow to ask questions the smart way! 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 Link to comment Share on other sites More sharing options...
face Posted January 21, 2014 Author Share Posted January 21, 2014 (edited) how can i make it so it multiplies until a row number If Not Mod($i, 50) Then $iMultiplier += 1 this multiplies every 50 times and adds +1 on the multiplier i want to multiply every 50 times and add +1 on the multiplier until a certain row number like 1000 and then every 60 times and add +1 on the multiplier If Not Mod($i, 60) Then $iMultiplier += 1 Edited January 22, 2014 by face Link to comment Share on other sites More sharing options...
face Posted January 22, 2014 Author Share Posted January 22, 2014 sorry to bump this post i really need this to work Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 22, 2014 Moderators Share Posted January 22, 2014 face,Please do not bump your own threads within 24hrs - it might be urgent to you but it is most certainly not to anyone else. And in addition, i have read this thread at least 3 times and I still have absolutely no idea what you are trying to do. How about you give us a short example of the file as it is and then as you want it to be - that might lift the gloom and allow us to help you. M23 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: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Malkey Posted January 22, 2014 Share Posted January 22, 2014 (edited) I am really not sure whether I am anywhere near what you want with this example. You may be able to adapt this example to what you want. expandcollapse popupLocal $sFilePath = @ScriptDir & "\temp1.txt" Local $sOutputFilePath = @ScriptDir & "\Output.txt" Local $iLimit = 50 ; Wanted 50. Use 2 for testing. <---------------- CHANGE --------------------- Local $EOF = 1, $iCounter = 0 Local $iMultiplier = 0 Local $sText, $sOutText Local $hFileOpen = FileOpen($sFilePath) If FileExists($sOutputFilePath) Then FileDelete($sOutputFilePath) Local $hFileOutput = FileOpen($sOutputFilePath, 1) While $EOF $sText = "" ; Initialize $sText for each While...WEnd loop. For $i = 1 To $iLimit $sText &= FileReadLine($hFileOpen) & @CRLF If @error = -1 Then $EOF = 0 ExitLoop ; Exit For..Next loop EndIf $iCounter += 1 Next $iMultiplier += 3 If $iCounter >= 1000 Then ; Wanted 1000. Use 50 for testing. <-------------- CHANGE --- $iMultiplier = 3 ; Initialize $iMultiplier after 1000 lines $iCounter = 0 ; Initialize counter $iLimit += 10 ; Wanted 10 so that 50+10 = 60. Use 1 for testing. <--------- CHANGE --- EndIf ; Multiply all columns x $iMultiplier. The number of rows at a time is in $iLimit. Local $sNew = StringRegExpReplace($sText, "(\d+)(\D+)(\d+)(\D+)(\d+)(\D+)(\d+)(\D+)(\d+)(\D+)(\d+)(\v*)", _ "(" & $iMultiplier & " * ${1}) & '${2} '& " & _ ; Column 1 "(" & $iMultiplier & " * ${3}) & '${4} '& " & _ ; Column 2 "(" & $iMultiplier & " * ${5}) & '${6} '& " & _ ; Column 3 "(" & $iMultiplier & " * ${7}) & '${8} '& " & _ ; Column 4 "(" & $iMultiplier & " * ${9}) & '${10} '& " & _ ; Column 5 "(" & $iMultiplier & " * ${11}) & @CRLF & ") ; Column 6 $sOutText = Execute(StringTrimRight($sNew, 3)) FileWrite($hFileOutput, $sOutText) ;ConsoleWrite($sNew & @LF) ;ConsoleWrite("----------------------------------------------" & @LF) ;ConsoleWrite($sOutText) WEnd FileClose($hFileOpen) FileClose($hFileOutput) Edited January 22, 2014 by Malkey Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now