Qousio Posted May 9, 2009 Share Posted May 9, 2009 (edited) Hello. I'm just transfering some of my old Pascal programs into Autoit (Want to make some pretty GUI's) And allot of them have something to do with importing/exporting arrays. For example, Bubble sorting (Yeah I know Shells and Hoars algorithm is better, just testing) Func Sort() _FileReadToArray(@ScriptDir & "\test.txt", $A) $Loop = $A[0] $I=2; {Шаг поиска} While $I<=$Loop;{Пока шаг поиска меньше кол-ва элементов массива} $J=$Loop; {Максимальный номер массива} While $J>=$I;{Пока номер элемента больше шага} If $A[$J-1]>$A[$J] then;{И Предыдущий элемент больше следующего} $X=$A[$J-1]; {Помещаем элемент в X} $A[$J-1]=$A[$J]; {Меняем местами элементы} $A[$J]=$X; EndIf; {/If} $J=$J-1; {Исключаем отсортированный элемент из поиска} WEnd; {/While} $I=$I+1; {Увеличиваем шаг поиска} WEnd; {/While} _FileWriteFromArray(@ScriptDir & "\Sorted.txt", $A, 1) EndFunc This 4 3 4 3 4 3 4 34 2 2 3 2 3 4 2 3 4 23 4 3 2 3 4 3 2 Gets sorted into this: 2 2 2 2 2 2 23 3 3 3 3 3 3 3 3 3 34 4 4 4 4 4 4 4 4 I tried this with lots of numbers, and the only numbers it sorts correctly are 0-9 numbers. So I figured FileReadToArray stores all information as strings or chars. Is it possible to store it as Integer? I figured this was asked before, but couldn't find it while searching.... Edited May 9, 2009 by Qousio Link to comment Share on other sites More sharing options...
Yashied Posted May 9, 2009 Share Posted May 9, 2009 Ты можешь использовать функцию Int().TRANSLATE: You can use the Int() function. My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 9, 2009 Moderators Share Posted May 9, 2009 Func _ArraySortNum(ByRef $n_array, $i_descending = 0, $i_start = 1) For $i_count = $i_start To UBound($n_array) - 2 Local $i_se = $i_count If $i_descending Then For $x_count = $i_count To UBound($n_array) - 1 If Number($n_array[$i_se]) < Number($n_array[$x_count]) Then $i_se = $x_count Next Else For $x_count = $i_count To UBound($n_array) - 1 If Number($n_array[$i_se]) > Number($n_array[$x_count]) Then $i_se = $x_count Next EndIf Local $i_hld = $n_array[$i_count] $n_array[$i_count] = $n_array[$i_se] $n_array[$i_se] = $i_hld Next EndFunc Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Qousio Posted May 9, 2009 Author Share Posted May 9, 2009 Ты можешь использовать функцию Int(). Спасибо за совет! Всё работает Я думал в Аутоит нельзя обьявлять типы. Func _ArraySortNum(ByRef $n_array, $i_descending = 0, $i_start = 1) For $i_count = $i_start To UBound($n_array) - 2 Local $i_se = $i_count If $i_descending Then For $x_count = $i_count To UBound($n_array) - 1 If Number($n_array[$i_se]) < Number($n_array[$x_count]) Then $i_se = $x_count Next Else For $x_count = $i_count To UBound($n_array) - 1 If Number($n_array[$i_se]) > Number($n_array[$x_count]) Then $i_se = $x_count Next EndIf Local $i_hld = $n_array[$i_count] $n_array[$i_count] = $n_array[$i_se] $n_array[$i_se] = $i_hld Next EndFunc Excuse me, but that doesnt have anything to do with FileReadToArray Anyhow, Yashied's advice solved my problem. Thank you! Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 9, 2009 Moderators Share Posted May 9, 2009 Excuse me, but that doesnt have anything to do with FileReadToArray No kidding, I was showing you how to sort with numbers. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Yashied Posted May 9, 2009 Share Posted May 9, 2009 Func _ArraySortNum(ByRef $n_array, $i_descending = 0, $i_start = 1) For $i_count = $i_start To UBound($n_array) - 2 Local $i_se = $i_count If $i_descending Then For $x_count = $i_count To UBound($n_array) - 1 If Number($n_array[$i_se]) < Number($n_array[$x_count]) Then $i_se = $x_count Next Else For $x_count = $i_count To UBound($n_array) - 1 If Number($n_array[$i_se]) > Number($n_array[$x_count]) Then $i_se = $x_count Next EndIf Local $i_hld = $n_array[$i_count] $n_array[$i_count] = $n_array[$i_se] $n_array[$i_se] = $i_hld Next EndFuncOr use this function before sorting. Perhaps it will be faster. Func _ArrayConvert(ByRef $Array) For $i = 1 To $Array[0] $Array[$i] = Int($Array[$i]) Next EndFunc; _ArrayConvert My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
GEOSoft Posted May 9, 2009 Share Posted May 9, 2009 Спасибо за совет! Всё работает Я думал в Аутоит нельзя обьявлять типы.Excuse me, but that doesnt have anything to do with FileReadToArray Anyhow, Yashied's advice solved my problem.Thank you!Excuse me but if you had checked the function SmOke_N gave you then you might have noticed that passing the array created by _FileReadToArray() to the function would have sorted the origional array as integers. 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!" Link to comment Share on other sites More sharing options...
Qousio Posted May 9, 2009 Author Share Posted May 9, 2009 (edited) No kidding, I was showing you how to sort with numbers.Oh, thanks!Its just 2 am and my brain is completely focused on other things.... Thanks again. Edited May 9, 2009 by Qousio Link to comment Share on other sites More sharing options...
MrCreatoR Posted May 9, 2009 Share Posted May 9, 2009 (edited) Func _ArraySortNum(ByRef $n_array, $i_descending = 0, $i_start = 1) For $i_count = $i_start To UBound($n_array) - 2 Local $i_se = $i_count If $i_descending Then For $x_count = $i_count To UBound($n_array) - 1 If Number($n_array[$i_se]) < Number($n_array[$x_count]) Then $i_se = $x_count Next Else For $x_count = $i_count To UBound($n_array) - 1 If Number($n_array[$i_se]) > Number($n_array[$x_count]) Then $i_se = $x_count Next EndIf Local $i_hld = $n_array[$i_count] $n_array[$i_count] = $n_array[$i_se] $n_array[$i_se] = $i_hld Next EndFunc Nice! Could be an UDF for File.au3 include; _FileSortNumLines (or something )... #include <File.au3> _FileSortNumLines(@ScriptDir & "\Sort.txt") Func _FileSortNumLines($sSrc_File, $sDest_File = $sSrc_File, $iDescending = 0, $iStart = 1) Local $avArray, $iRet _FileReadToArray($sSrc_File, $avArray) If @error Then Return SetError(@error, 0, 0) ;Func __ArraySortNums(ByRef $avArray, $i_descending = 0, $iStart = 1) Local $iSE, $iHold For $iCount = $iStart To UBound($avArray) - 2 $iSE = $iCount For $xCount = $iCount To UBound($avArray) - 1 If ($iDescending And Number($avArray[$iSE]) < Number($avArray[$xCount])) Or _ (Not $iDescending And Number($avArray[$iSE]) > Number($avArray[$xCount])) Then $iSE = $xCount Next $iHold = $avArray[$iCount] $avArray[$iCount] = $avArray[$iSE] $avArray[$iSE] = $iHold Next ;EndFunc ;__ArraySortNums $iRet = _FileWriteFromArray($sDest_File, $avArray, 1) SetError(@error, 0, $iRet) EndFunc And afaik, we don't have a simple _FileSortLines function as well... Edited May 9, 2009 by MrCreatoR Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
kittykat Posted May 11, 2009 Share Posted May 11, 2009 this is interesting. thank you for sharing simulation rachat de credit 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