Sign in to follow this  
Followers 0
demun

How to write the script to expand a for loop description?

10 posts in this topic

Hi,

I want to write a AutoIt script to translate the following strings format, can someone help me?

Thanks.

FROM:

forloop param1 {2 3} param2 {9 10} {

    The result is output1=$param1 output2=$param2
}
 
TO:
The result is output1=2 output2=9
The result is output1=2 output2=10
The result is output1=3 output2=9
The result is output1=3 output2=10
 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Welcome to the forum.

I'm struggling with what you are actually asking here.

How about instead of using param and output numbers, you tell us what they might be in the real world.

In fact what you are dealing with and what the result is likely to be or desired (i.e. 2 apples)

What you think needs to be done, and what actually needs to be done, might be two very different things.

I also recommend you look in the Help file at the various Loops available

i.e. While ... Wend

For ... Next

and so on.

Oops! Just realized you are in the wrong forum.

I will report it to be relocated to General Help & Support.

Edited by TheSaint

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

Hi,

 

I want to write a AutoIt script to translate the following command format, can someone help me?

 

Thanks.

 

Originate command format:

forloop param1 {2 3} param2 {9 10} {

    "The result is output1=$param1 output2=$param2"
}
 
Want to translate from above commands to following:
"The result is output1=2 output2=9"
"The result is output1=2 output2=10"
"The result is output1=3 output2=9"
"The result is output1=3 output2=10"

Share this post


Link to post
Share on other sites

Help file is a good place to begin.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

You really should have waited until your topic was relocated here, so I repeat again most of what I wrote there.

Which you haven't seemingly taken on board.

Welcome to the forum.

I'm struggling with what you are actually asking here.

How about instead of using param and output numbers, you tell us what they might be in the real world.

In fact what you are dealing with and what the result is likely to be or desired (i.e. 2 apples)

What you think needs to be done, and what actually needs to be done, might be two very different things.

I also recommend you look in the Help file at the various Loops available

i.e. While ... Wend

For ... Next

and so on.

Edited by TheSaint

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

Hi,

My question is:

Now i got many command script files in my hand, like this format: (where 'abc' and 'def' are the input for the string with {2, 3} and {9, 10}

forloop abc {2 3} def {9 10} {

    "The result is hello=$abc seeyou=$def"
}
 
I would like to expand above script language to new command like this:
 
"The result is hello=2 seeyou=9"
"The result is hello=2 seeyou=10"
"The result is hello=3 seeyou=9"
"The result is hello=3 seeyou=10"
 
ps. I updated some keywords as I found the originate keywords might cause some misunderstanding to anyone who reads my post

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

This still doesn't make much sense. 

Please provide a logical explanation of what you are trying to achieve:

Input data -----------(Conditions)-----------> Output data

So far all I gather if you're wanting for below:

Input: {2,3}{9,10}

Output1: 2,9

Output2: 2,10

Output3: 3,9

Output4, 3,10

 

If that's the case then you are just looking at a simple look that takes those two sets of numbers and outputs the four possible combinations according to your rule:

e.g. Input: {x,y}{z,k}

Output1: x,z

Output2: x,k

Output3: y,z

Output4, y,k

 

If I am not understanding correctly then please let me know. Otherwise this is what I came up with (there is probably a more elegant way but I don't know it :P):

#include <Array.au3>

$abc = '{2, 3}'
$def = '{9, 10}'

$abc = StringRegExp($abc, "\{([^}]*)\}", 1)
$abc = StringStripWS($abc[0], 8)
$set1 = StringSplit($abc, ',', 2)

$def = StringRegExp($def, "\{([^}]*)\}", 1)
$def = StringStripWS($def[0], 8)
$set2 = StringSplit($def, ',', 2)

Local $i, $k = 0, $j = 1
For $i = 0 to 1
    ConsoleWrite("The result is hello="&$set1[$i]&" seeyou="&$set2[$k]&@CRLF)
    ConsoleWrite("The result is hello="&$set1[$i]&" seeyou="&$set2[$j]&@CRLF)
Next
Edited by mpower

Share this post


Link to post
Share on other sites

$aABC = StringSplit( "2, 3", ", ", 3 )
$aDEF = StringSplit( "9, 10", ", ", 3 )

For $i In $aABC
  For $j in $aDEF
    ConsoleWrite( "$i, $j = " & $i & ", " & $j & @CRLF )
  Next
Next
$i, $j = 2, 9
$i, $j = 2, 10
$i, $j = 3, 9
$i, $j = 3, 10

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Another similar route:

For $i = 2 To 3
    For $j = 9 To 10
        ConsoleWrite("The result is hello=" & $i & " yousee=" & $j & @CRLF)
    Next
Next

output:

The result is hello=2 yousee=9
The result is hello=2 yousee=10
The result is hello=3 yousee=9
The result is hello=3 yousee=10

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

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