Increment parameter values

Hi

I am a novice user of eggplant and found a simple code to increment parameter values here in this forum, but I'm unable to implement in my scenario.
I have 2 fields: Account#, Accnt Description.
I need the program to create a new account number&desc each time a function "createAccount" is called.
For example say A1100 should display the respective description field as TestAccount1100. If i put the func call in a loop, 'repeat 5 times' then i need 5 accounts A1100, A1200, A1300, A1400 and A1500 displayed along with their description fields with incremental values.

Please help.

Comments

  • EggplantMattEggplantMatt ForumAdmin admin
    The simplest approach is to increment your counter outside of the function call:
    put 1100 into acctNum
    repeat 5 times
    	createAccount acctNum
    	add 100 to acctNum
    end repeat
    
    to createAccount acctNum
    	click "acctNumField"
    	typeText "A" & acctNum
    	click "acctDescField"
    	typeText "TestAccount" & acctNum
    end createAccount
    
    Or you could use a global variable to store the counter variable:
    global acctNum
    put 1100 into acctNum
    repeat 5 times
    	createAccount 
    end repeat
    
    to createAccount
    	global acctNum
    	click "acctNumField"
    	typeText "A" & acctNum
    	click "acctDescField"
    	typeText "TestAccount" & acctNum
    	add 100 to acctNum
    end createAccount
    
    Or you could pass the variable to the function by reference:
    put 1100 into acctNum
    repeat 5 times
    	createAccount @acctNum
    end repeat
    
    to createAccount acctCounter
    	click "acctNumField"
    	typeText "A" & acctCounter
    	click "acctDescField"
    	typeText "TestAccount" & acctCounter
    	add 100 to acctCounter
    end createAccount
    
  • I chose the simplest method. Thank you.
    Also, can I pass an image as a parameter to the func call? Is the following possible to achieve:

    createAccount( category, accNum)

    where 'category' contains the image of the Category number. What should be the data type of 'category'... boolean? Because my condition is that if that image is valid(i.e if there is a category present on the screen) then create an account underneath it.
  • EggplantMattEggplantMatt ForumAdmin admin
    To pass an image, you just refer to it by name, just as you do when using an image with any command or function. You don't need to worry about declaring types for parameters. There are cases where a command or function expects a particular object type and will complain when it gets something else, but those are run-time issues, not compile-time issues.
Sign In or Register to comment.