Jump to content
Sign in to follow this  
Maffe811

Check if file exist and then take it from there...

Recommended Posts

A function is never a variable.

A variable just stores some value

A function executes a set of commands and it may or may not return values.

Example: func add($a, $:huh2:

return $a+$b

endfunc

Here Func add return the sum of variables a & b.

Share this post


Link to post
Share on other sites

Just a word of caution, it will only return 1 if the ini file doesn't contain anything in the section specified in the the $section variable, and nothing in the key pointed to by $var. If it does contain something in them, you will get the value from the key and not 1 (unless that key holds the value of 1).

#include <WarUDF.au3>
$var = WarUdf(@AppDataDir & "\Program","test.ini","variable","section")
MsgBox(0,"",$var) ; first run through
iniwrite(@appdatadir & "\Program\test.ini", "section", "variable", "value")
$var = WarUdf(@AppDataDir & "\Program","test.ini","variable","section")
MsgBox(0,"",$var) ; second run through
Exit

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Rewrote the green helpfile a touch :huh2:

WarUdf.au3

Question:

Is it possible to turn it into part of the syntax?

Like this thing:

Posted Image

Edit: Didnt relise how big it was before posting... ;)

@Roshith: I see, thanks for clearing that up!

@BrewManNH: So if the key holds 7 then it wont work ?

What if i add this before i return ?

If $read = 0 then
    $read = 0
Else
    $read = 1
EndIf

Wouldnt that work ?

Edited by Maffe811

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Share this post


Link to post
Share on other sites

Question:

Is it possible to turn it into part of the syntax?

Read up on "User Calltips" and "User UDFs syntax highlighting" in the SciTE4AutoIt3 helpfile.

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.
  :)

Share this post


Link to post
Share on other sites

Will do!


[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Share this post


Link to post
Share on other sites

In response to the popup tooltip you're asking about, look in the SciTE\api folder for a file called "au3.user.calltips.api", if it doesn't exist you can create a new one. Inside that file you'd create your new calltips, as they're called in SciTE, formatted something like this

_BASS_SetConfig($option, $value) Sets the value of a config option. (Requires: Bass.au3)

The red section is your function name and it's parameters, the green section is the desriptive text you want displayed when you start typing the function. The last section isn't needed, it just helps to remind users what include file is needed to use this function.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Thanks to both of you, it worked like a charm :huh2:

But i thinkin about rewriting the script...

So instead of a 0/1 script ill make it able to fetch any value...

Maybe later ;)

Edited by Maffe811

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Share this post


Link to post
Share on other sites

I made a test script to show what i was planning the script to do from the start:

#include <WarUdf.au3>
#include <GUIConstantsEx.au3>

;Write and read UDF variables
$War_Dir = @ScriptDir
$War_File = "test.ini"
$War_Section = "test section"
$War_Key = "test"

;Write and read UDF
$WarUdf = WarUdf($War_Dir, $War_File, $War_Section, $War_Key)

;GUI variables
$EditHeight = 40
$EditWidht = 200
$EdgeRemove = 30
$title = "Info"

;Gui set up
GUICreate($title , 300, 200, -1, -1)
$guihandle = WinGetHandle($title)
$Name = GUICtrlCreateInput("Name", 50, $EditHeight-$EdgeRemove, $EditWidht, $EditHeight)
$Age = GUICtrlCreateInput("Age", 50, $EditHeight * 2-$EdgeRemove, $EditWidht, $EditHeight)
$Occupation = GUICtrlCreateInput("Occupation", 50, $EditHeight * 3-$EdgeRemove, $EditWidht, $EditHeight)
$OkButton = GUICtrlCreateButton("Ok", 50, $EditHeight * 4-$EdgeRemove,$EditWidht, $EditHeight)

;Shows gui if its first time
If $WarUdf = 0 Then
GUISetState(@SW_SHOW)
EndIf


;While loop
While 1
    If $WarUdf = 0 Then;If its first time
        $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE then;If close then exit
            Exit
        EndIf
        If $msg = $OkButton Then;If okay then save variables
            GUISetState(@SW_HIDE);Hide gui
            FileChangeDir($War_Dir);Change dir to the ini file
                If GUICtrlRead($Name) = "Name" Then;If the name isnt changed alert user and reset UDF variable
                    MsgBox(0,"Name", "You did not enter your name!")
                    IniWrite($War_File, $War_Section, $War_Key, 0);Reset UDF variable
                Else
                    IniWrite($War_File, $War_Section, "Name", GUICtrlRead($Name));If name is changed then save variable
                EndIf

                If GUICtrlRead($Age) = "Age" Then;If the age isnt changed alert user and reset UDF variable
                    MsgBox(0,"Age", "You did not enter your age!")
                    IniWrite($War_File, $War_Section, $War_Key, 0);Reset UDF variable
                Else
                    IniWrite($War_File, $War_Section, "Age", GUICtrlRead($Age));If Age is changed then save variable
                EndIf

                If GUICtrlRead($Occupation) = "Occupation" Then;If the occupation isnt changed alert user and reset UDF variable
                MsgBox(0,"Occupation", "You did not enter your occupation!")
                IniWrite($War_File, $War_Section, $War_Key, 0);Reset UDF variable
                Else
                IniWrite($War_File, $War_Section, "Occupation", GUICtrlRead($Occupation));If occupation is changed then save variable
                EndIf
            Exit
        EndIf
    Else
        FileChangeDir($War_Dir);Change dir to the ini file
        $Read_Name = IniRead($War_File, $War_Section, "Name", "Not found!");Reads name variable
        $Read_Age = IniRead($War_File, $War_Section, "Age", "Not found!");Reads age variable
        $Read_Occupation = IniRead($War_File, $War_Section, "Occupation", "Not found!");Reads occupation variable
        MsgBox(0,"Name", "Name: " & $Read_Name);Presents name
        MsgBox(0,"Age", "Age: " & $Read_Age);Presents age
        MsgBox(0,"Occupation", "Occupation: " & $Read_Occupation);Presents occupation
        Exit
    EndIf
WEnd

Im not sure, but i think i uploaded the wrong file last time... but im not sure.

This works and is final version:

WarUdf.au3

And then i want to end with saying this forum is great!

Ive asked and you have responded with helpfull tips and pointed me to a syntax i could look up in the helpfile!

Thanks for everything and i will definantly be spending more time here :huh2:


[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Share this post


Link to post
Share on other sites

If you changed the contents of the variable that holds the ini filename to this: $War_File = @ScriptDir & "\test.ini" you could avoid all of the FileChangeDir commands and just access the ini file the same way with the same command. Either way will work, but there's less coding doing it this way.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...