Sign in to follow this  
Followers 0
johnmcloud

[SOLVED] For...Next Question

11 posts in this topic

#1 ·  Posted (edited)

Hi all,

A fast question, i need to make a For...Next, like this:

For $x = 1 To 6
MsgBox(0,0, $x)
Next

But i want to make a version with zero like this:

01
02
03
...
09
10
11

and one like this:

001
002
003
...
009
010
011
...
099
100

I have try to make the 0 before the variable but i have 010 011 in the first version and 0010 0011 in the second.

Some suggestion?

Thanks

Edited by johnmcloud

Share this post


Link to post
Share on other sites



try using

StringFormat


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

Somewhat like this

$NoOfZeroes = 2
For $x = 1 To 6
MsgBox(64, @ScriptName & ' | Phoenix XL', StringFormat('%0' & $NoOfZeroes & 'i', $x))
Next


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

Create an array with the desired strings, then loop through with $array[$i] as the data in the message box.

Share this post


Link to post
Share on other sites

Yes, thanks ;)

I have a side-question for this, i want to apply that to a function for enable-disable checkbox

Local $Checkbox_

 
$Checkbox_01 = GUICtrlCreateCheckbox("", 300, 101, 65, 17)
$Checkbox_02 = GUICtrlCreateCheckbox("", 310, 101, 65, 17)
$Checkbox_03 = GUICtrlCreateCheckbox("", 320, 101, 65, 17)
$Checkbox_04 = GUICtrlCreateCheckbox("", 330, 101, 65, 17)
$Checkbox_05 = GUICtrlCreateCheckbox("", 340, 101, 65, 17)
$Checkbox_06 = GUICtrlCreateCheckbox("", 350, 101, 65, 17)

$NoOfZeroes = 2
For $x = 1 To 6
GUICtrlSetState($Checkbox_ & StringFormat('%0' & $NoOfZeroes & 'i', $x))
Next

But not work, tips?

Thanks

Share this post


Link to post
Share on other sites

you are getting confused

try looking at the Eval function


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

Somewhat like this

#include <GuiConstants.au3>

GUICreate('')
$Checkbox_1 = GUICtrlCreateCheckbox("", 300-40, 101, 65, 17)
$Checkbox_2 = GUICtrlCreateCheckbox("", 310-35, 121, 65, 17)
$Checkbox_3 = GUICtrlCreateCheckbox("", 320-30, 141, 65, 17)
$Checkbox_4 = GUICtrlCreateCheckbox("", 330-25, 161, 65, 17)
$Checkbox_5 = GUICtrlCreateCheckbox("", 340-20, 181, 65, 17)
$Checkbox_6 = GUICtrlCreateCheckbox("", 350-15, 201, 65, 17)

$NoOfZeroes = 2
For $x = 1 To 6
GUICtrlSetState(Eval('Checkbox_' & $x), $GUI_CHECKED)
Next
GUISetState()

While GUIGetMsg()<>-3
Sleep(10)
WEnd


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I dind't know the Eval function, but like this:

$NoOfZeroes = 2
For $x = 1 To 6
GUICtrlSetState(Eval("$Checkbox_" & StringFormat('%0' & $NoOfZeroes & 'i', $x)), $GUI_CHECKED)
Next

Seems not work

EDIT: My mistake, work ;)

I have put the $

Wrong:

