Jump to content

FileOpen + foreign syntax + converting to an array?


MrVining
 Share

Recommended Posts

I have a file that changes somewhat frequently (at least 5 times when this section of my script runs) and I want my script to capture some data from it. The file is much longer, but I have copied the syntax completely with two entries. Every time the file is written it writes the entries in random order, so next time the script reads the file entry yyy could be above xxx. The only two variables I need to work with are "value2" and "value3". The file changes so much that I'm not even sure if it makes sense to convert it into an array, but this is a small part of my FIRST script so I'm a total newb. (I'm pretty excited about what I have learned so far, I have started to work with arrays, and my script is connecting to a remote mysql database and doing some other fun stuff).

The script will have "xxx" and needs to find the number corresponding to it. What's worse (for me) is that it doesn't need the last 4 digits of the number. So the value currently associated with "xxx" is actually "24687". I'm not afraid to read, but I'd like some advice from some experienced people to point me at the right direction.

aaa = {
["xxx_bbb::zzz"] = {
["value1"] = true,
["value2"] = "xxx",
["value3"] = 246870316,
},
["yyy_ccc::zzz"] = {
["value1"] = true,
["value2"] = "yyy",
["value3"] = 32608358,
},
}
Link to comment
Share on other sites

  • Moderators

MrVining,

So you want to look for the digits "24687" in the file and then extract the "value2" and "value3" items in teh lines immediately above it? Is that correct? :huh:

M23

Edit:

If that is the case then this should work:

#include <File.au3>
#include <Array.au3>

Global $aLines
_FileReadToArray("data.txt", $aLines)

$iIndex = _ArraySearch($aLines, "= 24687", 0, 0, 0, 1)
If $iIndex <> -1 Then
    $sVal_3 = StringRegExpReplace($aLines[$iIndex], '.*\["(.*)"\].*', "$1")
    $sVal_2 = StringRegExpReplace($aLines[$iIndex - 1], '.*\["(.*)"\].*', "$1")
EndIf

MsgBox(0, "Result", $sVal_2 & @CRLF & $sVal_3)

on this data:

aaa = {
["xxx_bbb::zzz"] = {
["value11"] = true,
["value12"] = "xxx",
["value13"] = 246870316,
},
["yyy_ccc::zzz"] = {
["value21"] = true,
["value22"] = "yyy",
["value23"] = 32608358,
},
}
Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

First thing you need to make sure is that the data you read is consistent.

As the file changes to frequently how will you make sure that - after you have read block 1 - the file hasn't changed and block 2 is still valid data?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

@ Melba23, I need something like:

Func NewFunc($var)
Array_Magic($var)
EndFunc

$output = NewFunc("xxx")

; $output now = 24687

@ water, The script activates the change in the file up above in a different function, so I shoulc be good there.

@ Melba23, I've started looking into that array include, I'm thinking that will be the ticket. The problem I'm running into with the code you listed is this symbol seems to be throwing me errors:

{

Link to comment
Share on other sites

  • Moderators

MrVining,

So does the code work as you want? :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

MrVining,

This scripting stuff is fun

Very true! :thumbsup:

Sorry I got it the wrong way round - you know where we are if you need a pointer or two to get it working the right way. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Developers

The helpfile explains the options for IF quite well. There are 2 options: A one line if the performs the task defined after the "Then", or the format where the If performs anything between the IF and the endIf line.

Jos

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

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