Jump to content

Recommended Posts

Posted (edited)

There is a _ArrayToString() but no _ArrayFromString().  ( searched in the forum and google )
The example is based on the _ArrayToString() help file, to show the reconstruction of the array.

#include <Array.au3>
#include <MsgBoxConstants.au3>

Local $aArray[20]
For $i = 0 To 19
    $aArray[$i] = $i
Next
_ArrayDisplay($aArray, "1D Array")
MsgBox($MB_SYSTEMMODAL, "Items 1-7", _ArrayToString($aArray, @TAB, 1, 7))
ConsoleWrite('>' & _ArrayToString($aArray, @TAB, 1, 7) & '<' & @CRLF)
_ArrayDisplay(_ArrayFromString(_ArrayToString($aArray, @TAB, 1, 7), @TAB), "1D ArrayFromString")

Local $aArray[10][10]
For $i = 0 To 9
    For $j = 0 To 9
        $aArray[$i][$j] = $i & "-" & $j
    Next
Next
_ArrayDisplay($aArray, "2D Array")
MsgBox($MB_SYSTEMMODAL, "Rows 4-7,  cols 2-5", _ArrayToString($aArray, " :: ", 4, 7, @CRLF, 2, 5))
ConsoleWrite('>' & _ArrayToString($aArray, " :: ", 4, 7, @CRLF, 2, 5) & '<' & @CRLF)
_ArrayDisplay(_ArrayFromString(_ArrayToString($aArray, " :: ", 4, 7, @CRLF, 2, 5), " :: ", @CRLF), "2D ArrayFromString")

;   au3.user.calltips.api:
;   _ArrayFromString($sString , [$sDelim_Col = "|" [, $sDelim_Row = @CRLF [, $iForce2D = 0]]]) Rebuild an array from _ArrayToString()
Func _ArrayFromString($sString, $sDelim_Col = "|", $sDelim_Row = @CRLF, $iForce2D = 0,) ; https://www.autoitscript.com/forum/topic/197277-_arrayfromstring/
    If $sDelim_Col = Default Or String($sDelim_Col) = "" Then $sDelim_Col = "|"
    If $sDelim_Row = Default Or String($sDelim_Row) = "" Then $sDelim_Row = @CRLF
    $iForce2D = Int($iForce2D)
    Local $m, $n, $b, $c = StringSplit($sString, $sDelim_Row, 3) ; $STR_ENTIRESPLIT + $STR_NOCOUNT
    $b = StringSplit($c[0], $sDelim_Col, 3)
    If UBound($c) = 1 And Not $iForce2D Then Return $b
    Local $a[UBound($c)][UBound($b)]
    For $n = 0 To UBound($c) - 1
        $b = StringSplit($c[$n], $sDelim_Col, 3)
        If UBound($b) > UBound($a, 2) Then Return SetError(1)
        For $m = 0 To UBound($b) - 1
            $a[$n][$m] = $b[$m]
        Next
    Next
    Return $a
EndFunc   ;==>_ArrayFromString


PS: so, how to save an array to an ini file ? ( small array, the limitations of an ini file still applies )

#include <Array.au3>; For _ArrayDisplay()

; if you declare it, it will use it, else, use default
;Global $g_iniFile = @ScriptDir & "\ThisTest.ini"

Example()
Func Example()
    Local $n, $aTest, $aArray[3] = ["00", "one", "2"]

    ; if is not in the INI file, it will save it
    $aTest = IniGet("Test", $aArray)
    _ArrayDisplay($aTest, "1st")

    ; since is saved, it'll recall it
    $aTest = IniGet("Test")
    For $n = 0 To UBound($aTest) - 1 ; ..just to show the elements found as integer
        If IsInt($aTest[$n]) Then $aTest[$n] &= " = IsInt() = " & (IsInt($aTest[$n]) = 1)
    Next
    _ArrayDisplay($aTest, "2nd")
EndFunc   ;==>Example

