Sign in to follow this  
Followers 0
Hylia

Iniwrite() problem

15 posts in this topic

I'm wondering why it won't write the ini file I think I'm doing everything correctly? (Complete script in spoiler)

Case $msg = $Save
IniWrite("Vars.ini", "Variables", "X", $X[5])

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#Region ### START Koda GUI section ###
$Form1_1 = GUICreate("Form1_1", 170, 135, 222, 464)
$Save = GUICtrlCreateMenu("Save")
$hX = GUICtrlCreateInput("pos[0]", 16, 16, 49, 21)
$hY = GUICtrlCreateInput("pos[1]", 104, 16, 49, 21)
$MouseCoordX = GUICtrlCreateInput("-1", 16, 96, 49, 21)
$MouseCoordY = GUICtrlCreateInput("-1", 104, 96, 49, 21)
$N = GUICtrlCreateInput("1", 64, 56, 33, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

;pre-declare x & y

local $X[5]
local $Y[5]

;pre-declare end


HotKeySet("{SPACE}", "Var")

While 1

$nSet = GUICtrlRead($N)

$pos = MouseGetPos()
GUICtrlSetData($hX, $pos[0])
GUICtrlSetData($hY, $pos[1])

If $nSet > 0 then
GUICtrlSetData($MouseCoordX, $x[$nSet])
GUICtrlSetData($MouseCoordY, $y[$nSet])
EndIf


$Msg = GUIGetMsg()
Select

Case $msg = $GUI_EVENT_CLOSE
GUIDelete()
fileDelete(@tempDir & "\image9.jpg")
ExitLoop
Exit

Case $msg = $Save
IniWrite("Vars.ini", "Variables", "X", $X[5])

EndSelect

WEnd

Func Var()

If $nSet > 0 then
$x[$nSet] = $pos[0]
$y[$nSet] = $pos[1]
GUICtrlSetData($N, $nSet + 1)

EndIf

EndFunc

Share this post


Link to post
Share on other sites



The file could be read-only.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

try to set the full path to the ini file

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

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Tried both, File is not read-only, folder also isn't read-only, tried both running as admin and without, also tried with path specified nothing. (and yes, it's with a compiled file)

Edited by Hylia

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Are you saying it works when not compiled? You are trying to write a value that can't exist => $x[5]

Edited by czardas

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Are you saying it works when not compiled? You are trying to write a value that can't exist => $x[5]

No, it doesn't.

I want it to write all 5 of the $X[5] to write.

Edited by Hylia

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

$x only contains 5 elements as shown:

$x[0]

$x[1]

$x[2]

$x[3]

$x[4]

I want it to write all 5 of the $X[5] to write.

Write a separate entry for each element that exists. Edited by czardas

Share this post


Link to post
Share on other sites

$x only contains 5 elements:

$x[0]

$x[1]

$x[2]

$x[3]

$x[4]

Oh didn't know that [0] was also considered one.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

ok...got some 9999999999999999 unknoun code there

i second please

For $i = 1 To 5
IniWrite("Vars.ini", "Variables", "X", $X[$i])
next
Edited by HeavenlyDemon

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Changed it to $X[1] still no file is created. :S

Can someone give me something to compile to see if it's my computer?

V current thing I'm compiling

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#Region ### START Koda GUI section ###
$Form1_1 = GUICreate("Form1_1", 170, 135, 222, 464)
$Save = GUICtrlCreateMenu("Save")
$hX = GUICtrlCreateInput("pos[0]", 16, 16, 49, 21)
$hY = GUICtrlCreateInput("pos[1]", 104, 16, 49, 21)
$MouseCoordX = GUICtrlCreateInput("-1", 16, 96, 49, 21)
$MouseCoordY = GUICtrlCreateInput("-1", 104, 96, 49, 21)
$N = GUICtrlCreateInput("1", 64, 56, 33, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

;pre-declare x & y

local $X[5]
local $Y[5]

;pre-declare end


HotKeySet("{SPACE}", "Var")

While 1

$nSet = GUICtrlRead($N)

$pos = MouseGetPos()
GUICtrlSetData($hX, $pos[0])
GUICtrlSetData($hY, $pos[1])

If $nSet > 0 then
GUICtrlSetData($MouseCoordX, $x[$nSet])
GUICtrlSetData($MouseCoordY, $y[$nSet])
EndIf


$Msg = GUIGetMsg()
Select

Case $msg = $GUI_EVENT_CLOSE
GUIDelete()
fileDelete(@tempDir & "\image9.jpg")
ExitLoop
Exit

Case $msg = $Save
IniWrite("C:\Temp\Vars.ini", "Variables", "X", $X[1])

EndSelect

WEnd

Func Var()

If $nSet > 0 then
$x[$nSet] = $pos[0]
$y[$nSet] = $pos[1]
GUICtrlSetData($N, $nSet + 1)

EndIf

EndFunc

Edited by Hylia

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

So I put a message box after the IniWrite() and it never popped up when I clicked save. So that means the code is never even reaching that line.

I replaced the "Save" bar button with a regular button and it reaches the line, but $X[5] exceeds the variable's array range, which means $X's array is smaller than 5. I changed the number to 2 and it worked.

EDIT: Here is your edited code:

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#Region ### START Koda GUI section ###
$Form1_1 = GUICreate("Form1_1", 170, 135, 222, 464)
;$Save = GUICtrlCreateMenu("Save")
$Save = GUICtrlCreateButton("TEST", 10, 10, 30, 30)
$hX = GUICtrlCreateInput("pos[0]", 16, 16, 49, 21)
$hY = GUICtrlCreateInput("pos[1]", 104, 16, 49, 21)
$MouseCoordX = GUICtrlCreateInput("-1", 16, 96, 49, 21)
$MouseCoordY = GUICtrlCreateInput("-1", 104, 96, 49, 21)
$N = GUICtrlCreateInput("1", 64, 56, 33, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

;pre-declare x & y

local $X[5]
local $Y[5]

;pre-declare end


HotKeySet("{SPACE}", "Var")

While 1

$nSet = GUICtrlRead($N)

$pos = MouseGetPos()
GUICtrlSetData($hX, $pos[0])
GUICtrlSetData($hY, $pos[1])

If $nSet > 0 then
GUICtrlSetData($MouseCoordX, $x[$nSet])
GUICtrlSetData($MouseCoordY, $y[$nSet])
EndIf


$Msg = GUIGetMsg()
Select

Case $msg = $GUI_EVENT_CLOSE
GUIDelete()
fileDelete(@tempDir & "\image9.jpg")
ExitLoop
Exit

Case $msg = $Save
IniWrite("Vars.ini", "Variables", "X", $X[2])
MsgBox(64, "TEST", "MADE IT HERE")

EndSelect

WEnd

Func Var()

If $nSet > 0 then
$x[$nSet] = $pos[0]
$y[$nSet] = $pos[1]
GUICtrlSetData($N, $nSet + 1)

EndIf

EndFunc
Edited by Rux

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

The problem is here => GUICtrlCreateMenu. This menu has no items to click on. If you replace that with a button (or add a menu item that can receive clicks using GUICtrlCreateMenuItem), it will create the ini. There is currently no message being received.

Edited by czardas

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Rux, awesome, thanks a lot! and czardas I'll try that.

Edited by Hylia

Share this post


Link to post
Share on other sites

No problem.

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