Jump to content

[SOLVED] IniRead with condition


Recommended Posts

Hi guys, i have some problem with IniRead.

This is the script:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $ini = @WorkingDir & "\language.ini"

If FileExists(@WorkingDir & "\language.ini") Then
GUI()
Else
FileOpen(@WorkingDir & "\language.ini", 1)
INICreate()
EndIf

Func INICreate()
IniWrite ($ini, "Default_Language", "Title", "Window")
IniWrite ($ini, "Default_Language", "File", "File")
IniWrite ($ini, "Default_Language", "Modify", "Modify")
IniWrite ($ini, "Default_Language", "Language", "Language")
IniWrite ($ini, "Default_Language", "Label1", "Test text")
IniWrite ($ini, "Default_Language", "Label1", "Different text")
IniWrite ($ini, "Default_Language", "Button1", "Test")
IniWrite ($ini, "Default_Language", "Button2", "Word")
IniWrite ($ini, "User_Language", "Title", "?")
IniWrite ($ini, "User_Language", "File", "?")
IniWrite ($ini, "User_Language", "Modify", "?")
IniWrite ($ini, "User_Language", "Language", "?")
IniWrite ($ini, "User_Language", "Label1", "?")
IniWrite ($ini, "User_Language", "Label1", "?")
IniWrite ($ini, "User_Language", "Button1", "?")
IniWrite ($ini, "User_Language", "Button2", "?")
EndFunc

GUI()

Func GUI()
$Form1 = GUICreate("Window", 217, 239, -1, -1)
$MenuItem5 = GUICtrlCreateMenu(File())
$MenuItem6 = GUICtrlCreateMenuItem("Exit", $MenuItem5)
$MenuItem4 = GUICtrlCreateMenu("Modify")
$MenuItem3 = GUICtrlCreateMenu("Language")
$Label1 = GUICtrlCreateLabel("Test text", 44, 64, 129, 17)
$Label2 = GUICtrlCreateLabel("Different text", 54, 192, 109, 17)
$Button1 = GUICtrlCreateButton("Test", 16, 16, 89, 41)
$Button2 = GUICtrlCreateButton("Word", 112, 16, 89, 41)
GUICtrlCreateEdit("", 18, 80, 185, 105)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
EndSwitch
WEnd
EndFunc

Func File()
    $var = IniRead($ini, "Default_Language", "File", '')
    If $var Then
        Return $var
    Else
        $var = IniRead($ini, "User_Language", "Title", '')
        If Not $var Then
            MsgBox(0,'','Cant locate anything')
            Exit
  Else
   Return $var
        EndIf
    EndIf
EndFunc

I want to make a conditional IniRead in the GUI, in this case.

Work fine if i use this:

$MenuItem5 = GUICtrlCreateMenu(IniRead( $ini, "Default_Language", "Title", "Window")

But i need to make a something like this:

$MenuItem5 = GUICtrlCreateMenu(File())

Func File()
   If IniRead($ini, "User_Language", "Title", "?") = 0 Then
   IniRead($ini, "Default_Language", "File", "File")
   Else
   IniRead($ini, "User_Language", "Title", "i need a text here")
   EndIf
EndFunc

But not work, the result in the GUI is 0.

Someone has some idea? Thanks for support

PS If something is not clear, simply ask.

Edited by johnmcloud
Link to comment
Share on other sites

use return on func

$var = IniRead($ini, "User_Language", "Title", "i need a text here")
    EndIf
    Return $var
EndFunc

i need a text here

is part what iniread return if that key isnt located, so if there isnt any key named Title itl return 'i need a text here'

The default value to return if the requested key is not found.

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

Return $var

not Return and iniread need to log data to $var

look upper post one more time, i edited it

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

Return $var

Give me error, i don't have a $var variable :)

So i have try to

Return $ini

The result is the path in the of the .ini in the GUI

Please be more clear, i'm not a super expert. Thanks

EDIT: Maybe i'm a noob, but give me the same error, variable not found:

Func File()
   If IniRead($ini, "User_Language", "Title", "?") = 0 Then
   IniRead($ini, "Default_Language", "File", "File")
   Else
   $var = IniRead($ini, "User_Language", "Title", "i need a text here")
   EndIf
   Return $var
EndFunc
Edited by johnmcloud
Link to comment
Share on other sites

well more something like this :)

