I do not agree.
To get a correct description of a wish, much information is needed about surrounding equipment / configuration / program / data structure etc .. and it is easy that the focus comes on everything that the reader does not know something about or understand.
When I ask a question, I usually try to get an example with AHK code, which often is possible to run.
The best (for me) had been to ask "straight to the point", but when my problem is complicated…
The description becomes too long, and no one can be able / have time to understand my desire.
When I have tried, nobody has answered my question / desire. (My conclusion is that no one have time to get involved in the issue - I understand).
I am happy when I get any answer in the right direction. (the problems are not always easy for me to describe).
Just describe a question is difficult. The question should be simple and at the same time describe everything. (I may not be so good at it)
When a question is asked and the answers begin to come,
1) I discover "flaws" in my description. eg. the headings do not come in sequence, article numbers can start with zero "0", not in sequense, certain text may need to be attached to quotation marks etc.
2) I discover solutions that I have not thought of.
For example: Understanding how the headings should be handled, in maybe 4 years - when the conditions are changed.
Yes! Most CSV files do not have a header line and some have - depending on how they are created.
Files with header and without header should be handled in the "same way".
Will build one unique AHK-function() for each CSV-file. (all these should handle the data in the same way).
I can give two examples .:
Example1 .:
- The CSV file is checked for availability.
- The date on the CSV-file is checked, it is not too old.
- Check if the CSV file has a headline.
- etc.
- I want to know something about a user.
- Does the user exist?
- What's the name of the user?
Code: Select all
User = 205
SecCode = 8423
...
oUser := CheckUser(User, SecCode)
; or
; oUser := CheckUser(User, SecCode, Computer, File)
If ( oUser = "NotFound" )
{ Error handling - User not found.
}
...
MsgBox % oUser.name ; ( Clara Andersson )
ExitApp
CheckUser(UserName, UserSec, ComputerName := "BackStore", FileCSV := "c:\Temp\OPERATOR.csv")
{ ; Analyze if the file has no headlines
...
; No headlines in the file - create
; - - - Backstore - Rubriker i OPERATOR.db - - - - - - - - - - - - - - - - - - - - -
If ( ComputerName = "BackStore" )
{ ; FronStore = FS & BackStore = BS var denna information finns
aHead =
( LTrim Comments
"KeyName" | "opr_operator", ; (FS/BS) Nyckel till objektet - Rubrik används förmodligen inte (ex. 203)
"Name" | "opr_name", ; (FS/BS) Användarnamn (ex. Frida Larsson)
"Place" | "opr_department", ; (BS) Platsen användaren tillhör (ex. 200=Ort1, 300=Ort2 osv.)
"Pass" | "opr_code", ; (FS/BS) Lösenord / Säkerhetskod (ex. 345)
"Disc1" | "opr_discount", ; (FS/BS) Nivå på personalrabatt (ex. 20 = 20%)
"Undefined1" | "opr_purchper", ; (BS) Används ej
"Undefined2" | "opr_purchytd", ; (BS) Används ej
"Level" | "opr_level", ; (FS/BS) Nivå på behörighhet i kassan (ex. 1-9) 5=normal 9=hög
"class" | "opr_class", ; (BS) Behörigheter (0-999) - 100 Butikssäljare, 200 Driftansvarig, 500 HK, 999 Administratör
"Undefined3" | "opr_salesper", ; (BS) Används ej
"Undefined4" | "opr_cardid", ; (BS) Används ej
"Undefined5" | "opr_salesytd", ; (BS) Används ej
"Date" | "opr_valid", ; (BS) Obehörig när datum (20190528) passerat
"Disc2" | "opr_max_disc", ; (FS/BS) Max rabatt personen kan ge (50 => 50%)
"Chip" | "opr_chipkey" ; (FS/BS) Om chip används vid t.ex. inloggning (vi använder inte)
)
}
; - - - FrontStore - Rubriker i OPERATOR.db - - - - - - - - - - - - - - - - - - - -
If ( ComputerName = "FrontStore" )
{ aHead =
( LTrim Comments
"KeyName" | "opr_id", ; (FS/BS) Nyckel till objektet - Rubrik används förmodligen inte (ex. 203)
"Name" | "name", ; (FS/BS) Användarnamn (ex. Frida Larsson)
"Pass" | "security", ; (FS/BS) Lösenord / Säkerhetskod (ex. 345)
"Undefined1" | "credit", ; (FS) Används ej
"Level" | "acc_level", ; (FS/BS) Nivå på behörighhet i kassan (ex. 1-9) 5=normal 9=hög
"Disc1" | "empl_discount", ; (FS/BS) Nivå på personalrabatt (ex. 20 = 20%)
"Disc2" | "discount", ; (FS/BS) Max rabatt personen kan ge (50 => 50%)
"Chip" | "chipkey" ; (FS/BS) Om chip används vid t.ex. inloggning (vi använder inte)
)
}
; Some Code
If !oOperator.HasKey(KeyValue)
{ MsgBox % "Error handling! `n`nThe User (" Key ") is NOT found!"
Return "Error - Not found" ; Return error message
}
...
Return Operator ; Return some fields / information along with the object
}
To the function() .:
- User Code
- User SecurityCode
- Which Computer ( not required - normally )
- Which CSV-file ( not required - normally )
- Create an object to use in the function - oName[Key(firstkolumn), HeaderName]
- I check if the user exist, if the usercode is correct and the user have permission to use the system.
(otherwise, return an error message (has not decided if the error handling should be in the function or after the call to the function()) - The headings are managed based on which computer it is, and which program created the CSV files.
- If headers are in the CSV file, it is the same header name as in my middle column above.
- Return the second object with some information about the user. eg. oUser.name
To view the information - enter the name of the object and my header name (the first column above)
eg. oUser.name or oUser.pass - Or possibly, an error message about something that did not work in the function().
Example2 .:
- I want to know something about an article.
- Does the article exist?
- What is the barcode for an article?
Code: Select all
ArticleNo = 023456-7654
...
oArt := CheckArt(ArticleNo)
...
MsgBox % oArt.BarCode ; ( 7350053850019 )
ExitApp
CheckArt(ArtNo, ComputerName := "BackStore", FileCSV := "c:\Temp\ARTICLES.csv")
{
...
; - - - Backstore - Rubriker i ARTICLES.db - - - - - - - - - - - - - - - - - - - - -
If ( ComputerName = "BackStore" )
{ ...
}
; - - - FrontStore - Rubriker i ARTICLES.db - - - - - - - - - - - - - - - - - - - -
If ( ComputerName = "FrontStore" )
{
}
...
Return Article
}
The short answer is, different functions for different tasks, but the handling of the headings will be the same.
Because I want to run the same AHK program with as few changes as possible, on several different computers, with CSV files of different structure. Then I felt that the handling of headlines becomes difficult.
I have tested some different solutions, but at present this management of the headings is easiest to handle for me, when all the headline information is in the same string.
This is where this link began - How to convert a string to an array.