mbwh
(Fresh Scripter)
2012-05-23 10:00 AM
variable in variable

Hello,

ich have a Problem to become a value as an variable.

I have the variable

$localdrive_H = "\\Fileserver\share"

i build the new variable with
$drive = LEFT($localdrive_H, 1)

$NewVariable = "$localdrive_" + $drive
The variable $NewVariable has the value $localdrive_H

when i use this in
use h: $NewVariable

i become an errer because the Value of this is $localdrive_H and not \\Fileserver\share

how can i become the right value?
can everyone help me?

Regards
Michael


Mart
(KiX Supporter)
2012-05-23 11:27 AM
Re: variable in variable

Hi and welcome to the board.

You do a $drive = Left($localdrive_H, 1). This will put \ in the $drive variable. When this is added to the $localdrive_ variable (which is empty) it will result in incorrect values.

If I look at your script all you want to do is map the H drive so why can’t you just do: use H: $localdrive_H?


ShaneEP
(MM club member)
2012-05-23 04:40 PM
Re: variable in variable

Dynamic variables can be achieved using Execute(), but like Mart pointed out...your Left() results in a \. Not real sure what you're trying to accomplish.

mbwh
(Fresh Scripter)
2012-05-24 10:07 AM
Re: variable in variable

Hello,

oh sorry, i mean right!

With Execute ()???

Regards
Michael


Mart
(KiX Supporter)
2012-05-24 11:41 AM
Re: variable in variable

This works but I still don't get it. Using Use h: $localdrive_H will do exactly the same. Why make it more complex than it is?
I doubled the $ in the Right function to stop kix from resolving it to the actual value. In your example it resolves the variable to the actual value giving you an e (from \\fileserver\share).

 Code:
$localdrive_H = "\\Fileserver\share"
$drive = Right("$$localdrive_H", 1) 
$NewVariable = "$localdrive_" + $drive
Use h: $NewVariable 


mbwh
(Fresh Scripter)
2012-05-24 03:31 PM
Re: variable in variable

Hello!

here is my right script.

 Code:
$lokalDrive_G = "\\filesrv001\log$"

For $Count = 65 To 90 Step 1
	$L  = Chr ($Count)
	$LD = $L + ":"
	$LDR = ("$lokalDrive_" + $L)
	$LDRIVE = execute ('$$LDR')
	? $LDRIVE     ; This variable has the value 0 when the variable $LDR have the value "$lokaldrive_G". What can i do to become the value \\filesrv001\log$  ???
	If $LDRIVE <> NULL
		$Counter = 0
		DO
			$Counter = $Counter + 1
			? $Counter
			? $LD
			? $L
			? "$lokalDrive_" + $L
			If Exist ($LD) = 1
				Use $LD /Del 
				Use $LD $LDRIVE
            Else
				Use $LD $LDRIVE
            EndIf
        Until Exist($LD) = 1 or $Counter = 5
            
        If Exist ($LD) = 0
                        MessageBox ("ACHTUNG! Kein " + $L + "-Laufwerk vorhanden! Evtl. sind Sie nicht richtig am Netzwerk angemeldet.", "@TIME", 0)
                        $Error = $L + " "
        EndIf
	EndIf
Next


Can everyone help me?

Regards
Michael


LonkeroAdministrator
(KiX Master Guru)
2012-05-24 08:31 PM
Re: variable in variable

not sure what you want help with. You don't need the execute... And kixtart doesn't have null so that test will always pass.

mbwh
(Fresh Scripter)
2012-05-24 09:19 PM
Re: variable in variable

i will
? $LDRIVE ; This variable has the value 0 when the variable $LDR have the value "$lokaldrive_G". What can i do to become the value \\filesrv001\log$ ???

This is a construct variable about $lokalDrive_G = "\\filesrv001\log$"

my target is to show if the variable $lokalDrive_A....Z has an value and when it is, then connect the network drive.

Regards
Michael


LonkeroAdministrator
(KiX Master Guru)
2012-05-24 10:11 PM
Re: variable in variable

I get you. replace these lines:
 Code:
	$LDR = ("$lokalDrive_" + $L)
	$LDRIVE = execute ('$$LDR')
	? $LDRIVE     ; This variable has the value 0 when the variable $LDR have the value "$lokaldrive_G". What can i do to become the value \\filesrv001\log$  ???
	If $LDRIVE <> NULL


with these:
 Code:
	$LDR = "$$lokalDrive_" + $L
	$junk = execute ('$$LDRIVE="'+$LDR+'"')
	? $LDRIVE     ; This variable has the value 0 when the variable $LDR have the value "$lokaldrive_G". What can i do to become the value \\filesrv001\log$  ???
	If $LDRIVE <> ""


ShaneEP
(MM club member)
2012-05-25 05:01 AM
Re: variable in variable

I like Execute().

mbwh
(Fresh Scripter)
2012-05-25 08:40 AM
Re: variable in variable

Hello,

this was the right hint.

Here is my script.

 Code:

