olirav Posted July 20, 2010 Share Posted July 20, 2010 Is it possible to have a variable as part of another variables name? I have a loop that is reading a html file line by line and what I want to have is a new var created for each line. Just have a look: $html = FileOpen("FILE", 0) $CurrentLineNo = 0 If $html = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf While 1 ;Current Line Number increase $CurrentLineNo = $CurrentLineNo + 1 $temp = FileReadLine($html) If @error = -1 Then $CurrentLineNo = $CurrentLineNo - 1 ExitLoop EndIf $TempTest = StringLeft($temp, 11) If $TempTest == "<DT><A HREF" Then $line&$CurrentLineNo = $temp Else $CurrentLineNo = $CurrentLineNo - 1 EndIf Wend So the $line&$CurrentLineNo would be called $line1 for the first one Link to comment Share on other sites More sharing options...
Yoriz Posted July 20, 2010 Share Posted July 20, 2010 Assign Could be what your looking for. Assigns a variable by name with the data. Assign ( "varname", "data" [, flag] ) Parameters 'varname' The name of the variable you wish to assign. Cannot be an array element. 'data' The data you wish to assign to the variable. 'flag' [optional] controls the way that variables are assigned (add required options together): 0 = (default) Create variable if required 1 = Force creation in local scope 2 = Force creation in global scope 4 = Fail if variable does not already exist GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF. Link to comment Share on other sites More sharing options...
olirav Posted July 20, 2010 Author Share Posted July 20, 2010 Assign Could be what your looking for.The "Cannot be an array element." kills that I think, trying anything involving a variable in the name just throws up Assign^ ERROROli Link to comment Share on other sites More sharing options...
KaFu Posted July 20, 2010 Share Posted July 20, 2010 (edited) From a quick look on your code, better stick to an array. Try something like this (untested): #include <array.au3> $hFile = FileOpen("FILE", 0) If $hFile = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf Dim $aLines[1] = [0] While 1 $sFileLine = FileReadLine($hFile) If @error = -1 Then FileClose($hFile) ExitLoop endif If StringLeft($sFileLine, 11) = "<DT><A HREF" Then _ArrayAdd($aLines, $sFileLine) $aLines[0] += 1 EndIf WEnd _ArrayDisplay($aLines) MsgBox(0, "", $aLines[0]) If $aLines[0] > 0 Then MsgBox(0, "", $aLines[1]) Edited July 20, 2010 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
olirav Posted July 20, 2010 Author Share Posted July 20, 2010 From a quick look on your code, better stick to an array. Try something like this (untested): #include <array.au3> $hFile = FileOpen("FILE", 0) If $hFile = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf Dim $aLines[1] = [0] While 1 $temp = FileReadLine($html) If @error = -1 Then ExitLoop If StringLeft($temp, 11) = "<DT><A HREF" Then _ArrayAdd($aLines, $temp) $aLines[0] += 1 EndIf WEnd _ArrayDisplay($aLines) MsgBox(0, "", $aLines[0]) If $aLines[0] > 0 Then MsgBox(0, "", $aLines[1]) _ArrayDisplay($aLines) MsgBox(0, "", $aLines[0]) If $aLines[0] > 0 Then MsgBox(0, "", $aLines[1]) That seems to work great, I've not used arrays much before so I didn't think of using them, thank you. (BTW have applied small fixes to make it work above) Link to comment Share on other sites More sharing options...
olirav Posted July 20, 2010 Author Share Posted July 20, 2010 Just one other quick question if I may is it possible to use FileFindFirstFile more than one directory deep, E.g. child directories. Oli Link to comment Share on other sites More sharing options...
Yoriz Posted July 20, 2010 Share Posted July 20, 2010 The "Cannot be an array element." kills that I think, trying anything involving a variable in the name just throws up Assign^ ERROR Oli Doesn't look like you are using arrays. this throws up an error in scite as the variable is not declared but continuing works anyway $temp = "Test variable" $line = "Line" $CurrentLineNo = "1" Assign($line & $CurrentLineNo, $temp) MsgBox(0, "", $Line1) But yes using an array is better if you understand them. Rather then using _ArrayAdd i would add to a delimeted string and then string split afterwards, reason being _ArrayAdd uses redim which can be slow on big files. GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF. Link to comment Share on other sites More sharing options...
KaFu Posted July 20, 2010 Share Posted July 20, 2010 There are lots of _FileListToArray hacks in the example form supporting recursion. OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
olirav Posted July 20, 2010 Author Share Posted July 20, 2010 Thanks for all your helpOli Link to comment Share on other sites More sharing options...
KaFu Posted July 20, 2010 Share Posted July 20, 2010 How would Appu say? "Pleesse come again..." ... CaptainSparky 1 OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) 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