Page 1 of 2 12>
Topic Options
#205307 - 2012-05-23 10:00 AM variable in variable
mbwh Offline
Fresh Scripter

Registered: 2012-03-08
Posts: 5
Loc: Germany
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

Top
#205308 - 2012-05-23 11:27 AM Re: variable in variable [Re: mbwh]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4667
Loc: The Netherlands
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?
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#205311 - 2012-05-23 04:40 PM Re: variable in variable [Re: Mart]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2099
Loc: Tulsa, OK
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.
Top
#205312 - 2012-05-24 10:07 AM Re: variable in variable [Re: ShaneEP]
mbwh Offline
Fresh Scripter

Registered: 2012-03-08
Posts: 5
Loc: Germany
Hello,

oh sorry, i mean right!

With Execute ()???

Regards
Michael

Top
#205314 - 2012-05-24 11:41 AM Re: variable in variable [Re: mbwh]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4667
Loc: The Netherlands
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 


Edited by Mart (2012-05-24 11:42 AM)
Edit Reason: typo
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#205317 - 2012-05-24 03:31 PM Re: variable in variable [Re: mbwh]
mbwh Offline
Fresh Scripter

Registered: 2012-03-08
Posts: 5
Loc: Germany
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


Edited by Mart (2012-05-24 04:56 PM)
Edit Reason: Please use code tags when posting code.

Top
#205321 - 2012-05-24 08:31 PM Re: variable in variable [Re: mbwh]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22344
Loc: OK
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.
_________________________
!

download KiXnet

Top
#205322 - 2012-05-24 09:19 PM Re: variable in variable [Re: Lonkero]
mbwh Offline
Fresh Scripter

Registered: 2012-03-08
Posts: 5
Loc: Germany
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

Top
#205323 - 2012-05-24 10:11 PM Re: variable in variable [Re: mbwh]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22344
Loc: OK
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 <> ""
_________________________
!

download KiXnet

Top
#205324 - 2012-05-25 05:01 AM Re: variable in variable [Re: Lonkero]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2099
Loc: Tulsa, OK
I like Execute().
Top
#205325 - 2012-05-25 08:40 AM Re: variable in variable [Re: ShaneEP]
mbwh Offline
Fresh Scripter

Registered: 2012-03-08
Posts: 5
Loc: Germany
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

Top
#205326 - 2012-05-25 02:44 PM Re: variable in variable [Re: mbwh]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22344
Loc: OK
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.
_________________________
!

download KiXnet

Top
#205327 - 2012-05-25 04:49 PM Re: variable in variable [Re: Lonkero]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2099
Loc: Tulsa, OK
On a sidenote...Jooel, the '<' symbol does not show correctly when you post prep the above code.
Top
#205328 - 2012-05-25 04:56 PM Re: variable in variable [Re: ShaneEP]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2099
Loc: Tulsa, OK
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.
Top
#205329 - 2012-05-25 04:59 PM Re: variable in variable [Re: Lonkero]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
 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.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#205330 - 2012-05-25 05:00 PM Re: variable in variable [Re: Les]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2099
Loc: Tulsa, OK
Yeah. When I run the script...It never gets inside that first IF block.
Top
#205332 - 2012-05-25 07:39 PM Re: variable in variable [Re: ShaneEP]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22344
Loc: OK
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.
_________________________
!

download KiXnet

Top
#205333 - 2012-05-25 07:41 PM Re: variable in variable [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22344
Loc: OK
les, what you mean also the if?
the first if is outside.
_________________________
!

download KiXnet

Top
#205334 - 2012-05-25 08:12 PM Re: variable in variable [Re: Lonkero]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2099
Loc: Tulsa, OK
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.


Attachments
280.jpg
Description:



Top
#205335 - 2012-05-25 08:29 PM Re: variable in variable [Re: Lonkero]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
 Originally Posted By: Lonkero
les, what you mean also the if?
the first if is outside.
nvm... I was confused by the indenting.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
Page 1 of 2 12>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 312 anonymous users online.
Newest Members
Praveer, Ollero, rayyo, Foxlicht, DonChild
17742 Registered Users

Generated in 0.044 seconds in which 0.012 seconds were spent on a total of 15 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org