Q #1: I have a script:
; ======= Scriptlet Starts Here
=======
setenv, Sample, AutoIt
setenv, a, Sample
stringleft, \%a\%, a, 1, 8
MsgBox, 0, AutoIt, Sample =
%Sample%; a = %a%
stringleft, %a%, a, 1, 8
MsgBox, 0, AutoIt, Sample =
%Sample%; a = %a%
; ======= Scriptlet Ends Here
=======
After second stringleft content of
Sample - "AutoIt" converts
into "S". Why?
--------------------------------------------------------------
A #1: The syntax of Stringleft is:
StringLeft,<Output
Variable>,<Input Variable>,<# of chars to extract>
so why do you have the '1' and the
'8' when there is supposed
to be only one number?
here is what you are actually doing
the first stringleft command is
setting an environment variable
'%a%' Not 'a' but a completely different variable.
Unfortunately, you cannot retrieve this variable.
In the second stringleft command:
stringleft, %a%, a, 1, 8
the %a% is converted to
'Sample' and given the first character
of the variable 'a' (a=Sample, first
char=s)
what you are really saying in Pseudo
Basic is
%a%=left(a,1)
which is like saying
Sample=left("Sample",1)
which is like saying
Sample="S"
Which is what you got.
---------------------------------------------------------------------
I added two lines to correct content
Sample:
; ======= Scriptlet Starts Here
=======
setenv, Sample, AutoIt
setenv, a, Sample
stringleft, \%a\%, a, 1, 8
MsgBox, 0, AutoIt, Sample =
%Sample%; a = %a%
stringleft, %a%, a, 1, 8
MsgBox, 0, AutoIt, Sample = %Sample%; a = %a%
stringreplace, %a%, a, S, AutoIt
MsgBox, 0, AutoIt, Sample =
%Sample%; a = %a%
; ======= Scriptlet Ends Here
=======
but have "AutoItample"?
You are misunderstanding the
commands
After the line
stringleft, %a%, a, 1, 8
a = Sample
Sample = S
the next line:
stringreplace, %a%, a, S, AutoIt
becomes
stringreplace, Sample, a, S, AutoIt
which is equivalent to (in Basic)
Sample=
replace(a,"S","AutoIt")
which evaluates to
Sample = replace("Sample","S","AutoIt")
which evaluates to
Sample = AutoItample
Your command is saying: replace all
"S" in the variable a with the
word "AutoIt" and put the
result in the variable Sample.
---------------------------------------------------------------------
If the last two lines are changed
to:
; ======= Scriptlet Starts Here
=======
setenv, Sample, AutoIt
setenv, a, Sample
stringleft, \%a\%, a, 1, 8
MsgBox, 0, AutoIt, Sample =
%Sample%; a = %a%
stringleft, %a%, a, 1, 8
MsgBox, 0, AutoIt, Sample = %Sample%; a = %a%
stringreplace, %a%, %a%, S, AutoIt
MsgBox, 0, AutoIt, Sample =
%Sample%; a = %a%
; ======= Scriptlet Ends Here
=======
The script works the way it was
intended.
-----------------------------------------------------------------------------
Q #2: I know it is possible to use DOS
variables in Autoit by refering to
them between percentage symbols, but
how do you export an AutoIt
variable to DOS?
I've tried the following script to
discover the currently logged in
user:
RegRead, AUsername, REG_SZ,
HKEY_LOCAL_MACHINE, Network\\Logon, username
run, %comspec% /c set
username=%Ausername%
---------------------------------------------------------------------
A #1: The variable you are setting exists
only within the %comspec% session
in which it is created and
disappears immediately when %comspec%
terminates, which in this case is as
soon as the SET command is
executed. What you are trying to do is create the variable in the
*global* environment, and the way to
do that differs depending on
the platform: On Win9x, you must use the WinSet utility
(available
on the Win9x CD-ROM). On WinNT/2000,
you must use the SetX utility
available in the NT or 2000 Resource
Kit. You can launch both of
these utilities from within AutoIt
(using Run or RunWait).
---------------------------------------------------------------------
A #2: You can discover the currently
logged-in ID by executing the command
NET CONFIG in a DOS box.
---------------------------------------------------------------------
A #3: In Windows NT & 2000, there is
already a variable with the username
in it. I believe it is %username%.