3 Replies - 271 Views - Last Post: 14 July 2017 - 09:07 AM

#1 hexagod  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 242
  • Joined: 29-October 16

Recommendations for Repeating Lines of Code?

Posted 14 July 2017 - 08:18 AM

So lets say I'm trying to repeat an operation like this:

		String^ sendDir;

		qTDestination = textBox1->Text;

		String^ userName = textBox2->Text;

		String^ setExecutionPolicy = "Set-ExecutionPolicy Unrestricted" + "\r\n";

		String^ createRemoteDir = "New-Item -ItemType directory -Path C:\\users\\" + userName; 

		String^ dirPath = textBox3->Text;




..and I want to replace username with a couple different Strings^ then automatically repeat for several users. What would be your recommendations for doing this? I've got a program that I wrote for moving files using Powershell and I'd like to be able to check boxes for multiple users or computers then have several lines of code repeat and inject a different String^ each time it repeats. Any ideas?

Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Recommendations for Repeating Lines of Code?

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13401
  • View blog
  • Posts: 53,498
  • Joined: 12-June 08

Re: Recommendations for Repeating Lines of Code?

Posted 14 July 2017 - 08:20 AM

Loops work well. Like a for loop over a collection.
Was This Post Helpful? 0
  • +
  • -

#3 hexagod  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 242
  • Joined: 29-October 16

Re: Recommendations for Repeating Lines of Code?

Posted 14 July 2017 - 09:03 AM

Ok yea I'll see if I can get a draft going on some loopage then hopefully u can proofread it lol.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13401
  • View blog
  • Posts: 53,498
  • Joined: 12-June 08

Re: Recommendations for Repeating Lines of Code?

Posted 14 July 2017 - 09:07 AM

I would advocate testing the loop as well.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1