Eval("$Checkbox_"

Correct:

Eval("Checkbox_"
Edited by johnmcloud

Share this post


Link to post
Share on other sites

My really last question about For...Next

In a scenario like:

IniWrite("Test, "MyKey", "17", "7")
IniWrite("Test, "MyKey", "18", "8")
IniWrite("Test, "MyKey", "19", "9")
IniWrite("Test, "MyKey", "20", "10")
IniWrite("Test, "MyKey", "21", "11")
IniWrite("Test, "MyKey", "22", "12")

How i can concatenate the two For...Next?

Thanks for your time PhoenixXL

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

If there is a sequence of the Numbers use it inside the Loop

orelse make an Array and execute the Functions using the Index

Example

#include <GuiConstants.au3>

GUICreate('')
$Checkbox_1 = GUICtrlCreateCheckbox("", 300 - 40, 101, 65, 17)
$Checkbox_2 = GUICtrlCreateCheckbox("", 310 - 35, 121, 65, 17)
$Checkbox_3 = GUICtrlCreateCheckbox("", 320 - 30, 141, 65, 17)
$Checkbox_4 = GUICtrlCreateCheckbox("", 330 - 25, 161, 65, 17)
$Checkbox_5 = GUICtrlCreateCheckbox("", 340 - 20, 181, 65, 17)
$Checkbox_6 = GUICtrlCreateCheckbox("", 350 - 15, 201, 65, 17)
Local $nArray[6][2] = [ ["17","7"], _
["18","8"], _
["19","9"], _
["20","10"], _
["21","11"], _
["22","12"] _
]
$NoOfZeroes = 2
For $x = 1 To 6
GUICtrlSetState(Eval("$Checkbox_" & StringFormat('%0' & $NoOfZeroes & 'i', $x)), $GUI_CHECKED)
IniWrite("Test.ini", "MyKey",$nArray[$x-1][0],$nArray[$x-1][1])
Next
GUISetState()
While GUIGetMsg() <> -3
Sleep(10)
WEnd

Use Tidy[CTRL + T] to make the Syntax look Clean ;)

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Are two sequence of number, so i think i can avoid to write every number in the array

EDIT: This time i have resolved by myself

Static $iCount = 10
For $x = 1 To 6
 $iCount += 1
 ConsoleWrite($x & " " & $iCount & @CRLF)
Next

Thanks again ;)

Edited by johnmcloud

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0

  • Similar Content

    • nacerbaaziz
      By nacerbaaziz
      hellow guys
      I am a blind young man
      I started a project to make an audio player
      with recorder
      I ended the player and i did not know how to recorder
      This player is Compatible with the blind and visually impaired and ordinary users
      Unfortunately I do not see so I could not merge images and icons
      So I hope you will be able to help me in this matter
      I will bring you the open source project and please help me to add images, icons and recorder, the project is requires easy access in order to be compatible with the screen readers, Please take this into account.
      the software is organized so the recorder is In a special  menu that Contains stop and start and pause and save.
      The same is true for player
      Please help
      And greetings to all
      easy player.zip
    • nlta1992
      By nlta1992
      I want creat GUI, have button 1 to 10, but only use loop for ... to ... step ... next.
      Thanks.
    • digitalexpl0it
      By digitalexpl0it
      Hello,
       
      I am trying to updated a autoit app that moves files from one location to another. What Ia m trying to do is exclude specified sub directories from being moved/copied or files within the sub-folders
      As of now the code doesn't want to execute the nested for loop 
       
      Global $szDrive, $szDir, $szFName, $szExt Global $File = "*" func File_mover($Src,$File,$Dst) ; GET DIRECTORY EXCLUDES ; ###################### ; Create blank 2 dem array Local $ExArray[0][1] ; load ini file Local Const $sFilePath = "exclude.ini" ; Check to see if ini exists Local $iFileExists = FileExists($sFilePath) ; If the INI file is not found, output error message If not $iFileExists Then msgbox(0,"Oh NO!", $sFilePath & " not found!") endif ; Read ini file Local $aArray = IniReadSection($sFilePath, "test") ; Start the array loop If Not @error Then for $i = 1 to $aArray[0][0] ; Add Ini values into array _ArrayAdd($ExArray, $aArray[$i][1]) next endif ; Display array ;_ArrayDisplay($ExArray, "test Label") ProgressOn("Moving Scanned File(s)", "Moving scans into citrix...", "0%") $aFiles = _FileListToArray3($Src, $File, 1, 1, 0, 0) For $i = 1 To $aFiles[0] call("_PathSplit",$aFiles[$i], $szDrive, $szDir, $szFName, $szExt) $SrcFile = $Src & "\" & $szDrive & $szDir & $szFName & $szExt $DstFile = $Dst & "\" & $szDir & $szFName & $szExt $NumFiles = DirGetSize($Src,1) ; If File Exsists copy and rename file If FileExists($DstFile) Then $DstFile = call("_IfIdenticalIncrement", $SrcFile, $DstFile) If $DstFile <> "" Then For $ii = $NumFiles[1] To 100 Step 10 ProgressSet($ii, $ii & "%","Moving Files...") ; Move Scans ; List Dir in srouce dir $dirEx = _FileListToArray($Src,"*",2) If UBound($dirEx) > 1 Then ; Look in the dir list array For $dir In $dirEx ; Find and compaire dir in exclude array For $exclude In $ExArray If ($dir = $exclude) Then ; if exclude dir found go to top loop and skip ContinueLoop 2 EndIf Next FileMove($SrcFile, $DstFile, 8) Next endif Sleep(100) Next EndIf ; File doesnt exists so copy the file over Else For $ii = $NumFiles[1] To 100 Step 10 ProgressSet($ii, $ii & "%","Moving Files...") ; Move Scans ; List Dir in srouce dir $dirEx = _FileListToArray($Src,"*",2) If UBound($dirEx) > 1 Then ; Look in the dir list array For $dir In $dirEx ; Find and compaire dir in exclude array For $exclude In $ExArray If ($dir = $exclude) Then ; if exclude dir found go to top loop and skip ContinueLoop 2 EndIf Next FileMove($SrcFile, $DstFile, 8) Next endif Sleep(100) next EndIf ProgressSet(100, "Scans Moved...Successfully!", "Done!") sleep(2000) ProgressOff() Next endfunc Func _IfIdenticalIncrement($vSrcFile, $vDstFile) Local $Count = 0 ; Get the modified date of the source file. $ScrVer = FileGetTime($vSrcFile, 0, 1) ; To get all elemnt of the distination file (in plan to add incremental number). call("_PathSplit",$vDstFile, $szDrive, $szDir, $szFName, $szExt) ; Loop to increment the name of the file. While FileExists($vDstFile) $Count += 1 $vDstFile = $szDrive & $szDir & $szFName & "(" & $Count & ")" & $szExt WEnd ; If file(1), it assume that is the first copy. If $Count = 1 Then Return $vDstFile ; If file(x-1) is identical then assume the file is already duplicated. ElseIf $ScrVer = FileGetTime($szDrive & $szDir & $szFName & "(" & $Count - 1 & ")" & $szExt, 0, 1) Then Return "" ; Else assume it is a new version. Else Return $vDstFile EndIf EndFunc ;==>_IfIdenticalIncrement  
       
      This part is skipped and not sure why
       
      For $exclude In $ExArray If ($dir = $exclude) Then ; if exclude dir found go to top loop and skip ContinueLoop 2 EndIf Next INI file is this
       
      [test] EXCLUDE1=test1 EXCLUDE2=test2 EXCLUDE3=test3  
    • RyukShini
      By RyukShini
      Opt("WinDetectHiddenText",1) #include <IE.au3> #include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> #include <clear.au3> #include <ColorConstants.au3>; Including required files #include <GUIConstantsEx.au3> #include <file.au3> #include <string.au3> Sleep(5000) Local $emails = "email.txt" ;sets file path Local $pwd = "pwd.txt" ;sets file path Local $name = "name.txt" Local $ArrayEmail[57], $ArrayPwd[57], $ArrayName[57] ;declares array _FileReadToArray($emails, $ArrayEmail) ;converts file to array _FileReadToArray($pwd, $ArrayPwd);converts file to array _FileReadToArray($name, $ArrayName);converts file to array Local $url= "https://localhost/signup" Local $oIE = _IECreate($url, 1) $tags = $oIE.document.GetElementsByTagName("a") For $tag in $tags $class_value = $tag.GetAttribute("class") If string($class_value) = "badge-signup-email-link" Then $oCorrectObj = $tag ExitLoop EndIf Next If IsObj ( $oCorrectObj ) Then _IEAction ($oCorrectObj, "click") EndIf Local $name = _IEGetObjByName ($oIE, "fullname") Local $email = _IEGetObjByName ($oIE, "email") Local $password = _IEGetObjByName ($oIE, "password") _IEFormElementSetValue($name, $ArrayName[1]) _IEFormElementSetValue($email, "" & ++1 & $Arrayemail[1]) _IEFormElementSetValue($password, $ArrayPwd[1]) $colTags = _IETagNameGetCollection($oIE, "input") For $oTag In $colTags If $oTag.value = "Sign Up" Then sleep(15000) _IEAction($oTag, "click") _IENavigate($oIE,"javascript:void(0);") ; javascript:void is triggered. EndIf Next I coded this script and silly me forgot to create it in a loop to begin with -.-
      now I have tried While & For loop with counters and what not, but I just can't seem to get it to work.

      Could someone be of assistance?

      Thanks in advance.
    • alien4u
      By alien4u
      I was having some problems with Progressbar with  nested "FOR" Loop but I was using it unnecessarily so I end up with only one "FOR" Loop.

      Here I'm sharing with you two ways of solve the progressbar problem, this is not for advanced users, this is for reference and newbies like me.
      And about the progressbar using GUICtrlSetData() with one FOR Loop and variable cicles(for example cicles base of elements on Array with variable size) you can do it as fallow:
      Note: Does not matter if the Array size is 50 or 5000 the progressbar will work properly.
      $progress = GUICtrlCreateProgress() Local $count = UBound($Array) Local $imove = ((1 / $count) * 100) ; One is because you will SetData to Progress each 1 cicle. Local $itemp = 0 For $i = 0 To UBound($Array) - 1 ; Your Code could be here $itemp += $imove GUICtrlSetData($progress, $itemp) ; Or your code could be here. Next  
      Another way to do it and I think is more elegant or fancy is like this:
      $progress = GUICtrlCreateProgress() Local $itemp = 0 Local $count = 0 Local $intcount = Floor(Ubound($Array)/100) For $i = 0 To UBound($Array) - 1 ; Your Code could be here If Mod($i, $intcount) == 0 Then $count = $count+1 GUICtrlSetData($progress, $count) EndIf ; Or your code could be here. Next
      Kind Regards
      Alien.