Jump to content

Possible with less code?


Recommended Posts

Hi,

Is it possible to reduce the code below?

What I do now is keep repeating the same code, when creating the GUI, I always count 25 pixels down for the next line.

When create the TraceLevels.properties file I check whether it meets the conditions, if not i set the tracelevel to default 0. (Checking user input)

I am now 300+ lines of codes further and actually have i have nothing done yet.

Later when the script is finally off and I continue this way I'm on the thousands of lines of code. That is not what i want.

Is it possible to create a function with an Array or something like that for doing the same?

And what is the best way to read TraceLevels.properties without doing the same thing multiple times? (Read the values of the TraceLevels.properties file and write the values to the correct inputbox).

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <Array.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>


Local $traceLevels[] = ['MAIN', 'EMMAIN', 'KEYDETECTOR', 'PRINTATHOME', 'OEMREADER', 'BARRIER', 'CODER', 'IO', 'SCREEN', 'SIOPORT', 'SERIALPORT', 'USB', 'THREADING', 'TIMER', 'ETHERNET', 'SERVICETOOL', 'SDSERIAL']
;~ _ArrayDisplay($traceLevels)


#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("SET TRACE LEVELS", 300, 495, 1064, 450)

    $Label1 = GUICtrlCreateLabel("MAIN", 10, 15, 150, 17)
    Local $MAIN = GUICtrlCreateInput("0", 150, 13, 35, 20)
    $Level1 = GUICtrlCreateUpdown($MAIN)
    GUICtrlSetLimit($Level1, 8, 0)

    $Label2 = GUICtrlCreateLabel("EMMAIN", 10, 40, 150, 17)
    Local $EMMAIN = GUICtrlCreateInput("0", 150, 37, 35, 20)
    $Level2 = GUICtrlCreateUpdown($EMMAIN)
    GUICtrlSetLimit($Level2, 8, 0)

    $Label3 = GUICtrlCreateLabel("KEYDETECTOR", 10, 65, 150, 17)
    Local $KEYDETECTOR = GUICtrlCreateInput("0", 150, 62, 35, 20)
    $Level3 = GUICtrlCreateUpdown($KEYDETECTOR)
    GUICtrlSetLimit($Level3, 8, 0)

    $Label4 = GUICtrlCreateLabel("PRINTATHOME", 10, 90, 150, 17)
    Local $PRINTATHOME = GUICtrlCreateInput("0", 150, 87, 35, 20)
    $Level4 = GUICtrlCreateUpdown($PRINTATHOME)
    GUICtrlSetLimit($Level4, 8, 0)

    $Label5 = GUICtrlCreateLabel("OEMREADER", 10, 115, 150, 17)
    Local $OEMREADER = GUICtrlCreateInput("0", 150, 112, 35, 20)
    $Level5 = GUICtrlCreateUpdown($OEMREADER)
    GUICtrlSetLimit($Level5, 8, 0)

    $Label6 = GUICtrlCreateLabel("BARRIER", 10, 140, 150, 17)
    Local $BARRIER = GUICtrlCreateInput("0", 150, 137, 35, 20)
    $Level6 = GUICtrlCreateUpdown($BARRIER)
    GUICtrlSetLimit($Level6, 8, 0)

    $Label7 = GUICtrlCreateLabel("CODER", 10, 165, 150, 17)
    Local $CODER = GUICtrlCreateInput("0", 150, 163, 35, 20)
    $Level7 = GUICtrlCreateUpdown($CODER)
    GUICtrlSetLimit($Level7, 8, 0)

    $Label8 = GUICtrlCreateLabel("IO", 10, 190, 150, 17)
    Local $IO = GUICtrlCreateInput("0", 150, 187, 35, 20)
    $Level8 = GUICtrlCreateUpdown($IO)
    GUICtrlSetLimit($Level8, 8, 0)

    $Label9 = GUICtrlCreateLabel("SCREEN", 10, 215, 150, 17)
    Local $SCREEN = GUICtrlCreateInput("0", 150, 212, 35, 20)
    $Level9 = GUICtrlCreateUpdown($SCREEN)
    GUICtrlSetLimit($Level9, 8, 0)

    $Label10 = GUICtrlCreateLabel("SIOPORT", 10, 240, 150, 17)
    Local $SIOPORT = GUICtrlCreateInput("0", 150, 237, 35, 20)
    $Level10 = GUICtrlCreateUpdown($SIOPORT)
    GUICtrlSetLimit($Level10, 8, 0)

    $Label11 = GUICtrlCreateLabel("SERIALPORT", 10, 265, 150, 17)
    Local $SERIALPORT = GUICtrlCreateInput("0", 150, 262, 35, 20)
    $Level11 = GUICtrlCreateUpdown($SERIALPORT)
    GUICtrlSetLimit($Level11, 8, 0)

    $Label12 = GUICtrlCreateLabel("USB", 10, 290, 150, 17)
    Local $USB = GUICtrlCreateInput("0", 150, 287, 35, 20)
    $Level12 = GUICtrlCreateUpdown($USB)
    GUICtrlSetLimit($Level12, 8, 0)

    $Label13 = GUICtrlCreateLabel("THREADING", 10, 315, 150, 17)
    Local $THREADING = GUICtrlCreateInput("0", 150, 312, 35, 20)
    $Level13 = GUICtrlCreateUpdown($THREADING)
    GUICtrlSetLimit($Level13, 8, 0)

    $Label14 = GUICtrlCreateLabel("TIMER", 10, 340, 150, 17)
    Local $TIMER = GUICtrlCreateInput("0", 150, 337, 35, 20)
    $Level14 = GUICtrlCreateUpdown($TIMER)
    GUICtrlSetLimit($Level14, 8, 0)

    $Label15 = GUICtrlCreateLabel("ETHERNET", 10, 365, 150, 17)
    Local $ETHERNET = GUICtrlCreateInput("0", 150, 362, 35, 20)
    $Level15 = GUICtrlCreateUpdown($ETHERNET)
    GUICtrlSetLimit($Level15, 8, 0)

    $Label16 = GUICtrlCreateLabel("SERVICETOOL", 10, 390, 150, 17)
    Local $SERVICETOOL = GUICtrlCreateInput("0", 150, 387, 35, 20)
    $Level16 = GUICtrlCreateUpdown($SERVICETOOL)
    GUICtrlSetLimit($Level16, 8, 0)

    $Label17 = GUICtrlCreateLabel("SDSERIAL", 10, 415, 150, 17)
    Local $SDSERIAL = GUICtrlCreateInput("0", 150, 413, 35, 20)
    $Level17 = GUICtrlCreateUpdown($SDSERIAL)
    GUICtrlSetLimit($Level17, 8, 0)

    $Label18 = GUICtrlCreateLabel("MAX TRACE FILE COUNT", 10, 440, 150, 17)
    Local $MAX_TRACE_FILE_COUNT = GUICtrlCreateInput("0", 150, 437, 35, 20)
    $Level18 = GUICtrlCreateUpdown($MAX_TRACE_FILE_COUNT)
    GUICtrlSetLimit($Level18, 9, 1)

    $Label19 = GUICtrlCreateLabel("MAX TRACE FILE SIZE", 10, 465, 150, 17)
    Local $MAX_TRACE_FILE_SIZE = GUICtrlCreateInput("0", 150, 462, 35, 20)
    $Level19 = GUICtrlCreateUpdown($MAX_TRACE_FILE_SIZE)
    GUICtrlSetLimit($Level19, 4, 1)

    $Button1 = GUICtrlCreateButton("Get current", 206, 11, 83, 21)
    $Button2 = GUICtrlCreateButton("Set tracelevels", 206, 37, 83, 21)
    $Button3 = GUICtrlCreateButton("Set all to 0", 206, 63, 83, 21)
    $Button4 = GUICtrlCreateButton("Set all to 8", 206, 89, 83, 21)


GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1 ;~ Get current tracelevels

            Local $aArray = 0

        If Not _FileReadToArray(@ScriptDir & "\TraceLevels.properties", $aArray, 0, '=') Then
            MsgBox($MB_SYSTEMMODAL, "", "There was an error reading the file. @error: " & @error) ; An error occurred reading the current script file.
        EndIf

        ; Display the array in _ArrayDisplay.
        _ArrayDisplay($aArray)

        Case $Button2 ;~ Set tracelevels
            setTraceLevels8()
        Case $Button3 ;~ Set all tracelevels to 0

        Case $Button4 ;~ Set all tracelevels to 8

    EndSwitch
WEnd


Func setTraceLevels8()
    Local const $sFilePath = @ScriptDir & "\TraceLevels.properties"
    FileDelete($sFilePath)

    Local $hFileOpen = FileOpen($sFilePath, $FO_APPEND)
    If $hFileOpen = -1 Then
        MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file.")
    EndIf

    Switch GUICtrlRead($MAIN)
        Case 1 to 8
            FileWriteLine($hFileOpen, "MAIN=" & GUICtrlRead($MAIN))
            ConsoleWrite("MAIN=" & GUICtrlRead($MAIN))
        Case Else
            FileWriteLine($hFileOpen, "MAIN=0")
            ConsoleWrite("MAIN=0")
    EndSwitch

    Switch GUICtrlRead($EMMAIN)
        Case 1 to 8
            FileWriteLine($hFileOpen, "EMMAIN=" & GUICtrlRead($EMMAIN))
            ConsoleWrite("EMMAIN=" & GUICtrlRead($EMMAIN))
        Case Else
            FileWriteLine($hFileOpen, "EMMAIN=0")
            ConsoleWrite("EMMAIN=0")
    EndSwitch

    Switch GUICtrlRead($KEYDETECTOR)
        Case 1 to 8
            FileWriteLine($hFileOpen, "KEYDETECTOR=" & GUICtrlRead($KEYDETECTOR))
            ConsoleWrite("KEYDETECTOR=" & GUICtrlRead($KEYDETECTOR))
        Case Else
            FileWriteLine($hFileOpen, "KEYDETECTOR=0")
            ConsoleWrite("KEYDETECTOR=0")
    EndSwitch

    Switch GUICtrlRead($PRINTATHOME)
        Case 1 to 8
            FileWriteLine($hFileOpen, "PRINTATHOME=" & GUICtrlRead($PRINTATHOME))
            ConsoleWrite("PRINTATHOME=" & GUICtrlRead($PRINTATHOME))
        Case Else
            FileWriteLine($hFileOpen, "PRINTATHOME=0")
            ConsoleWrite("PRINTATHOME=0")
    EndSwitch

    Switch GUICtrlRead($OEMREADER)
        Case 1 to 8
            FileWriteLine($hFileOpen, "OEMREADER=" & GUICtrlRead($OEMREADER))
            ConsoleWrite("OEMREADER=" & GUICtrlRead($OEMREADER))
        Case Else
            FileWriteLine($hFileOpen, "OEMREADER=0")
            ConsoleWrite("OEMREADER=0")
    EndSwitch

    Switch GUICtrlRead($BARRIER)
        Case 1 to 8
            FileWriteLine($hFileOpen, "BARRIER=" & GUICtrlRead($BARRIER))
            ConsoleWrite("BARRIER=" & GUICtrlRead($BARRIER))
        Case Else
            FileWriteLine($hFileOpen, "BARRIER=0")
            ConsoleWrite("BARRIER=0")
    EndSwitch

    Switch GUICtrlRead($CODER)
        Case 1 to 8
            FileWriteLine($hFileOpen, "CODER=" & GUICtrlRead($CODER))
            ConsoleWrite("CODER=" & GUICtrlRead($CODER))
        Case Else
            FileWriteLine($hFileOpen, "CODER=0")
            ConsoleWrite("CODER=0")
    EndSwitch

    Switch GUICtrlRead($IO)
        Case 1 to 8
            FileWriteLine($hFileOpen, "IO=" & GUICtrlRead($IO))
            ConsoleWrite("IO=" & GUICtrlRead($IO))
        Case Else
            FileWriteLine($hFileOpen, "IO=0")
            ConsoleWrite("IO=0")
    EndSwitch

    Switch GUICtrlRead($SCREEN)
        Case 1 to 8
            FileWriteLine($hFileOpen, "SCREEN=" & GUICtrlRead($SCREEN))
            ConsoleWrite("SCREEN=" & GUICtrlRead($SCREEN))
        Case Else
            FileWriteLine($hFileOpen, "SCREEN=0")
            ConsoleWrite("SCREEN=0")
    EndSwitch

    Switch GUICtrlRead($SIOPORT)
        Case 1 to 8
            FileWriteLine($hFileOpen, "SIOPORT=" & GUICtrlRead($SIOPORT))
            ConsoleWrite("SIOPORT=" & GUICtrlRead($SIOPORT))
        Case Else
            FileWriteLine($hFileOpen, "SIOPORT=0")
            ConsoleWrite("SIOPORT=0")
    EndSwitch

    Switch GUICtrlRead($SERIALPORT)
        Case 1 to 8
            FileWriteLine($hFileOpen, "SERIALPORT=" & GUICtrlRead($SERIALPORT))
            ConsoleWrite("SERIALPORT=" & GUICtrlRead($SERIALPORT))
        Case Else
            FileWriteLine($hFileOpen, "SERIALPORT=0")
            ConsoleWrite("SERIALPORT=0")
    EndSwitch

    Switch GUICtrlRead($USB)
        Case 1 to 8
            FileWriteLine($hFileOpen, "USB=" & GUICtrlRead($USB))
            ConsoleWrite("USB=" & GUICtrlRead($USB))
        Case Else
            FileWriteLine($hFileOpen, "USB=0")
            ConsoleWrite("USB=0")
    EndSwitch

    Switch GUICtrlRead($THREADING)
        Case 1 to 8
            FileWriteLine($hFileOpen, "THREADING=" & GUICtrlRead($THREADING))
            ConsoleWrite("THREADING=" & GUICtrlRead($THREADING))
        Case Else
            FileWriteLine($hFileOpen, "THREADING=0")
            ConsoleWrite("THREADING=0")
    EndSwitch

    Switch GUICtrlRead($TIMER)
        Case 1 to 8
            FileWriteLine($hFileOpen, "TIMER=" & GUICtrlRead($TIMER))
            ConsoleWrite("TIMER=" & GUICtrlRead($TIMER))
        Case Else
            FileWriteLine($hFileOpen, "TIMER=0")
            ConsoleWrite("TIMER=0")
    EndSwitch

    Switch GUICtrlRead($ETHERNET)
        Case 1 to 8
            FileWriteLine($hFileOpen, "ETHERNET=" & GUICtrlRead($ETHERNET))
            ConsoleWrite("ETHERNET=" & GUICtrlRead($ETHERNET))
        Case Else
            FileWriteLine($hFileOpen, "ETHERNET=0")
            ConsoleWrite("ETHERNET=0")
    EndSwitch

    Switch GUICtrlRead($SERVICETOOL)
        Case 1 to 8
            FileWriteLine($hFileOpen, "SERVICETOOL=" & GUICtrlRead($SERVICETOOL))
            ConsoleWrite("SERVICETOOL=" & GUICtrlRead($SERVICETOOL))
        Case Else
            FileWriteLine($hFileOpen, "SERVICETOOL=0")
            ConsoleWrite("SERVICETOOL=0")
    EndSwitch

    Switch GUICtrlRead($SDSERIAL)
        Case 1 to 8
            FileWriteLine($hFileOpen, "SDSERIAL=" & GUICtrlRead($SDSERIAL))
            ConsoleWrite("SDSERIAL=" & GUICtrlRead($SDSERIAL))
        Case Else
            FileWriteLine($hFileOpen, "SDSERIAL=0")
            ConsoleWrite("SDSERIAL=0")
    EndSwitch

    Switch GUICtrlRead($MAX_TRACE_FILE_COUNT)
        Case 1 to 9
            FileWriteLine($hFileOpen, "MAX_TRACE_FILE_COUNT=" & GUICtrlRead($MAX_TRACE_FILE_COUNT))
            ConsoleWrite("MAX_TRACE_FILE_COUNT=" & GUICtrlRead($MAX_TRACE_FILE_COUNT))
        Case Else
            FileWriteLine($hFileOpen, "MAX_TRACE_FILE_COUNT=2")
            ConsoleWrite("MAX_TRACE_FILE_COUNT=2")
    EndSwitch

    Switch GUICtrlRead($MAX_TRACE_FILE_SIZE)
        Case 1 to 4
            FileWriteLine($hFileOpen, "MAX_TRACE_FILE_SIZE=" & GUICtrlRead($MAX_TRACE_FILE_SIZE))
            ConsoleWrite("MAX_TRACE_FILE_SIZE=" & GUICtrlRead($MAX_TRACE_FILE_SIZE))
        Case Else
            FileWriteLine($hFileOpen, "MAX_TRACE_FILE_SIZE=1")
            ConsoleWrite("MAX_TRACE_FILE_SIZE=1")
    EndSwitch

    ; Close the handle returned by FileOpen.
    FileClose($hFileOpen)

    ; Display the contents of the file passing the filepath to FileRead instead of a handle returned by FileOpen.
    MsgBox($MB_SYSTEMMODAL, "", "Contents of the file:" & @CRLF & FileRead($sFilePath))

