Jump to content

Reading Script From Seperate File


Recommended Posts

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:

Link to comment
Share on other sites

  • Developers

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)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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)
Link to comment
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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
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)

Link to comment
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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...