Jump to content
Sign in to follow this  
Rex

Multiply $var's in one $var

Recommended Posts

Rex

Hi.

Is this possible.

$var1 = User1
$Var2 = User4
$var = 2

if $var = 2 then
$varMore = $Var1 and $var2
Dircreate($VarMore)

would this create 2 Directorys, one with User1 and one with User2 ?

Share this post


Link to post
Share on other sites
Blue_Drache

Hi.

Is this possible.

$var1 = User1
$Var2 = User4
$var = 2

if $var = 2 then
$varMore = $Var1 and $var2
Dircreate($VarMore)

would this create 2 Directorys, one with User1 and one with User2 ?

<{POST_SNAPBACK}>

The actual code would be $varMore = $var1 & $var2, but ... it would only create the string "User1User4"

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites
CyberSlug

About the closest you can do:

Dim $var[2];create array of two elements
$var[0] = "UserA";first element has index zero
$var[1] = "UserB";second element has index one
$numberOfUsers = 2

; Loop through each array element
For $i = 0 to $numberOfUsers-1
    DirCreate($var[$i])
Next

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites
Rex

I need it in this code, and for up to 8 users

If $Users = 1 Then
      $User = $User_1
  ElseIf $Users = 2 Then
      $User =  $User_1
      $User =  $User_2
      EndIf
 
     
      DirCreate($drev_1 & ":\" & $Mappe_1 & "\" & $User & "\" & $Dokumenter_1)
      DirCreate($drev_1 & ":\" & $Mappe_1 & "\" & $User & "\" & $Foretrukne_1)
      DirCreate($drev_1 & ":\" & $Mappe_1 & "\" & $User & "\" & $Post_1)
      DirCreate($drev_1 & ":\" & $Mappe_1 & "\" & $User & "\" & $TCM_1)
      DirCreate($drev_1 & ":\" & $Mappe_1 & "\" & $User & "\" & $Andet_1)
      DirCreate($drev_1 & ":\" & $Mappe_1 & "\" & $User & "\" & $Andet_2)
      DirCreate($drev_1 & ":\" & $Mappe_1 & "\" & $User & "\" & $Andet_3)
      DirCreate($drev_1 & ":\" & $Mappe_1 & "\" & $User & "\" & $Andet_4)

So if i under stand right if must be somthing like this

If $Users = 1 Then
      $User = $User[0]
  ElseIf $Users = 2 Then
      $User =  $User[1]
            EndIf
 
     For $User = 0 to $Users-1
      DirCreate($drev_1 & ":\" & $Mappe_1 & "\" & $User[ & "\" & $Dokumenter_1)
      DirCreate($drev_1 & ":\" & $Mappe_1 & "\" & $User & "\" & $Foretrukne_1)
      DirCreate($drev_1 & ":\" & $Mappe_1 & "\" & $User & "\" & $Post_1)
      DirCreate($drev_1 & ":\" & $Mappe_1 & "\" & $User & "\" & $TCM_1)
      DirCreate($drev_1 & ":\" & $Mappe_1 & "\" & $User & "\" & $Andet_1)
      DirCreate($drev_1 & ":\" & $Mappe_1 & "\" & $User & "\" & $Andet_2)
      DirCreate($drev_1 & ":\" & $Mappe_1 & "\" & $User & "\" & $Andet_3)
      DirCreate($drev_1 & ":\" & $Mappe_1 & "\" & $User & "\" & $Andet_4)
next

Is that correct ?

Course if i can het this to work i will end up with <6000 lines of code, current i allready have <2000 lines :-(

Script attached to My first post

http://www.autoitscript.com/forum/index.php?showtopic=9661

I realy try to learn how to use AutoIt correct :) , but i still have alot of hangovers form the good old DOS....

Share this post


Link to post
Share on other sites
MHz

Depends on your circumstances, but you could use StringSplit to create the array?

$drev_1 = 'C'
$Mappe_1 = 'All'
$folder = 'Group'

;;; The Users stored here.
$AllUsers = 'Bob|Paul|George|Scott|Peter|Francis|Louise|Jackie'

;;; $user_ becomes an array.
$User_ = StringSplit($AllUsers, '|')

;;; $Create folders
For $i = 1 To UBound($user_) - 1
    DirCreate($drev_1 & ":\" & $Mappe_1 & "\" & $Folder & "\" & $User_[$i])
Next

Share this post


Link to post
Share on other sites
Rex

Depends on your circumstances, but you could use StringSplit to create the array?

$drev_1 = 'C'
$Mappe_1 = 'All'
$folder = 'Group'

;;; The Users stored here.
$AllUsers = 'Bob|Paul|George|Scott|Peter|Francis|Louise|Jackie'

;;; $user_ becomes an array.
$User_ = StringSplit($AllUsers, '|')

;;; $Create folders
For $i = 1 To UBound($user_) - 1
    DirCreate($drev_1 & ":\" & $Mappe_1 & "\" & $Folder & "\" & $User_[$i])
Next

<{POST_SNAPBACK}>

Thanks that works Perf.

My code now looks like this

For $i = 1 To UBound($user_) - 1
   If $Alle_NOT = 0 Then
      
      DirCreate($drev_1 & ":\" & $Mappe_1 & "\" & $User_[$i] & "\" & $Dokumenter_1)
      DirCreate($drev_1 & ":\" & $Mappe_1 & "\" & $User_[$i] & "\" & $Foretrukne_1)
      DirCreate($drev_1 & ":\" & $Mappe_1 & "\" & $User_[$i] & "\" & $Post_1)
      DirCreate($drev_1 & ":\" & $Mappe_1 & "\" & $User_[$i] & "\" & $TCM_1)
      DirCreate($drev_1 & ":\" & $Mappe_1 & "\" & $User_[$i] & "\" & $Andet_1)
      DirCreate($drev_1 & ":\" & $Mappe_1 & "\" & $User_[$i] & "\" & $Andet_2)
      DirCreate($drev_1 & ":\" & $Mappe_1 & "\" & $User_[$i] & "\" & $Andet_3)
      DirCreate($drev_1 & ":\" & $Mappe_1 & "\" & $User_[$i] & "\" & $Andet_4)
      MsgBox(0, "Opret mapper", "Følgende mapper er oprettet på drev " & $drev_1 & " " & @CRLF _
             & $Mappe_1 & @CRLF & $Bruger_1 & @CRLF & $Dokumenter_1 & @CRLF & $Foretrukne_1 & @CRLF _ 
       & $Post_1 & @CRLF & $TCM_1 & @CRLF & $Andet_1 & @CRLF & $Andet_2 & @CRLF & $Andet_3 & @CRLF & $Andet_4)
   EndIf
   Next

Now i only have to figer out to get the Msgbox to show only the one time if there is only one user, a.s.o. Hmm why not use CyberSlug's idea.

Might be somthing like this

Dim $var[8];create array of 1 to 8 elements
$var[0] = "User1";first element has index zero
$var[1] = "User2";second element has index one
$var[2] = "User3";
$var[3] = "User4";
$var[4] = "User5";
$var[5] = "User6";
$var[6] = "User7";
$var[7] = "User8";

; Loop through each array element
For $ii = 0 to $User-1
  ;DirCreate($var[$i])
    MsgBox(0, "Opret mapper æøå", "Følgende mapper er oprettet på drev " & $drev_1 & " " & @CRLF _
             & $Mappe_1 & @CRLF & $User_[$i] & @CRLF & $Dokumenter_1 & @CRLF & $Foretrukne_1 & @CRLF & $Post_1)
Next

EDIT:

Hmm nope that did't work maby the $i is't saved after the next has end.

Is is possible to use 2 'for' with in one next, or how do i do it

Edited by Rex

Share this post


Link to post
Share on other sites
MHz

Dim $var[8];create array of 1 to 8 elements

$var[0] = "User1";first element has index zero

$var[1] = "User2";second element has index one

$var[2] = "User3";

$var[3] = "User4";

$var[4] = "User5";

$var[5] = "User6";

$var[6] = "User7";

$var[7] = "User8";

; Loop through each array element

For $ii = 0 to UBound($var) - 1

  ;DirCreate($var[$i])

    MsgBox(0, "Opret mapper æøå", "Følgende mapper er oprettet på drev " & $drev_1 & " " & @CRLF _

            & $Mappe_1 & @CRLF & $var_[$i] & @CRLF & $Dokumenter_1 & @CRLF & $Foretrukne_1 & @CRLF & $Post_1)

Next

Corrected a couple of key items.

UBound reads the number of array elements in $var, but we add the minus 1, as arrays declared, are 1 element bigger.

The For Next, indexes $i, from 0 to the array amount, calculated by UBound. As it is indexed, so is the highlighted array, in the msgbox statement. Each loop will produce a different user, as you declared, at the top of the script.

Share this post


Link to post
Share on other sites
Rex

Corrected a couple of key items.

UBound reads the number of array elements in $var, but we add the minus 1, as arrays declared, are 1 element bigger.

The For Next, indexes $i, from 0 to the array amount, calculated by UBound. As it is indexed, so is the highlighted array, in the msgbox statement. Each loop will produce a different user, as you declared, at the top of the script.

<{POST_SNAPBACK}>

Hmm still i get an error about the $i is not declared, so i det it like this insted

If $User = 8 Then
$AllUsers = $Bruger_1 &'|' & $Bruger_2 &'|' & $Bruger_3 &'|' & $Bruger_4 &'|' & $Bruger_5 &'|' & $Bruger_6 &'|' & $Bruger_7 &'|' & $Bruger_8
ElseIf $User =7 Then
    $AllUsers = $Bruger_1 &'|' & $Bruger_2 &'|' & $Bruger_3 &'|' & $Bruger_4 &'|' & $Bruger_5 &'|' & $Bruger_6 &'|' & $Bruger_7
ElseIf $User = 6 Then
    $AllUsers = $Bruger_1 &'|' & $Bruger_2 &'|' & $Bruger_3 &'|' & $Bruger_4 &'|' & $Bruger_5 &'|' & $Bruger_6
ElseIf $User = 5 Then
    $AllUsers = $Bruger_1 &'|' & $Bruger_2 &'|' & $Bruger_3 &'|' & $Bruger_4 &'|' & $Bruger_5
ElseIf $User = 4 Then
    $AllUsers = $Bruger_1 &'|' & $Bruger_2 &'|' & $Bruger_3 &'|' & $Bruger_4
ElseIf $User = 3 Then
    $AllUsers = $Bruger_1 &'|' & $Bruger_2 &'|' & $Bruger_3
ElseIf $User = 2 Then
    $AllUsers = $Bruger_1 &'|' & $Bruger_2
ElseIf $User = 1 Then
    $AllUsers = $Bruger_1
    EndIf

;;; $user_ becomes an array.
$User_ = StringSplit($AllUsers, '|')

For $i = 1 To UBound($user_) - 1

Well and that seems to work :D , and still that cuts my code lines form <2000 lines to, after cleaming up comments,white spaces and running a tidy i'm dovn >900 lines, a cut down for over 1100 lines wow, THX guys :huh:

Now i will try to translate my GUI to english, so other's can use it cource i can't be the only one who sets up Pc's and moving User profiles to a nother drive.

The only thing i now need i to finde out how to use AutoIt to create the corect entrys in reg. to tell the system that i have moved the Documents, Favorites, Post a.s.o to the locations of Opret Profile(s).

The first part i easy, but the second part :) , normely i use the TweakiUI XP (M$'s own Tweaki for XP). Does any of u know how to finde out wath the current users enty under HKEY_Users is ?, if i look in the reg mine is HKEY_USERS\S-1-5-21-2025429265-220523388-725345543-1003, but at my Laptop it's HKEY_USERS\S-1-5-21-2025429265-220523388-725368538-1003. and i know that it's in that reg i hawe to tell the sys the path's. reg shot showed me that :D

When i'm finished translating my script ill uploade it in here.

And ones again THX guys

:EDIT

Well translating finished (i hope)

:EDIT again

A littel misspell. attc updated

Edited by Rex

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.