Func File()
    $var = IniRead($ini, "Default_Language", "File", '')
    If $var Then
        Return $var
    Else
        $var = IniRead($ini, "User_Language", "Title", '')
        If Not $var Then
            MsgBox(0,'','Cant locate anything')
            Exit
        Else
            Return $var
        EndIf
    EndIf
EndFunc

confusing iniread rewrited it

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

Thanks guys, but there is a problem, the result is always "File" also if i delete the "?"

I want to make a two language gui.

So if ? is replaced by any text i want to load that text, hope this is the right approach.

@bogQ Same problem, if i delete the "?" the result is always "File" into the GUI

Edited by johnmcloud
Link to comment
Share on other sites

maby its better for you to load them into array, newer the less i edited upper code, i got lost in your iniwrite so i made mistake first time

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

The ini structure is easy:

[Default_Language]

File=File

[user_Language]

File=?

If user replace "?" with "autoit", i want to load that string in the GUI, so instead of "File" i want to see "autoit" :)

If you can do an example, i'll be grateful

Edited by johnmcloud
Link to comment
Share on other sites

i now c, did not know that you need to use ? in your 'if then else',

well if noone help you untill i get home from work (in 40 minutes) il post you some small example

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

Ok, thanks. I'm using "?" or i can write "none" or " "

The default return value is up to you and won't change anything.

If user replace "?" with "autoit", i want to load that string in the GUI, so instead of "File" i want to see "autoit" :)

If you can do an example, i'll be grateful

Your not checking if the value is "?". Your checking if the value = 0.

If IniRead($ini, "User_Language", "Title", "?") = 0 Then

That would need to be

If IniRead($ini, "User_Language", "Title", "?") = "?" Then
Link to comment
Share on other sites

@Beege i think was like other function, like MsgBox(0,0, "Test") = 1 Then etc

You have right, now work:

Func File()
   Local $var
   If IniRead($ini, "User_Language", "File", "?") = "?" Then
   $var = IniRead($ini, "Default_Language", "File", "File")
   Else
   $var = IniRead($ini, "User_Language", "File", "")
   EndIf
   Return $var
EndFunc

Thanks to all for support :)

Edited by johnmcloud
Link to comment
Share on other sites

This shud work perfectly

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Global $ini = @WorkingDir & "language.ini"
Dim $element_array[9]=['Title','File','Exit','Modify','Language','Label1','Label2','Button1','Button2']
If Not FileExists($ini) Then
    INICreate()
EndIf
GUI()


Func INICreate()
    IniWrite ($ini, "Default_Language", "Title", "Window")
    IniWrite ($ini, "Default_Language", "File", "File")
    IniWrite ($ini, "Default_Language", "Exit", "Exit")
    IniWrite ($ini, "Default_Language", "Modify", "Modify")
    IniWrite ($ini, "Default_Language", "Language", "Language")
    IniWrite ($ini, "Default_Language", "Label1", "Test text")
    IniWrite ($ini, "Default_Language", "Label2", "Different text")
    IniWrite ($ini, "Default_Language", "Button1", "Test")
    IniWrite ($ini, "Default_Language", "Button2", "Word")
    IniWrite ($ini, "User_Language", "Title", "?")
    IniWrite ($ini, "User_Language", "File", "?")
    IniWrite ($ini, "User_Language", "Exit", "?")
    IniWrite ($ini, "User_Language", "Modify", "?")
    IniWrite ($ini, "User_Language", "Language", "?")
    IniWrite ($ini, "User_Language", "Label1", "?")
    IniWrite ($ini, "User_Language", "Label2", "?")
    IniWrite ($ini, "User_Language", "Button1", "?")
    IniWrite ($ini, "User_Language", "Button2", "?")