EndFunc
# First Draft
Local $traceLevels[] = ['MAIN', 'EMMAIN', 'KEYDETECTOR', 'PRINTATHOME', 'OEMREADER', 'BARRIER', 'CODER', 'IO', 'SCREEN', 'SIOPORT', 'SERIALPORT', 'USB', 'THREADING', 'TIMER', 'ETHERNET', 'SERVICETOOL', 'SDSERIAL']

Local $traceLevelMax        = 8 ;~ minimum 0
Local $maxTraceFileSize     = 4 ;~ minimum 1
Local $maxTraceFileCount    = 9 ;~ minimum 1

Func createGUI()
    ...
EndFunc

Func setTraceLevels()
    ...
EndFunc

Func getTraceLevels()
    ...
EndFunc

Func setTraceLevelsto0()
    ...
EndFunc

Func setTraceLevelsto8()
    ...
EndFunc

 

# TraceLevels.Properties Example
MAIN=0
EMMAIN=0
KEYDETECTOR=0
PRINTATHOME=0
OEMREADER=0
BARRIER=0
CODER=0
IO=0
SCREEN=0
SIOPORT=0
SERIALPORT=0
USB=0
THREADING=0
TIMER=0
ETHERNET=5
SERVICETOOL=0
SDSERIAL=0
MAX_TRACE_FILE_COUNT=2
MAX_TRACE_FILE_SIZE=1