Func IniGet($sKey, $vDefault = Default, $sSection = "Settings")
    Local Static $ini = IsDeclared("g_iniFile") ? Eval("g_iniFile") : StringTrimRight(@ScriptFullPath, 4) & ".ini"
    Local $v, $s = IniRead($ini, $sSection, $sKey, Chr(1))
    If $s = Chr(1) Then
        If $vDefault == Default Then
            Return SetError(1, 0, "")
        Else
            IniSet($sKey, $vDefault, $sSection)
            Return $vDefault
        EndIf
    EndIf

    $v = StringLeft($s, 1)
    Switch $v
        Case "i"
            Return Int(StringTrimLeft($s, 2))
        Case "a"
            Return _ArrayFromString(BinaryToString(StringTrimLeft($s, 2)), Chr(1), Chr(2))
        Case "d"
            Return Binary(StringTrimLeft($s, 2))
        Case Else
            Return String(StringTrimLeft($s, 2))
    EndSwitch
EndFunc   ;==>IniGet

Func IniSet($sKey, $vValue, $sSection = "Settings")
    Local Static $ini = IsDeclared("g_iniFile") ? Eval("g_iniFile") : StringTrimRight(@ScriptFullPath, 4) & ".ini"
    If IsInt($vValue) Then
        $vValue = "i:" & $vValue
    ElseIf IsArray($vValue) Then
        $vValue = "a:" & StringToBinary(_ArrayToString($vValue, Chr(1), -1, -1, Chr(2)))
    ElseIf IsBinary($vValue) Then
        $vValue = "d:" & $vValue
    Else
        $vValue = "s:" & $vValue
    EndIf
    $vValue = IniWrite($ini, $sSection, $sKey, $vValue)
    Return SetError(@error, @extended, $vValue)
EndFunc   ;==>IniSet

;   au3.user.calltips.api:
;   _ArrayFromString($sString , [$sDelim_Col = "|" [, $sDelim_Row = @CRLF [, $iForce2D = 0]]]) Rebuild an array from _ArrayToString()
Func _ArrayFromString($sString, $sDelim_Col = "|", $sDelim_Row = @CRLF, $iForce2D = 0,) ; https://www.autoitscript.com/forum/topic/197277-_arrayfromstring/
    If $sDelim_Col = Default Or String($sDelim_Col) = "" Then $sDelim_Col = "|"
    If $sDelim_Row = Default Or String($sDelim_Row) = "" Then $sDelim_Row = @CRLF
    $iForce2D = Int($iForce2D)
    Local $m, $n, $b, $c = StringSplit($sString, $sDelim_Row, 3) ; $STR_ENTIRESPLIT + $STR_NOCOUNT
    $b = StringSplit($c[0], $sDelim_Col, 3)
    If UBound($c) = 1 And Not $iForce2D Then Return $b
    Local $a[UBound($c)][UBound($b)]
    For $n = 0 To UBound($c) - 1
        $b = StringSplit($c[$n], $sDelim_Col, 3)
        If UBound($b) > UBound($a, 2) Then Return SetError(1)
        For $m = 0 To UBound($b) - 1
            $a[$n][$m] = $b[$m]
        Next
    Next
    Return $a
EndFunc   ;==>_ArrayFromString


PS2: https://www.autoitscript.com/trac/autoit/ticket/3696#ticket

Edited by argumentum
better code

Share this post


Link to post
Share on other sites

certainly different from stringsplit with the second delimiter, it's more akin to passing a string to _ArrayAdd.


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

They do have a difference, in that yours builds the array based off input rather than trying to cram the input into the existing dimensions.  There are cases where this would be desirable behavior and clean up a lot of prep work. 


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

