Sign in to follow this  
Followers 0
Anuin

Reading Script From Seperate File

10 posts in this topic

This is a tough question for me cause i have 0 programing knowledge, besides learning some auto it.

Anyway, I was wondering if its possible to read a command or variable from a seperate file.

IE. Have on one file:

$a = $b

and on the second file, store:

$b = 54

what im trying to do is save mouse coordinates in a seperate file so that when the the script loads up again you dont have to re -input the coordinates again unless you want to. :whistle:

Share this post


Link to post
Share on other sites



the best way to save info is probably saving it into a INI file.

IniWrite("C:\Temp\myfile.ini", "section2", "key", "this is a new value")

$var = IniRead("C:\Temp\myfile.ini", "section2", "key", "NotFound")
MsgBox(4096, "Result", $var)

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Thanks Man!!!

Exactly what i was looking for. You saved me from a world of frustration

:whistle:

Share this post


Link to post
Share on other sites

I have another problem. Everything seems to be working fine, but cant get the mouse position to store mabe my code is wrong.

Ive Tried

$toolset = MsgBox(4, "Toolbar Settings", "Change the Toolbar Settings")

If $toolset = 6 Then
$pos1 = MouseGetPos()
IniWrite("MouseSetting2.ini", "Mouse", "Mouse1", $pos1[0],$pos1[1])
EndIf

$pos1 = iniread("MouseSetting2.ini", "Mouse", "Mouse1", ($pos1[0],$pos1[1]) )
MsgBox(4096, "Result", $pos1)

And also:

$toolset = MsgBox(4, "Toolbar Settings", "Change the Toolbar Settings")

If $toolset = 6 Then
$pos1 = MouseGetPos()
IniWrite("MouseSetting2.ini", "Mouse", "Mouse1", $pos1)
EndIf

$pos1 = iniread("MouseSetting2.ini", "Mouse", "Mouse1", $pos1)
MsgBox(4096, "Result", $pos1)

Share this post


Link to post
Share on other sites

Sorry made mistake. The firstone goes:

$toolset = MsgBox(4, "Toolbar Settings", "Change the Toolbar Settings")

If $toolset = 6 Then
$pos1 = MouseGetPos()
IniWrite("MouseSetting2.ini", "Mouse", "Mouse1", $pos1[0],$pos1[1])
EndIf

$pos1 = iniread("MouseSetting2.ini", "Mouse", "Mouse1", $pos1[0],$pos1[1] )
MsgBox(4096, "Result", $pos1)

And yes ive tried it with brackets as well

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Ini read and write use one bit of information, you placed in both $pos1[0] and $pos1[1] on the same line seperated by a comma, and thus not the correct number of parameters.

$toolset = MsgBox(4, "Toolbar Settings", "Change the Toolbar Settings")
If $toolset = 6 Then
$pos1 = MouseGetPos()
IniWrite("MouseSetting2.ini", "Mouse", "Mouse1", $pos1[0])
IniWrite("MouseSetting2.ini", "Mouse", "Mouse2", $pos1[1])
EndIf
dim $pos1[2]

$pos1[0] = iniread("MouseSetting2.ini", "Mouse", "Mouse1", 0 )
$pos1[1] = iniread("MouseSetting2.ini", "Mouse", "Mouse2", 0)

MsgBox(4096, "Result", $pos1[0]&@CRLF&$pos1[1])
Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Ini files can only store one value per element, so use two elements, e.g.

IniWrite("MouseSetting2.ini", "Mouse", "MouseX", $pos1[0])
IniWrite("MouseSetting2.ini", "Mouse", "MouseY", $pos1[1])

Edit: ScriptKitty got in there first, chiz :whistle:

Edited by GrahamS

GrahamS

Share this post


Link to post
Share on other sites

Thanks Allot Guys, works like its supposta

Share this post


Link to post
Share on other sites

And then there's this idea (I got from TextPad I think? :whistle: ) ..

$pos1 = MouseGetPos()
IniWrite("MouseSetting2.ini", "Mouse", "MouseXY", $pos1[0] & " " & $pos1[1])

This means you can do a StringSplit when you read it back..

$sPos = IniRead("MouseSetting2.ini", "Mouse", "MouseXY", "0 0")
$aPos = StringSplit($sPos, " ")

Granted, you're not saving any code for MouseGetPos, and you're only saving one line in the INI file ... but ... think how this technique works on say WinGetPos which has 4 items to store and read back B)

Share this post


Link to post
Share on other sites

Yea, one of the main reasons for an array is to be able to dynamically call out dimentions in an array.

You can store InI files many ways. :whistle:

Here is a sloppy example, I personally would remove the first , but shown more simply in this example.

$toolset = MsgBox(4, "Toolbar Settings", "Change the Toolbar Settings")
If $toolset = 6 Then
$pos1 = MouseGetPos()

for $i=0 to 1
$pos=$pos&","&$pos1[$i]
next

IniWrite("MouseSetting2.ini", "Mouse", "Mouse1", $pos)
EndIf

$split=(iniread("MouseSetting2.ini", "Mouse", "Mouse1", 0 ))
$pos1= StringSplit($split,","); shown in two lines only for ease of viewing.

MsgBox(4096, "Result", $pos1[2]&@CRLF&$pos1[3])

AutoIt3, the MACGYVER Pocket Knife for computers.

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  
Followers 0