$lokalDrive_G = "\\Server\Share"

For $Count = 65 To 90 Step 1 
	$L  = Chr ($Count)
	$LD = $L + ":"
	
	$LDR = "$$lokalDrive_" + $L
	$junk = execute ('$$LDRIVE="'+$LDR+'"')
	
	If $LDRIVE <> $LDR
		$Counter = 0
		DO
			$Counter = $Counter + 1
			If Exist ($LD) = 1
				Use $LD /Del 
				Use $LD $LDRIVE
            Else
				Use $LD $LDRIVE
            EndIf
        Until Exist($LD) = 1 or $Counter = 5
            
        If Exist ($LD) = 0
                        MessageBox ("ACHTUNG! Kein " + $L + "-Laufwerk vorhanden! Evtl. sind Sie nicht richtig am Netzwerk angemeldet.", "@TIME", 0)
                        $Error = $L + " "
        EndIf
	EndIf
Next


Thank you for all!!!

Regards
Michael


LonkeroAdministrator
(KiX Master Guru)
2012-05-25 02:44 PM
Re: variable in variable

can I ask what you are testing for here:
If $LDRIVE <> $LDR

they are always different, again.
LDR will always have "lokaldrive_" in it and LDRIVE will either be empty or have UNC.
but still they are always different.


ShaneEP
(MM club member)
2012-05-25 04:49 PM
Re: variable in variable

On a sidenote...Jooel, the '<' symbol does not show correctly when you post prep the above code.

ShaneEP
(MM club member)
2012-05-25 04:56 PM
Re: variable in variable

And I disagree. I would thank that $LDRIVE and $LDR will ALWAYS be equal. The line before the check actually sets $LDRIVE to $LDR in the execute statement. They will always be equal unless something in the execute goes wrong.

Les
(KiX Master)
2012-05-25 04:59 PM
Re: variable in variable

 Originally Posted By: Lonkero
can I ask what you are testing for here:
If $LDRIVE <> $LDR

they are always different, again.
LDR will always have "lokaldrive_" in it and LDRIVE will either be empty or have UNC.
but still they are always different.
Also, the IF is outside of the DO - UNTIL loop.


ShaneEP
(MM club member)
2012-05-25 05:00 PM
Re: variable in variable

Yeah. When I run the script...It never gets inside that first IF block.

LonkeroAdministrator
(KiX Master Guru)
2012-05-25 07:39 PM
Re: variable in variable

shane, the LDRIVE is set to the value inside LOKALDRIVE_X
LDR will always be LOKALDRIVE_X

if LOKALDRIVE_X contains \\server\share
that if will be:
 Code:
if "LOKALDRIVE_X" <> "\\server\share"


always different.


LonkeroAdministrator
(KiX Master Guru)
2012-05-25 07:41 PM
Re: variable in variable

les, what you mean also the if?
the first if is outside.


ShaneEP
(MM club member)
2012-05-25 08:12 PM
Re: variable in variable

Gotcha...My mistake. I missed the very first line of his script (before the looped script).

The weird thing is that the <> check is still needed. For some reason if LOKALDRIVE_X is never defined in the list of mappings, the execute sets it to the name of the variable, not blank.

When I run the code, they all appear equal except for the G which is the one defined at the beginning of the script. It's weird that the execute simply uses the variable name when it isnt defined.


Les
(KiX Master)
2012-05-25 08:29 PM
Re: variable in variable

 Originally Posted By: Lonkero
les, what you mean also the if?
the first if is outside.
nvm... I was confused by the indenting.


ShaneEP
(MM club member)
2012-05-25 08:37 PM
Re: variable in variable

It's something with the quotes.

Change this line:
 Code:
$junk = execute ('$$LDRIVE="'+$LDR+'"')
With this line:
 Code:
$junk = execute ('$$LDRIVE='+$LDR)


It then sets it to blank if not defined instead of to the variable name.
 Code:
$lokalDrive_G = "\\Server\Share"

For $Count = 65 To 90 Step 1 
   $L  = Chr ($Count)
   $LD = $L + ":"
   $LDR = "$$lokalDrive_" + $L
   $junk = execute ('$$LDRIVE='+$LDR)

   If $LDRIVE
      $Counter = 0
      DO
         $Counter = $Counter + 1
         If Exist ($LD) = 1
            Use $LD /Del
            Use $LD $LDRIVE
         Else
            Use $LD $LDRIVE
         EndIf
      Until Exist($LD) = 1 or $Counter = 5
      If Exist ($LD) = 0
         MessageBox ("ACHTUNG! Kein " + $L + "-Laufwerk vorhanden! Evtl. sind Sie nicht richtig am Netzwerk angemeldet.", "@TIME", 0)
         $Error = $L + " "
      EndIf
   EndIf
Next


LonkeroAdministrator
(KiX Master Guru)
2012-05-25 09:01 PM
Re: variable in variable

hmm... it sets it to blank and doesn't error?
well, I guess it will but kixtart doesn't give execute() errors so it will work.
good catch.