danielmohr91 Posted December 8, 2009 Share Posted December 8, 2009 I've been trying to learn how to use ini files. I'm doing alright, but I'm stuck at the FileSaveDialog() command. This is probably something simple I'm overlooking, but it's not saving the file with the .ini extension at the end. $file = FileSaveDialog("Save As...", @ScriptDir, "All (*.ini)" Am I doing something wrong, or is this a limitation of the program. It doesn't place the .ini at the end of my file name. Here's my whole script if you're curious. I just wrote it for practice, and to learn how to use .ini files. expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form=d:\documents\farmville bot\ini practice.kxf $Form1_1 = GUICreate("Form1", 275, 273, 192, 124) $NewFile = GUICtrlCreateButton("File", 16, 16, 241, 49, $WS_GROUP) $InputX = GUICtrlCreateInput("", 40, 96, 137, 21) $SaveX = GUICtrlCreateButton("SaveX", 32, 120, 145, 33, $WS_GROUP) $InputY = GUICtrlCreateInput("", 40, 184, 137, 21) $SaveY = GUICtrlCreateButton("SaveY", 32, 208, 145, 33, $WS_GROUP) $X = GUICtrlCreateLabel("X", 32, 96, 11, 17) $Y = GUICtrlCreateLabel("Y", 32, 184, 11, 17) GUICtrlCreateGroup("", 16, 72, 241, 89) GUICtrlCreateGroup("", -99, -99, 1, 1) GUICtrlCreateGroup("", 16, 168, 241, 89) GUICtrlCreateGroup("", -99, -99, 1, 1) $DeleteX = GUICtrlCreateButton("DeleteX", 192, 120, 49, 33, $WS_GROUP) $DeleteY = GUICtrlCreateButton("DeleteY", 192, 216, 49, 33, $WS_GROUP) $ReadX = GUICtrlCreateButton("ReadX", 192, 88, 49, 33, $WS_GROUP) $ReadY = GUICtrlCreateButton("ReadY", 192, 184, 49, 33, $WS_GROUP) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $file = "Practice.ini" While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $NewFile $ans = MsgBox(4, "File", "File is " & $file & " and is in the script directry. Would you save to a new file location?") If $ans = 6 Then $file = FileSaveDialog("Save As...", @ScriptDir, "All (*.ini)") Case $SaveX one() Case $SaveY two() Case $DeleteX DeleteX() Case $DeleteY DeleteY() Case $ReadX ReadX() Case $ReadY ReadY() EndSwitch WEnd Func defualt() TrayTip("It worked", "Button acknowledged", 10) IniWrite($file, "Section", "Key", "Value") EndFunc ;==>defualt Func One() $val = GUICtrlRead($InputX) IniWrite($file, "SectionX", "$x", $val) TrayTip("It worked", "Button acknowledged. " & $val & " was written to file", 10) EndFunc ;==>One Func Two() TrayTip("It worked", "Button acknowledged", 10) $val = GUICtrlRead($InputY) IniWrite($file, "SectionY", "$y", $val) EndFunc ;==>Two Func DeleteX() IniDelete($file, "SectionX", "") EndFunc ;==>DeleteX Func DeleteY() IniDelete($file, "SectionY", "") EndFunc ;==>DeleteY Func ReadX() $msg = IniRead($file, "SectionX", "$x", "ERROR: Not Found.") MsgBox(32, "Section X", $msg) EndFunc ;==>ReadX Func ReadY() $msg = IniRead($file, "SectionY", "$y", "ERROR: Not Found.") MsgBox(32, "Section Y", $msg) EndFunc ;==>ReadY Link to comment Share on other sites More sharing options...
danielmohr91 Posted December 9, 2009 Author Share Posted December 9, 2009 Anyone? Link to comment Share on other sites More sharing options...
funkey Posted December 9, 2009 Share Posted December 9, 2009 expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form=d:\documents\farmville bot\ini practice.kxf $Form1_1 = GUICreate("Form1", 275, 273, 192, 124) $NewFile = GUICtrlCreateButton("File", 16, 16, 241, 49, $WS_GROUP) $InputX = GUICtrlCreateInput("", 40, 96, 137, 21) $SaveX = GUICtrlCreateButton("SaveX", 32, 120, 145, 33, $WS_GROUP) $InputY = GUICtrlCreateInput("", 40, 184, 137, 21) $SaveY = GUICtrlCreateButton("SaveY", 32, 208, 145, 33, $WS_GROUP) $X = GUICtrlCreateLabel("X", 32, 96, 11, 17) $Y = GUICtrlCreateLabel("Y", 32, 184, 11, 17) GUICtrlCreateGroup("", 16, 72, 241, 89) GUICtrlCreateGroup("", -99, -99, 1, 1) GUICtrlCreateGroup("", 16, 168, 241, 89) GUICtrlCreateGroup("", -99, -99, 1, 1) $DeleteX = GUICtrlCreateButton("DeleteX", 192, 120, 49, 33, $WS_GROUP) $DeleteY = GUICtrlCreateButton("DeleteY", 192, 216, 49, 33, $WS_GROUP) $ReadX = GUICtrlCreateButton("ReadX", 192, 88, 49, 33, $WS_GROUP) $ReadY = GUICtrlCreateButton("ReadY", 192, 184, 49, 33, $WS_GROUP) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $file = @ScriptDir & "\Practice.ini" Global $SaveFile While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $NewFile $ans = MsgBox(4, "File", "File is " & $file & " and is in the script directry. Would you save to a new file location?") If $ans = 6 Then $SaveFile = FileSaveDialog("Save As...", @ScriptDir, "All (*.ini)") If Not @error Then If StringRight($SaveFile, 4) = ".ini" Then $file = $SaveFile Else $file = $SaveFile & ".ini" EndIf EndIf EndIf Case $SaveX one() Case $SaveY two() Case $DeleteX DeleteX() Case $DeleteY DeleteY() Case $ReadX ReadX() Case $ReadY ReadY() EndSwitch WEnd Func defualt() TrayTip("It worked", "Button acknowledged", 10) IniWrite($file, "Section", "Key", "Value") EndFunc ;==>defualt Func One() $val = GUICtrlRead($InputX) IniWrite($file, "SectionX", "$x", $val) TrayTip("It worked", "Button acknowledged. " & $val & " was written to file", 10) EndFunc ;==>One Func Two() TrayTip("It worked", "Button acknowledged", 10) $val = GUICtrlRead($InputY) IniWrite($file, "SectionY", "$y", $val) EndFunc ;==>Two Func DeleteX() IniDelete($file, "SectionX", "") EndFunc ;==>DeleteX Func DeleteY() IniDelete($file, "SectionY", "") EndFunc ;==>DeleteY Func ReadX() $msg = IniRead($file, "SectionX", "$x", "ERROR: Not Found.") MsgBox(32, "Section X", $msg) EndFunc ;==>ReadX Func ReadY() $msg = IniRead($file, "SectionY", "$y", "ERROR: Not Found.") MsgBox(32, "Section Y", $msg) EndFunc ;==>ReadY Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning. Link to comment Share on other sites More sharing options...
danielmohr91 Posted December 11, 2009 Author Share Posted December 11, 2009 (edited) expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form=d:\documents\farmville bot\ini practice.kxf $Form1_1 = GUICreate("Form1", 275, 273, 192, 124) $NewFile = GUICtrlCreateButton("File", 16, 16, 241, 49, $WS_GROUP) $InputX = GUICtrlCreateInput("", 40, 96, 137, 21) $SaveX = GUICtrlCreateButton("SaveX", 32, 120, 145, 33, $WS_GROUP) $InputY = GUICtrlCreateInput("", 40, 184, 137, 21) $SaveY = GUICtrlCreateButton("SaveY", 32, 208, 145, 33, $WS_GROUP) $X = GUICtrlCreateLabel("X", 32, 96, 11, 17) $Y = GUICtrlCreateLabel("Y", 32, 184, 11, 17) GUICtrlCreateGroup("", 16, 72, 241, 89) GUICtrlCreateGroup("", -99, -99, 1, 1) GUICtrlCreateGroup("", 16, 168, 241, 89) GUICtrlCreateGroup("", -99, -99, 1, 1) $DeleteX = GUICtrlCreateButton("DeleteX", 192, 120, 49, 33, $WS_GROUP) $DeleteY = GUICtrlCreateButton("DeleteY", 192, 216, 49, 33, $WS_GROUP) $ReadX = GUICtrlCreateButton("ReadX", 192, 88, 49, 33, $WS_GROUP) $ReadY = GUICtrlCreateButton("ReadY", 192, 184, 49, 33, $WS_GROUP) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $file = @ScriptDir & "\Practice.ini" Global $SaveFile While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $NewFile $ans = MsgBox(4, "File", "File is " & $file & " and is in the script directry. Would you save to a new file location?") If $ans = 6 Then $SaveFile = FileSaveDialog("Save As...", @ScriptDir, "All (*.ini)") If Not @error Then If StringRight($SaveFile, 4) = ".ini" Then $file = $SaveFile Else $file = $SaveFile & ".ini" EndIf EndIf EndIf Case $SaveX one() Case $SaveY two() Case $DeleteX DeleteX() Case $DeleteY DeleteY() Case $ReadX ReadX() Case $ReadY ReadY() EndSwitch WEnd Func defualt() TrayTip("It worked", "Button acknowledged", 10) IniWrite($file, "Section", "Key", "Value") EndFunc ;==>defualt Func One() $val = GUICtrlRead($InputX) IniWrite($file, "SectionX", "$x", $val) TrayTip("It worked", "Button acknowledged. " & $val & " was written to file", 10) EndFunc ;==>One Func Two() TrayTip("It worked", "Button acknowledged", 10) $val = GUICtrlRead($InputY) IniWrite($file, "SectionY", "$y", $val) EndFunc ;==>Two Func DeleteX() IniDelete($file, "SectionX", "") EndFunc ;==>DeleteX Func DeleteY() IniDelete($file, "SectionY", "") EndFunc ;==>DeleteY Func ReadX() $msg = IniRead($file, "SectionX", "$x", "ERROR: Not Found.") MsgBox(32, "Section X", $msg) EndFunc ;==>ReadX Func ReadY() $msg = IniRead($file, "SectionY", "$y", "ERROR: Not Found.") MsgBox(32, "Section Y", $msg) EndFunc ;==>ReadY Brilliant! Thank you so much for your help. I read up on StringRight. I never would have found that on my own. Thanks funkey! Edited December 11, 2009 by danielmohr91 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now