Jump to content

Recommended Posts

Posted

hi all,

i want to try to learn how to use arrays, but the F1 help file from SciTE isnt really user friendly.. and the other sample scripts here arent either :)

so, can anyone link me to some useufl beginner guides on arrays, or just post some really simple scripts?

what i'm trying to do is, for example, read "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run" and then write all the entries into an ini file.

thanks for your help!

Posted

hi all,

i want to try to learn how to use arrays, but the F1 help file from SciTE isnt really user friendly.. and the other sample scripts here arent either :)

so, can anyone link me to some useufl beginner guides on arrays, or just post some really simple scripts?

what i'm trying to do is, for example, read "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run" and then write all the entries into an ini file.

thanks for your help!

why are you using the Scite help file? You supposed to use the autoit help file, Start>Programs>Autoit v3>Beta>Autoit Help File

Posted

thats the same file :)

#include <Array.au3>

dim $E[20][20]

_Arraydisplay ($E); for looking on the one-dimension array of $E 200 rows.

for $i=1 to 5
$m=RegEnumVal ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run",$i)
MsgBox (0,"this is $m",$m)
$E[1][$i]=$m
Next
_ArrayDisplay ($E)
for $i=1 to 5
$m=RegEnumVal ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run",$i)
MsgBox (0,"this is $m",$m)
$E[$i][2]=$m
Next
_ArrayDisplay ($E)

have fun... :)

Posted

This should be close.

Func _BuildIni()
   Local $eArray [1][2], $Ini = @DesktopDir & "\Test.ini"
   Local $I, $Count = 1, $eReg = "", $rKey = "HKCU\Software\Microsoft\Windows\CurrentVersion\Run"
   While 1
      $kVal = RegEnumVal($rKey, $Count)
      If @Error Then ExitLoop
      If StringInStr($kVal, ".dll") OR StringInStr($kVal, ".ocx") OR StringInStr($kVal, ".tbl") Then
         ReDim $eArray[UBound($eArray) + 1][2]
         $eArray[UBound($eArray) - 1][0] = $kVal
         $eArray[UBound($eArray) - 1][1] = RegRead($rKey, $kVal)
      EndIf
      $Count += 1
   Wend
   For $I = 1 To UBound($eArray) - 1
      IniWrite($Ini, "Run", $eArray[$i][0], $eArray[$i][1])
   Next
EndFunc  ;==>_BuildIni

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!"

Posted

thanks for the help erezlevi and GEOSoft.

@erezlevi, i dont know how i can really make use of that as i dont really understand that much of it.

@GEOSoft, when i compile this, it does nothing. when i add a _BuildIni() on top (to make it run the function or something) then still nothing happens.

sorry if i seem really stupid, but im still new to AutoIT3 :S

Posted

thanks for the help erezlevi and GEOSoft.

@erezlevi, i dont know how i can really make use of that as i dont really understand that much of it.

@GEOSoft, when i compile this, it does nothing. when i add a _BuildIni() on top (to make it run the function or something) then still nothing happens.

sorry if i seem really stupid, but im still new to AutoIT3 :S

That was my fault. I was modifying a function that I already use and I forgot to remove an If statement that you don't need. here is the correction (Tested this time).

_BuildIni()

Func _BuildIni()
   Local $eArray [1][2], $Ini = @DesktopDir & "\Test.ini"
   Local $I, $Count = 1, $eReg = "", $rKey = "HKCU\Software\Microsoft\Windows\CurrentVersion\Run"
   While 1
      $kVal = RegEnumVal($rKey, $Count)
      If @Error Then ExitLoop
         ReDim $eArray[UBound($eArray) + 1][2]
         $eArray[UBound($eArray) - 1][0] = $kVal
         $eArray[UBound($eArray) - 1][1] = RegRead($rKey, $kVal)
      $Count += 1
   Wend
   For $I = 1 To UBound($eArray) - 1
      IniWrite($Ini, "Run", $eArray[$i][0], $eArray[$i][1])
   Next
EndFunc ;==>_BuildIni

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!"

Posted

thanks you are right, its working. now i just need to figure out how to relate all those [0] and [1]'s with each other :)

Posted

Here is another example if your still confused.

Global $Array[3] = ["Hi, "Hello", "Bye"]
$GetInput = InputBox("", "Please type in a greeting:")
For $I = 1 To $Array[0]
    If $GetInput = $Array[$I] Then Beep(8000, 100)
Next

Actually, that example was pretty useless, but I hope you get the idea.

Posted

Here is another example if your still confused.

Global $Array[3] = ["Hi, "Hello", "Bye"]
$GetInput = InputBox("", "Please type in a greeting:")
For $I = 1 To $Array[0]
    If $GetInput = $Array[$I] Then Beep(8000, 100)
NextoÝ÷ Ø-¹©eÊØZµìZ^Á«)­ëmÊëë,nëH^Ê zÛaz'^kú®¢×¬¥v}ý¶+[y«­¢+Ù½ÈÀÌØí$ôÀQ¼U½Õ¹ ÀÌØíÉÉ䤴

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Posted

Actually, yes that is a way, and two reasons why it didn't work was that For $I = 1 should be For $I = 0, and the top array was correct. Here is the updated code:

Global $Array[3] = ["Hi", "Hello", "Bye"]
$GetInput = InputBox("", "Please type in a greeting:")
For $I = 0 To $Array[0]
    If $GetInput = $Array[$I] Then Beep(8000, 100)
Next

I could use UBound($Array) -1 instead of $Array[0] but $Array[0] does the same thing. :)

Thanks Gary.

Posted

Actually, yes that is a way, and two reasons why it didn't work was that For $I = 1 should be For $I = 0, and the top array was correct. Here is the updated code:

Global $Array[3] = ["Hi", "Hello", "Bye"]
$GetInput = InputBox("", "Please type in a greeting:")
For $I = 0 To $Array[0]
    If $GetInput = $Array[$I] Then Beep(8000, 100)
Next

I could use UBound($Array) -1 instead of $Array[0] but $Array[0] does the same thing. :)

Thanks Gary.

How do you figure? $Array[0] contains "Hi"

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Posted

Oh, I guess it only works for certain types of arrays. The arrays returned by the _Array() functions and things like _FileListToArray() return the number of items in an array with $Array[0].

Here is the fixed code:

Global $Array[4] = ["3", "Hi", "Hello", "Bye"]
$GetInput = InputBox("", "Please type in a greeting:")
For $I = 0 To $Array[0]
    If $GetInput = $Array[$I] Then Beep(8000, 100)
Next

The first $Array value, 3, tells how many greetings are in the array. So, now it works. :), And, thanks again Gary.

Posted (edited)

Oh, I guess it only works for certain types of arrays. The arrays returned by the _Array() functions and things like _FileListToArray() return the number of items in an array with $Array[0].

Here is the fixed code:

Global $Array[4] = ["3", "Hi", "Hello", "Bye"]
$GetInput = InputBox("", "Please type in a greeting:")
For $I = 0 To $Array[0]
    If $GetInput = $Array[$I] Then Beep(8000, 100)
Next

The first $Array value, 3, tells how many greetings are in the array. So, now it works. :), And, thanks again Gary.

Don't get use to the offset of zero being the number in the array, that may change in the future.

Just figured if your going to tell someone how to use an array, it needs to be correct.

Edited by GaryFrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

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...