@jchd, could you modify the _SQLite_Display2DResult() as shown in the comment in the code ? ( I've done it for my use but I think is a good idea for everyone )
I dump to text some db tables and I like the human readable output but I wanted the possibility to reconstruct the array.  With this additional parameter I can do it easily. 

#include <Array.au3>
#include <SQLite.au3>


#cs

on SQLite.au3, modify these two places

from:
Func _SQLite_Display2DResult($aResult, $iCellWidth = 0, $bReturn = False)
to:
Func _SQLite_Display2DResult($aResult, $iCellWidth = 0, $bReturn = False, $sDelim_Col = "")

from:
$sOut &= StringFormat(" %-" & $iCellWidthUsed & "." & $iCellWidthUsed & "s ", $aResult[$iRow][$iCol])
to:
$sOut &= StringFormat(" %-" & $iCellWidthUsed & "." & $iCellWidthUsed & "s ", $aResult[$iRow][$iCol]) & $sDelim_Col


#ce


Local $sDisplay2DResult, $aArray[10][10]
For $i = 0 To 9
    For $j = 0 To 9
        $aArray[$i][$j] = $i & "-" & $j
    Next
Next

$sDisplay2DResult = _SQLite_Display2DResult($aArray, 0, True, @TAB) ; with the above mod.
ConsoleWrite($sDisplay2DResult)
_ArrayDisplay(_ArrayFromString(StringTrimRight($sDisplay2DResult, 4), " " & @TAB & " ", " " & @TAB & @CRLF))

Func _ArrayFromString($s, $sDelim_Col = "|", $sDelim_Row = @CRLF, $iForce2D = 0) ; https://www.autoitscript.com/forum/topic/197277-_arrayfromstring/
    Local $m, $n, $b, $c = StringSplit($s, $sDelim_Row, 3)
    $b = StringSplit($c[0], $sDelim_Col, 3)
    If UBound($c) = 1 And Not $iForce2D Then Return $b
    Local $a[UBound($c)][UBound($b)]
    For $n = 0 To UBound($c) - 1
        $b = StringSplit($c[$n], $sDelim_Col, 3)
        If UBound($b) > UBound($a, 2) Then Return SetError(1)
        For $m = 0 To UBound($b) - 1
            $a[$n][$m] = $b[$m]
        Next
    Next
    Return $a
EndFunc   ;==>_ArrayFromString

Thanks  :)
PS: https://www.autoitscript.com/trac/autoit/ticket/3695#ticket

Edited by argumentum
better code

Share this post


Link to post
Share on other sites

I'm not able to maintain code anymore so you should post a ticket in Trac about that. In the meantime, change your own copy of the UDF.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

In looking at the code in the _ArrayFromString I have a question. what this line is supposed to be doing?

If $b[$m] == Int($b[$m]) Then $b[$m] = Int($b[$m])

You're checking an entry in the $b array against the string value of the Integer of that entry? And, if the value is equal, you set it to the integer value of the integer you just checked?The only time that line will return true is if $b[m] is a whole number, either a string value or a numeric value, so why does it need to be set to a whole number if it's already a whole number?


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
2 hours ago, BrewManNH said:

I have a question

Global $s = "00"
If $s Then MsgBox(0, @ScriptName, "zero")
If $s = Int($s) Then MsgBox(0, @ScriptName, "equal")
If $s == Int($s) Then MsgBox(0, @ScriptName, "not equal") ; the reason for double equal
$s = Int($s)
If $s Then MsgBox(0, @ScriptName, "nothing") ; the reason for String2Integer

 

Edited by argumentum
spelling

Share this post


Link to post
Share on other sites

Silently removing leading zeroes may permanently destroy data, never do that in the general case. Leading zeroes are semantically significant in an unbounded number of situations: James is "007", not "7" and 13-digit barcode "0000870361925" may designate a completely distinct item from "870361925".


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

..at the time I came up with the idea, it made sense for what I was doing, but "James 7" is just wrong.
So due to overwhelming resistance to the idea due to "preponderance of the evidence", I'll remove the lines that makes this not fit for general purpose.
I recon the user can integerify if is needed.

Share this post


Link to post
Share on other sites

I didn't say that to annoy you ;)

Just think of a string is a file/folder name or relative URL or time stamp ("00:13:43") having leading zero(es). It's always correct to avoid presuming the nature of user data when we have no clue what it really is and means.

Integerifying number-like strings isn't even required in most use case under AutoIt: ConsoleWrite("123" + "00444" & @LF) works transparently.

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

@jchd, I am not annoyed, am grateful. I am pushing for this function to be included in the distribution as I find it complementary to other functions.
Comments from @BrewManNH and @user4157124 are also welcomed.
If y'all don't share your views, I may be going on believing this is kosher but eventually find myself scratching my head. Or worse, someone else, trusting this code, stuff don't work.