EndFunc

Func GUI()
    $Form1 = GUICreate(Language(0), 217, 239, -1, -1)
    $MenuItem5 = GUICtrlCreateMenu(Language(1))
    $MenuItem6 = GUICtrlCreateMenuItem(Language(2), $MenuItem5)
    $MenuItem4 = GUICtrlCreateMenu(Language(3))
    $MenuItem3 = GUICtrlCreateMenu(Language(4))
    $Label1 = GUICtrlCreateLabel(Language(5), 44, 64, 129, 17)
    $Label2 = GUICtrlCreateLabel(Language(6), 54, 192, 109, 17)
    $Button1 = GUICtrlCreateButton(Language(7), 16, 16, 89, 41)
    $Button2 = GUICtrlCreateButton(Language(8), 112, 16, 89, 41)
    GUICtrlCreateEdit("", 18, 80, 185, 105)
    GUISetState(@SW_SHOW)
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
        EndSwitch
    WEnd
EndFunc
Func Language($el_num)
    $User_Language = IniRead($ini, "User_Language", $element_array[$el_num], '')
    $Def__Language = IniRead($ini, "Default_Language", $element_array[$el_num], '')
    If $User_Language <> '?' And $User_Language <> '' And $User_Language <> ' ' And $User_Language <> ' ' Then
        Return $User_Language
    Else
        Return $Def__Language
    EndIf
EndFunc

later if i have time il post you some easyer solution

edit:

or another one

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Global $ini = "language.ini"
Dim $element_array[9][2]=[ _
    ['Title','Window'], _
    ['File','File'], _
    ['Exit','Exit'], _
    ['Modify','Modify'], _
    ['Language','Language'], _
    ['Label1','Test text'], _
    ['Label2','Different text'], _
    ['Button1','Test'], _
    ['Button2','Word']]
If Not FileExists($ini) Then
    INICreate()
EndIf
GUI()
Func INICreate()
    IniWrite ($ini, "User_Language", $element_array[0][0], "?")
    IniWrite ($ini, "User_Language", $element_array[1][0], "?")
    IniWrite ($ini, "User_Language", $element_array[2][0], "?")
    IniWrite ($ini, "User_Language", $element_array[3][0], "?")
    IniWrite ($ini, "User_Language", $element_array[4][0], "?")
    IniWrite ($ini, "User_Language", $element_array[5][0], "?")
    IniWrite ($ini, "User_Language", $element_array[6][0], "?")
    IniWrite ($ini, "User_Language", $element_array[7][0], "?")
    IniWrite ($ini, "User_Language", $element_array[8][0], "?")
EndFunc

Func GUI()
    $Form1 = GUICreate(Language(0), 217, 239, -1, -1)
    $MenuItem5 = GUICtrlCreateMenu(Language(1))
    $MenuItem6 = GUICtrlCreateMenuItem(Language(2), $MenuItem5)
    $MenuItem4 = GUICtrlCreateMenu(Language(3))
    $MenuItem3 = GUICtrlCreateMenu(Language(4))
    $Label1 = GUICtrlCreateLabel(Language(5), 44, 64, 129, 17)
    $Label2 = GUICtrlCreateLabel(Language(6), 54, 192, 109, 17)
    $Button1 = GUICtrlCreateButton(Language(7), 16, 16, 89, 41)
    $Button2 = GUICtrlCreateButton(Language(8), 112, 16, 89, 41)
    GUICtrlCreateEdit("", 18, 80, 185, 105)
    GUISetState(@SW_SHOW)
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
        EndSwitch
    WEnd
EndFunc
Func Language($el_num)
    $User_Language = IniRead($ini, "User_Language", $element_array[$el_num][0], '')
    If $User_Language <> '?' And $User_Language <> '' And $User_Language <> ' ' And $User_Language <> ' ' Then
        Return $User_Language
    Else
        Return $element_array[$el_num][1]
    EndIf
EndFunc
Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
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

×
×
  • Create New...