Page 1 of 1 1
Topic Options
#48037 - 1999-08-12 09:27 PM Combining variables to make one variable?
Anonymous
Unregistered


Hi ppl.

I have tried like heck to create a variable which is composed of the value of 2 other variables. I understand the difference between strings and numerical values, but am having no luck. (This is Kix v 3.51)

Ideally I want to say:

$x = really
$y = not-so
$z = not-at-all
$a = stupid

($x$a) = Function(...)
($y$a) = Function(...)
($z$a) = Function(...)

($x$a)= $situation1
? "First is: " $situation1

And have it return "reallystupid"

And ideally also to mix numerical and text strings in order to be able to increment the numbers as I move through the script.

I've tried every combo I can think of using plus signs, spaces, brackets, ellipses... to combine the two variables into one.

THANKS
-Harold
<morelife@stealth.net>


------------------

Top
#48038 - 1999-08-19 08:33 AM Re: Combining variables to make one variable?
Anonymous
Unregistered


Try:
[CODE}
$string = "string"
$value = 1

$total = $string + $value
? " Loop 1 $total "

$value = $value + 1

$total = $string + $value
? " Loop 2 $total "
[/CODE]

------------------
Lon Geefshuysen (MCP)
kixtart.to/lon
lon@kixtart.to


Top
#48039 - 1999-08-21 03:21 PM Re: Combining variables to make one variable?
Anonymous
Unregistered


Strangely enough, I found myself trying the very same thing this weekend whilst drinking a couple cold ones up at the cottage.

I am trying to create a very simple array where each element contains a string of text from each line of a file. I am first running "shell "%comspec% /c dir /ad /b > d:\doit.hlp"" to spit out a list of directories from which a user can choose one. I want to load each line into one array element, display it, and allow a user to select an element (by number).

Seemingly, I am having troubles with the syntax. So far, I have:

*****************************
open(2, "d:\doit.hlp", 2)
$cntr = 0
while @error = 0
$cntr = $cntr + 1
$tmpary = readline(2)
$xxx = "$rdln" + $cntr
? "XXX equals: " + $xxx <<returns things like $rdln1>>
"$" + "rdln" + $cntr = $tmpary
? "Array variable is:" + $xxx
? "Line #" + $cntr + " contains: " + $tmpary <<returns the desired dir. names>>
loop
close(2)
*****************************

How can I create an array?!? I wanted my array to contain values such as:

$rdln1 = dir1
$rdln2 = dir2
$rdln3 = dir3

Anybody?

TIA,

../mk

Top
#48040 - 1999-08-22 10:52 AM Re: Combining variables to make one variable?
Anonymous
Unregistered


Not that I like to reply to my own posts, I have have a new summary for the problem I am having.

I can't seem to assign variables to variables. For example:

$total = "$" + "array" + $cntr
--or--
"$" + "array" + $cntr = $tmpval

Can this be done (implementing a quasi array?)

TIA,

../mk

Top
#48041 - 1999-08-25 08:57 PM Re: Combining variables to make one variable?
Anonymous
Unregistered


Forgive my LONG delay in getting to the answers both Lon and MK posted.

Lon: thanks for answering this, but I phrased my original question poorly.

From my original post:
----------------------
($x$a) = Function()
($x$a)= $situation1
? "First is: " $situation1
And have it return "reallystupid"
----------------------

** but somehow keeping the value somewhere of Function(). Well I guess it's impossible.

But if anyone has ideas...

If it's any consolation, MK, I expanded a little on the code you posted, and came up with something that does produce a list that you can then present as a menu choice (so the user can choose the directory they want). If you then expand on that, perhaps you can share the code and how you used it. Thanks to all!

-Harold
---------------------------------------------

cls
break on


$workdir = C:\tester
$listfile = C:\tester\DOIT.HLP

$composite = C:\tester\dirbuild.txt

if exist("$workdir\nul") goto "SUB1" endif
shell "%comspec% /c mkdir $workdir"

:sub1
if exist($composite) del "$composite" endif
if exist($listfile) del "$listfile" endif
shell "%comspec% /c dir C:\ /ad /b > $listfile"
color Y/n
cls
? "Starting ... "

$o1 = open(1,"$composite",5)
$o2 = open(2,"$listfile")
$cntr = 0

while @error = 0
$cntr = $cntr + 1
$tmpary = readline(2)
$xxx = "$rdln" + $cntr

? "XXX equals: " + $xxx
? "Array variable is: " + $xxx
? "Line #" + $cntr + " contains: " + $tmpary
if $tmpary > 0
writeline(1, " $cntr. $tmpary" + chr(10) + chr(13))
endif
loop

close(2)
color G+/n
cls

? "-------------------------------------"
? "Choose from the list: "
? "-------------------------------------"

? "Here you would display a file and do a get..."
? "Look at the file in a shell using more<c:\tester\dirbuild.txt"
? "(notepad can't handle the extended characters)."



Top
#48042 - 1999-08-27 10:28 AM Re: Combining variables to make one variable?
Anonymous
Unregistered


Harold,

Thanks for the code. That problem bugged me a bit so I came up with a slightly different angle of attack that night. Technically, it may not be the most efficient (though it makes better use of memory), but this is splitting hairs, especially for the application of this script!

My whole script is now approximately 4 pages long. It is used to migrate user's data from one machine to another as our sales force is getting new notebooks. The script determines if the machine is a new one or old one, and simply does file copying. Here is the part that determines what 'machines' are available on a Jazz tape (many machines can exist on a single tape organised by user name) and renames the machine name as per our naming convention.

I tried to have the script determine the last directory created so that I could have that as the default, but it seems that 'comparefiletimes' only works on files.

If anyone sees any room for improvement, please do give it up!

../mk (Marc Knoop)

***********************

$hlpfl = "doit.hlp"
shell "%comspec% /c dir /ad /b > $drv$hlpfl"

$null = open(2, "$drv$hlpfl", 2)
$cntr = 0
while @error = 0
$cntr = $cntr + 1
$tmpval = readline(2)
if $tmpval="RECYCLED" or $tmpval=""
$cntr = $cntr - 1
else
at ($cntr+5,2) $cntr
at ($cntr+5,5) $tmpval
endif
loop
$null = close(2)
at (20,2) "Please choose a directory to copy to target machine (enter #)..."

if $cntr < 10
$tmp = 10
while $tmp > $cntr
at (24,75) get $tmp
loop
else
color r/n box(22,32,24,36,full)
color w/n
$tmp = 100
while $tmp > $cntr
at (23,33) gets $tmp
loop
endif
$null = open(2, "$drv$hlpfl", 2)
$cntr = 0
while @error = 0
$cntr = $cntr + 1
$tmpval = readline(2)
if $tmpval="RECYCLED" or $tmpval=""
$cntr = $cntr - 1
endif
if $cntr = $tmp
$uname = ucase($tmpval)
$null = close(2)
goto GOTIT
endif
loop

:GOTIT
$null = writevalue("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\VxD\VNETSUP", "ComputerName", "RMSMWP$uname", "REG_SZ")
$null = writevalue("HKEY_LOCAL_MACHINE\System\CurrentControlSet\control\ComputerName\ComputerName", "ComputerName", "RMSMWP$uname", "REG_SZ")

Top
Page 1 of 1 1


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

Who's Online
0 registered and 302 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.05 seconds in which 0.022 seconds were spent on a total of 12 queries. Zlib compression enabled.

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