So as a defacto, prove me wrong. I'll be happy and grateful.

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

  • Similar Content

    • By jimdaway
      I'm struggling with something I'm sure I've missed...
      I have a 1-dimensional array and I'm populating a ListBox using an _ArrayToString function within the GUICtrlSetData function.
      If I perform an _ArrayReverse on the array before I execute the _ArrayToString function within the GUICtrlSetData, the list still populates in a sorted order.
      If I do an _ArrayDisplay, it's showing to be reversed but when I populate the ListBox, it's still sorted!
      _GetDirectoryListing() _ArrayReverse($aMasterJobList) _ArrayDisplay($aMasterJobList) GUICtrlSetData($hJobList, _ArrayToString($aMasterJobList)) Am I missing a subtle (or not-so subtle) flag somewhere?
    • By AndreasNWWWWW
      Hi, i'm curious if this is even possible, i want to do an action if the ini file contains current values under a section.
      for my test i'm looking for 100,200,300,400,500
      and if any of those excits i want to pop a msgbox with the number in the section.
      i can in my example find one, but it does not check everyone. why?  what am i missing?
      Local $iscore810[5] = [100,200,300,400,500] Local $iMax800 = 5 While 1 ;~     Send("{pause}") ;;func les ini fil     $var = IniReadSection("Area.ini", "modus")     If @error Then         MsgBox(4096, "Error", "Unable to read section.")     Else          For $number = 1 To $var[0][0] If $var[$number][1] == $iscore810[3] Then       MsgBox($MB_SYSTEMMODAL, "FAnt den på", $var[$number][0], 5) EndIf                       Next     EndIf     exit WEnd  
    • By Jibsbrown
      Need some help understanding why the ConsoleWrite works inside 2nd For loop but not out side. Between Audit Wiki, Help file , Forum searching (lots of code reading), and YouTube ( shout out to TutsTeach), I have not been able to find the reason why. 
      $sIniPath = "installLog.ini" ; - Get section name $iniSctionNames = IniReadSectionNames($sIniPath) ; - Get Keys and Vaules For $a = 1 to UBound($iniSctionNames) - 1 $keys = IniReadSection($sIniPath , $iniSctionNames[$a]) For $b = 1 to UBound($keys) - 1 $oldSysInfo = IniRead($sIniPath , $iniSctionNames[1], $keys[$b][0], "") $PntIPInfo = IniRead($sIniPath , $iniSctionNames[2], $keys[$b][0], "") $NewPCInfor = IniRead($sIniPath , $iniSctionNames[3], $keys[$b][0], "") ;ConsoleWrite($oldSysInfo & @LF) Next ;ConsoleWrite($oldSysInfo & @LF) Next ConsoleWrite($oldSysInfo) My intention is to use the variables later for Listboxes. Any explanation, forum post links or whatever would help. Sorry also very very new to Autoit.
      Also here's the ini file.
      [OldSysInfo] 4=192.168.0.4|DESKTOP-RDIU2SN|R90M05Q8 5=192.168.0.5|SD0123456789101|R9WGP9P 6=192.168.0.6|SD0123456789102|R9WGP9PT 3=192.168.0.3|DESKTOP-3RS4LKL|R9WGP9P 23=192.168.0.23|SD0123456789102|MXL1234P5I [PrinterIp] 50=192.168.0.50 48=192.168.0.48 47=192.168.0.47 [NewSysInfo] newPC = SD0123456789adfs|192.168.0.185|2UA1234FTR Thank you for your time.
    • By damon
      @JLogan3o13 I apologize, I did not think of it that way.  I have attached all the code and the Ini File information.  Please let me know if I need to add anything else to help understand what is happening.  thank you.
       
       
       
      Guys, I apologize in advance as I did not search for my answer before posting.  I just could not figure out a way to search that made since so I decided to go ahead and post my question.
       
      Getting to it.
      Background: this is being used to validate file names before moving to a new location.  though i have not included all the code, below is what i am having a problem with.
       I have an ini file that i am reading values from. Func ConfigDefineVars() -- I read the value of $ValidationRDA and everything is good then I set 
      $CaseRDALocationCheck = '$SplitFile[$ValidationRDALocation]' <> $ValidationRDA
      the code that will be used in the select case in Func FileSplitCount().  The problem i have is that even though the numbers = each other they are not recognizing as =.  
      This is what i am getting in my log file i create.
      2017-12-04 14:09:53 : RDA was 2403 should have been 2403:
      If I move $SplitFile[$ValidationRDALocation] <> $ValidationRDA to the Case line under the function it works correctly.
       
      I think this has to do with my use of ' ' around the '$SplitFile[$ValidationRDALocation]' but  i don't know what option i have in Func ConfigDefineVars I am not ready to define $SplitFile.  I have tried adding it to my Global Vars at the top of my script but that did not seem to help.
      There will be more fail this is just the first one in the select case.
       
      Any help or ideas would be greatly appreciated.
       
      thanks,
      Damon
      Example of a filename used.
      DWRSSD-37087-95-026.%-064.00-Tatum Family %-%-1230 Academy Rd-%-PERM-TRUE-2403.pdf
      This file will fail on the 95, it should be 095.  The problem i am getting is with the 2403 it fails even though the ini file value ValidationRDA = 2403 
       
       
      Ini File:
      [SSD_FolderPaths]
      pendingFolder=C:\Users\bg01152\Desktop\SSD Test\pending
      reviewFolder=C:\Users\bg01152\Desktop\SSD Test\review
      completedFolder=C:\Users\bg01152\Desktop\SSD Test\Completed
      FileNetProperties=DocumentTitle,ZipCode,County,MapAndGroupID,ParcelID,PropertyOwner,Subdivision,StreetAddress,LotNumber,DocumentType,Approved,RDANumber
      ValidationDocumentTitle=DWRSSD
      ValidationDocumentTitleLocation=1
      ValidationCountyCodeLocation=3
      ValidationRDA=2403
      ValidationRDALocation=12
      Validation3=TRUE
      Validation3Location=11
      Validation4=PERM
      Validation4Location=10
       
       
      #include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> ;------------Global Vars --------------------- Global $SplitFile, $aFileList, $FileLog, $dFolder, $sFolder, $cFolder, $ConfigFile, $t Global $ValidationDocumentTitle, $ValidationDocumentTitleLocation, $ValidationCountyCodeLocation, $ValidationRDA Global $ValidationRDALocation, $Validation3, $Validation3Location, $Validation4, $Validation4Location, $FileNetPropertiesSplit Global $CaseCountyCheck, $CaseRDALocationCheck, $CaseValidation3LocationCheck, $CaseValidation4LocationCheck, $SplitFile ;;--------------------------------Check and Read Config files-------------------------------- $SysConfigFile = @ScriptDir & "\SysConfig.ini" ;----------------PreCheck for Config File-------------- If FileExists ($SysConfigFile) <> 1 Then Exit EndIf ;----------------End PreCheck-------------------------- $FileNetEXE = @ScriptDir & "\" & IniRead ($SysConfigFile, "FileNetUploader","FileName","") $delimiter = IniRead ($SysConfigFile, "FileInformation", "Delimiter","") $Filter = IniRead ($SysConfigFile, "FileInformation", "Filter", "") $ConfigFile = @ScriptDir & "\Config.ini" ;----------------PreCheck for Config File-------------- If FileExists ($ConfigFile) <> 1 Then Exit EndIf ;----------------End PreCheck-------------------------- ;;-------------------------------------------------------------------------------------------- $Sections = IniReadSectionNames ($ConfigFile) ;MsgBox (0,"test", $Sections[0] & @CRLF & $Sections[1] & @CRLF & $Sections[2] & @CRLF & $Sections[3] & @CRLF & $Sections[4]);TESTING ONLY - DELETE WHEN DONE $p = 0 Do $t = 0 ;used for precheck $p = $p + 1 ConfigDefineVars($Sections[$p]) ;MsgBox(0,"ConfigDefineVars", $sFolder & @CRLF & $dFolder & @CRLF & $cFolder);TESTING ONLY - DELETE WHEN DONE PreCheck($dFolder, $sFolder, $cFolder) ;Runs a Pre-check to make sure folder structure exists before running the program If $t = 0 Then ;MsgBox(0,"PreCheck Run", "Running next functions");TESTING ONLY - DELETE WHEN DONE ListArray($sFolder, $Filter) ;Puts File Names in String Array ;_ArrayDisplay ($aFileList, $Sections[$p]) If $t = 0 Then FileSplitCount($dFolder, $aFileList) ;Takes filename String Array and splits by $delimiter ;MsgBox(0,"PreCheck Run2", "Running split function");TESTING ONLY - DELETE WHEN DONE Else ;MsgBox(0,"PreCheck Run2", "Skipping split function");TESTING ONLY - DELETE WHEN DONE EndIf Else ;MsgBox(0,"PreCheck Run", "Skipping next functions");TESTING ONLY - DELETE WHEN DONE EndIf Until $p = $Sections[0] ExitScript() ;Exit script Function Func ConfigDefineVars($SectionsNum);Defines Variables from config file Sections $sFolder = IniRead ($ConfigFile, $SectionsNum, "pendingFolder","") ;Pending Folder, Folder that is awaiting the process $dFolder = IniRead ($ConfigFile, $SectionsNum, "reviewFolder","") ;Review Folder, Files that did not pass validation check and division needs to review $cFolder = IniRead ($ConfigFile, $SectionsNum, "completedFolder","") ;Completed Folder, Once process is completed this would be location files get moved to $FileNetProperties = IniRead ($ConfigFile, $SectionsNum, "FileNetProperties","") $FileNetPropertiesSplit = StringSplit ($FileNetProperties,",") $ValidationDocumentTitle = IniRead ($ConfigFile, $SectionsNum, "ValidationDocumentTitle","") $ValidationDocumentTitleLocation = IniRead ($ConfigFile, $SectionsNum, "ValidationDocumentTitleLocation","") $ValidationCountyCodeLocation = IniRead ($ConfigFile, $SectionsNum, "ValidationCountyCodeLocation","") $ValidationRDA = IniRead ($ConfigFile, $SectionsNum, "ValidationRDA","") $ValidationRDALocation = IniRead ($ConfigFile, $SectionsNum, "ValidationRDALocation","") $Validation3 = IniRead ($ConfigFile, $SectionsNum, "Validation3","") $Validation3Location = IniRead ($ConfigFile, $SectionsNum, "Validation3Location","") $Validation4 = IniRead ($ConfigFile, $SectionsNum, "Validation4","") $Validation4Location = IniRead ($ConfigFile, $SectionsNum, "Validation4Location","") If $ValidationCountyCodeLocation = 999 Then $CaseCountyCheck = 1 <> 1 Else ;MsgBox (0,"test of county code", "location = " &$ValidationCountyCodeLocation) $CaseCountyCheck = StringLen('$SplitFile[$ValidationCountyCodeLocation]') <> 3 ; Checks for 3 digit County Code EndIf If $ValidationRDALocation = 999 Then $CaseRDALocationCheck = 1 <> 1 Else $CaseRDALocationCheck = '$SplitFile[$ValidationRDALocation]' <> $ValidationRDA ; Checks for 4 Digit RDA EndIf If $Validation3Location = 999 Then $CaseValidation3LocationCheck = 1 <> 1 Else $CaseValidation3LocationCheck = '$SplitFile[$Validation3Location]' <> $Validation3 ; Checks that Approved = True EndIf If $Validation4Location = 999 Then $CaseValidation4LocationCheck = 1 <> 1 Else $CaseValidation3LocationCheck = '$SplitFile[$Validation4Location]' <> $Validation4 ; Checks that Document Type = PERM EndIf EndFunc Func ValidationCheck ($check1) $blank = StringLen ($check1) If $check1 Then EndIf EndFunc Func PreCheck($dFolder, $sFolder, $cFolder) ;----------------PreCheck for Destination Folder-------------- If FileExists ($dFolder) <> 1 Then $t = 1 Return Else $FileLog = FileOpen($dFolder & "\FileLog.log", 1) EndIf ;----------------End PreCheck-------------------------- ;----------------PreCheck for Source Folder-------------- If FileExists ($sFolder) <> 1 Then _FileWriteLog($FileLog, "Path to Pending Folder -- " & $sFolder & " -- does not exist") $t = 1 Return EndIf ;----------------End PreCheck-------------------------- ;----------------PreCheck for Completed Folder--------- If FileExists ($cFolder) <> 1 Then _FileWriteLog($FileLog, "Path to Completed Folder -- " & $cFolder & " -- does not exist") $t = 1 Return EndIf ;----------------End PreCheck-------------------------- EndFunc Func ListArray($sFolder, $Filter) $aFileList = _FileListToArray($sFolder, $Filter, 1) ;Create an array of files from the source folder filtering by filetype ;in the config.ini files for the specified section If @error = 1 Then ;MsgBox($MB_SYSTEMMODAL, "", "Path was invalid.") _FileWriteLog($FileLog, "Path to File(s) is Invalid") $t = 1 Return EndIf If @error = 4 Then ;MsgBox($MB_SYSTEMMODAL, "", "No file(s) were found.") _FileWriteLog($FileLog, "No File(s) were found, exiting.") $t = 1 Return EndIf EndFunc ;==>ListArray  
       
       
       
    • By Wingens
      Hi I am trying to read multiple sections from an ini file into an array and use the result to calculate how many records there are from the suppliers and this devided into the status records that belong to it. The problem I am having; I am able to use Ubound to calculate how many record there are in total to the option chosen from the combo box, but where I am getting stuck is the part to link the status and leverancier to each other and count them.
      Hope some one can help me.
      My code right now:
      #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <file.au3> #include <array.au3> $Form1 = GUICreate("Form1", 615, 437, 569, 253) $LEVCOMBO = GUICtrlCreateCombo("", 184, 112, 145, 25, BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL)) Global $aSections = IniReadSectionNames(@ScriptDir & "\leveranciers.ini") If (Not @Error) Then GUICtrlSetData($LEVCOMBO, _ArraytoString($aSections, "|", 1), $aSections[1]) $LABEL = GUICtrlCreateLabel("Totaal aantal RMA aanvragen: ", 48, 200, 250, 21) $TOTALCOUNT = GUICtrlCreateLabel("", 200, 200, 100, 21) $LABEL2 = GUICtrlCreateLabel("Aantal aangevraagd: ", 48, 225, 250, 21) $TOTALAANGEVRAAGD = GUICtrlCreateLabel("", 200, 225, 100, 21) $LABEL3 = GUICtrlCreateLabel("Aantal verzonden: ", 48, 250, 250, 21) $TOTALVERZONDEN = GUICtrlCreateLabel("", 200, 250, 100, 21) $LABEL4 = GUICtrlCreateLabel("Aantal afgehandeld: ", 48, 275, 250, 21) $TOTALAFGEHANDELD = GUICtrlCreateLabel("", 200, 275, 100, 21) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $LEVCOMBO COMBO() EndSwitch WEnd Func COMBO() Local $hINI_FILENAME = @ScriptDir & "\ini.ini" $READAANGEVRAAGDRMA = IniReadSection($hINI_FILENAME, 'LEVERANCIER') $READSTATUS = IniReadSection($hINI_FILENAME, 'STATUS') $VAR = GUICtrlRead($LEVCOMBO) $READAANGEVRAAGDRMACOUNT = _ArrayFindAll($READAANGEVRAAGDRMA, $VAR, Default, Default, Default, Default, 1) GUICtrlSetData($TOTALCOUNT,UBound($READAANGEVRAAGDRMACOUNT)) $nb = $READAANGEVRAAGDRMA[0][0] Local $res[$nb+1][3] $res[0][0] = $nb For $i = 1 to $nb $res[$i][0] = $READAANGEVRAAGDRMA[$i][1] $res[$i][1] = $READSTATUS[$i][1] Next _ArrayDisplay($res) EndFunc And the ini files that goes with it:
      ini.ini:
      [STATUS] 1=Afgehandeld 3=Verzonden 4=Aangevraagd 5=Aangevraagd 6=Aangevraagd 7=Aangevraagd 8=Verzonden 9=Aangevraagd 10=Aangevraagd 11=Aangevraagd 12=Aangevraagd 13=Aangevraagd 14=Aangevraagd 15=Aangevraagd 16=Aangevraagd 17=Aangevraagd 18=Aangevraagd 19=Aangevraagd 20=Aangevraagd 21=Aangevraagd 22=Aangevraagd [LEVERANCIER] 9=Dobit B.V. 1=Dobit B.V. 10=Dobit B.V. 11=Dobit B.V. 12=Dobit B.V. 13=Dobit B.V. 14=Asus 15=Asus 16=Brother 17=Dobit B.V. 18=Dobit B.V. 19=Dobit B.V. 20=Dobit B.V. 21=Dobit B.V. 22=Asus leveranciers.ini:
      [Kies een leverancier...] [Dobit B.V.] URL =http://eline.dobit.be/eline/master.php [TechData B.V.] URL = [MaxICT B.V.] URL = [Brother] URL= [Asus] URL=https://eu-rma.asus.com/pickup_europe/pickup.aspx?country=nl [HP] URL= [Lenovo] URL= [CCV] URL=  
      test.au3
      ini.ini
      leveranciers.ini
×
×
  • Create New...