Thanks in advance,
Sorry for my bad english..

Edited by Rijswijker
Case $Button1 (Updated)
Link to comment
Share on other sites

Look into arrays, though maybe you should look at reading about DRY (don't repeat yourself).

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

As guinness says using array will be better.

 

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>

#Region ### START Koda GUI section ### Form=
Global $aoLabels[19],$aoInputs[19]
$Form1 = GUICreate("SET TRACE LEVELS", 300, 495, 400, 450)

Global $sFileProperties="TraceLevels.Properties"
Local $sLine=""
Local $sName=""
For $i=0 to UBound($aoInputs)-1
    $sLine=FileReadLine($sFileProperties,$i+2)
    $sName=StringMid($sLine,1,StringInStr($sLine,"=")-1)
   $aoLabels[$i] = GUICtrlCreateLabel($sName, 10, 15+(25*$i), 140, 17)
    $aoInputs[$i]= GUICtrlCreateInput("0", 150, 13+(25*$i), 35, 20)
    GUICtrlCreateUpdown($aoInputs[$i])
    GUICtrlSetLimit(-1, 8, 0)
Next



    $Button1 = GUICtrlCreateButton("Get current", 206, 11, 83, 21)
    $Button2 = GUICtrlCreateButton("Set tracelevels", 206, 37, 83, 21)
    $Button3 = GUICtrlCreateButton("Set all to 0", 206, 63, 83, 21)
    $Button4 = GUICtrlCreateButton("Set all to 8", 206, 89, 83, 21)


GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###



While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1 ;~ Get current tracelevels

        Case $Button2 ;~ Set tracelevels
FileDelete($sFileProperties)
FileWrite($sFileProperties,"# TraceLevels.Properties Example" & @CRLF)
For $i=0 to UBound($aoInputs)-1
ConsoleWrite(GUICtrlRead($aoLabels[$i]) & "=" & GUICtrlRead($aoInputs[$i]) & @CRLF)
FileWrite($sFileProperties,GUICtrlRead($aoLabels[$i]) & "=" & GUICtrlRead($aoInputs[$i]) & @CRLF)
Next
        Case $Button3 ;~ Set all tracelevels to 0

        Case $Button4 ;~ Set all tracelevels to 8

    EndSwitch
WEnd

Saludos

Link to comment
Share on other sites

Probably does not exist in tracelevels.properties file the code load from it. But you can rewrite better it's just an example. I think a better way should be declare your array of field as you've done in your fisrt post. 

 

Saludos

Link to comment
Share on other sites

Probably does not exist in tracelevels.properties file the code load from it. But you can rewrite better it's just an example. I think a better way should be declare your array of field as you've done in your fisrt post. 

 

Saludos

I am almost there where i want to be.
The only problem is read-out the file and update the values in the input boxes (Get current button)

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <Array.au3>
#include <File.au3>


Global $aoLabels[19],$aoInputs[19]
Global $traceLevels[] = ['MAIN', 'EMMAIN', 'KEYDETECTOR', 'PRINTATHOME', 'OEMREADER', 'BARRIER', 'CODER', 'IO', 'SCREEN', 'SIOPORT', 'SERIALPORT', 'USB', 'THREADING', 'TIMER', 'ETHERNET', 'SERVICETOOL', 'SDSERIAL']

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("SET TRACE LEVELS", 300, (UBound($traceLevels)*25)+70, 400, 450)

Global $sFileProperties="TraceLevels.Properties"
Local $sLine=""
Local $sName=""
For $i=0 to UBound($traceLevels)-1
    $aoLabels[$i] = GUICtrlCreateLabel($traceLevels[$i], 10, 15+(25*$i), 140, 17)
    $aoInputs[$i]= GUICtrlCreateInput("0", 150, 13+(25*$i), 35, 20)
    GUICtrlCreateUpdown($aoInputs[$i])
    GUICtrlSetLimit(-1, 8, 0)
Next

    $fileCountLabel = GUICtrlCreateLabel("MAX_TRACE_FILE_COUNT", 10, 15+(25*$i), 150, 17)
    $fileCountInput = GUICtrlCreateInput("0", 150, 13+(25*$i), 35, 20)
    GUICtrlCreateUpdown($fileCountInput)
    GUICtrlSetLimit(-1, 9, 1)

    $fileSizeLabel = GUICtrlCreateLabel("MAX_TRACE_FILE_SIZE", 10, 40+(25*$i), 150, 17)
    $fileSizeInput = GUICtrlCreateInput("0", 150, 38+(25*$i), 35, 20)
    GUICtrlCreateUpdown($fileSizeInput)
    GUICtrlSetLimit(-1, 4, 1)

    $Button1 = GUICtrlCreateButton("Get current", 206, 11, 83, 21)
    $Button2 = GUICtrlCreateButton("Set tracelevels", 206, 37, 83, 21)
    $Button3 = GUICtrlCreateButton("Set all to 0", 206, 63, 83, 21)
    $Button4 = GUICtrlCreateButton("Set all to 8", 206, 89, 83, 21)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1 ;~ Get current tracelevels

        Local $aArray = 0

        If Not _FileReadToArray(@ScriptDir & "\TraceLevels.properties", $aArray, 0, '=') Then
            MsgBox($MB_SYSTEMMODAL, "", "There was an error reading the file. @error: " & @error) ; An error occurred reading the current script file.
        EndIf

;~      GUICtrlSetData($MAIN, '3')

        ; Display the array in _ArrayDisplay.
        _ArrayDisplay($aArray)

        Case $Button2 ;~ Set tracelevels
            FileDelete($sFileProperties)
            FileWrite($sFileProperties,"# TraceLevels.Properties Example" & @CRLF)
            For $i=0 to UBound($traceLevels)-1
            ConsoleWrite(GUICtrlRead($aoLabels[$i]) & "=" & GUICtrlRead($aoInputs[$i]) & @CRLF)
            FileWrite($sFileProperties,GUICtrlRead($aoLabels[$i]) & "=" & GUICtrlRead($aoInputs[$i]) & @CRLF)
            Next

        Case $Button3 ;~ Set all tracelevels to 0
            FileDelete($sFileProperties)
            FileWrite($sFileProperties,"# TraceLevels.Properties Reset" & @CRLF)
            For $i=0 to UBound($traceLevels)-1
            ConsoleWrite(GUICtrlRead($aoLabels[$i]) & "=0" & @CRLF)
            FileWrite($sFileProperties,GUICtrlRead($aoLabels[$i]) & "=0" & @CRLF)
            Next
            writeFileConditions()

        Case $Button4 ;~ Set all tracelevels to 8
            FileDelete($sFileProperties)
            FileWrite($sFileProperties,"# TraceLevels.Properties Set all to 8" & @CRLF)
            For $i=0 to UBound($traceLevels)-1
            ConsoleWrite(GUICtrlRead($aoLabels[$i]) & "=8" & @CRLF)
            FileWrite($sFileProperties,GUICtrlRead($aoLabels[$i]) & "=8" & @CRLF)
            Next
            writeFileConditions()

    EndSwitch
WEnd

Func writeFileConditions()
                Switch GUICtrlRead($fileCountInput)
                    Case 1 to 9
                        FileWriteLine($sFileProperties, "MAX_TRACE_FILE_COUNT=" & GUICtrlRead($fileCountInput))
                        ConsoleWrite("MAX_TRACE_FILE_COUNT=" & GUICtrlRead($fileCountInput) & @CRLF)
                    Case Else
                        FileWriteLine($sFileProperties, "MAX_TRACE_FILE_COUNT=2")
                        ConsoleWrite("MAX_TRACE_FILE_COUNT=2" & @CRLF)
                EndSwitch

                Switch GUICtrlRead($fileSizeInput)
                    Case 1 to 4
                        FileWriteLine($sFileProperties, "MAX_TRACE_FILE_SIZE=" & GUICtrlRead($fileSizeInput))
                        ConsoleWrite("MAX_TRACE_FILE_SIZE=" & GUICtrlRead($fileSizeInput) & @CRLF)
                    Case Else
                        FileWriteLine($sFileProperties, "MAX_TRACE_FILE_SIZE=1")
                        ConsoleWrite("MAX_TRACE_FILE_SIZE=1" & @CRLF)
                EndSwitch
EndFunc

Now i get an Array with the values, but how can i update the fields created by the script?

Schermafbeelding 2015-08-08 om 22.00.25.png

 

----- EDIT -----

Problem Solved

Case $Button1 ;~ Get current tracelevels

        Local $aArray = 0

        If Not _FileReadToArray(@ScriptDir & "\TraceLevels.properties", $aArray, 0, '=') Then
            MsgBox($MB_SYSTEMMODAL, "", "There was an error reading the file. @error: " & @error) ; An error occurred reading the current script file.
        EndIf

        For $i=0 to UBound($traceLevels)-1
            $aoSearch = _ArraySearch($traceLevels, $traceLevels[$i], 0, 0, 0, 0, 1, 2)
            GUICtrlSetData($aoInputs[$aoSearch], $aArray[$i][1])


        Next

        Case $Button2 ;~ Set tracelevels

 

Edited by Rijswijker
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...