Jump to content

Slim down code / do it more easy [SOLVED]


Rex
 Share

Recommended Posts

I'm a bit tired and I made some mistakes in my previous post. Here's the corrected example code.

#include <Array.au3>

Global $customerArray[34][5] ; Customer | number of Collies | Type | weight | Ordre Numbers

For $i = 0 To 33 ; For each customer get the following information:
    _customerNumber()
    _collieCount()
    _collieType()
    _height()
    _order()
Next

Func _customerNumber() ; Get details to modify the array
    $customerArray[$i][0] = "CUSTOMER_" & $i
EndFunc

Func _collieCount()
    $customerArray[$i][1] = "CL_" & $i
EndFunc

Func _collieType()
    $customerArray[$i][2] = "T_" & $i
EndFunc

Func _height()
    $customerArray[$i][3] = "WEIGH_" & $i
EndFunc

Func _order()
    $customerArray[$i][4] = "ORDRE_NUMBERS_" & $i
EndFunc

_ArrayDisplay($customerArray)

You will have to write the functions you need to get the appropriate details.

Edited by czardas
Link to comment
Share on other sites

You might as well do this more compactly.

#include <Array.au3>

Global $customerArray[34][5] ; Customer | number of Collies | Type | weight | Ordre Numbers

For $i = 0 To 33 ; For each customer get the following information:
    $customerArray[$i][0] = "CUSTOMER_" & $i
    $customerArray[$i][1] = "CL_" & $i
    $customerArray[$i][2] = "T_" & $i
    $customerArray[$i][3] = "WEIGH_" & $i
    $customerArray[$i][4] = "ORDRE_NUMBERS_" & $i
Next

_ArrayDisplay($customerArray)

But, please, what is the point of building an array of constants in the first place?

How on earth can this help Rex in outputing his data correctly?

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)

Link to comment
Share on other sites

But, please, what is the point of building an array of constants in the first place?

How on earth can this help Rex in outputing his data correctly?

Every function will be slightly different, so it makes sense to separate them from the main script. For example, some details will not change at all, such as customer Number. That could be excluded from the array altogether, because each row of the array is already numbered. The output will have to be dealt with by another function. Do something with the array when it is full: like grab details of each customer and write the new html code. You can output the information any way you like [see below]. The values in the array are not constants: as they will vary with each new order.

#include <Array.au3>

Global $customerArray[34][5] ; Customer | number of Collies | Type | weight | Ordre Numbers

For $i = 0 To 33 ; For each customer get the following information:
    _customerNumber()
    _collieCount()
    _collieType()
    _height()
    _order()
Next

Func _customerNumber() ; Get details to modify the array
    $customerArray[$i][0] = "CUSTOMER_" & $i
EndFunc

Func _collieCount()
    $customerArray[$i][1] = "CL_" & $i
EndFunc

Func _collieType()
    $customerArray[$i][2] = "T_" & $i
EndFunc

Func _height()
    $customerArray[$i][3] = "WEIGH_" & $i
EndFunc

Func _order()
    $customerArray[$i][4] = "ORDRE_NUMBERS_" & $i
EndFunc

$random = Random(0, 33, 1)

; Display information about a random customer:
MsgBox(0, "Random customer information?", $customerArray[$random][0] & @CRLF & $customerArray[$random][1] & @CRLF & $customerArray[$random][2] & @CRLF & $customerArray[$random][3] & @CRLF & $customerArray[$random][4])

This is meant to be an example of a method that could be used to reduce the complexity of the task. Nothing more, nothing less. There are also other methods. This approach saves having to write out every element in multiple arrays. To get the information you need to fill the array, you could write functions such as: _readSenderInfoFromIniFile() and place it at the appropriate position in the first loop etc.

Edited by czardas
Link to comment
Share on other sites

OMG!

PLEASE, don't take it bad, but your way is terribly wrong in that it makes things very complicated.

First you need to get your input data (for one day) ready in a 2-D table, like this:

One entry (row) per individual end_customer, each comprising (columns):

o) the wholeseller ID

o) the end_customer ID (identical to above, except for 1 genuine wholeseller)

o) number of collie

o) total weight for this customer

o) collie type

o) number of order (optional)

In another 2-D table, for the same day:

one entry (row) per customer, each grouping:

o) end_customer

o) order number

o) order weight (?)

o) order number of collie (?)

Except the things that escape me rightnow, I think that when you have that ready, 90% of your task is done.

The idea is to generate the html by concatenating its components as needed rather than replacing litteral strings in fixed format (html or whatever).

Geez, organizing your data is a job for a database! It would bring us a long way to build that over the forum, but it definitely is the way to do it reliably and painlessly!

My friend, I bet you'll learn to master 2-D arrays shortly and SQLite just after. After that, you'll see how easy that can be compared to :cough: another "solution". Again don't take it bad!

Hi jchd

No offend taken :)

The only way to learn to do things right is to listen to those who tell you what you do wrong :D

I think that a database is to overdo it :D

And the array thing well :D wouldn't know how to do it :huggles:

The main reason i do a replace in a static file is that way it's more easy to change the design/layout og the end document, rather then "hardcode" then document :D

I thing that for now i will write a function that writes my checkups to a file so i can copy paste it, and when then my prog works and we can use it at work, then i can go back and play with slimming it down.

Course as i see it for now I'm way in over my head, mangling with something that i quit don't understand :

I will return to this tropic and post my result when it's done.

Cheers

/Rex

Link to comment
Share on other sites

I've PMed you so that we don't turn this general support forum into a very specific group-coding arena that is likely to be of little generic interest, if any.

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)

Link to comment
Share on other sites

... so that we don't turn this general support forum into a very specific group-coding arena that is likely to be of little generic interest, if any.

If people's input is not wanted, then why would anyone post a topic? I do not pretend that code I write is always correct or cannot sometimes be improved. There are many veteran coders on this forum who have far greater knowledge and experience than me. But if something is not of interest to one person, that does not mean that others might not find it interesting, or possibly even useful.
Link to comment
Share on other sites

If people's input is not wanted, then why would anyone post a topic? I do not pretend that code I write is always correct or cannot sometimes be improved. There are many veteran coders on this forum who have far greater knowledge and experience than me. But if something is not of interest to one person, that does not mean that others might not find it interesting, or possibly even useful.

Hi czardas

Sorry that i havn't responded before :huggles:

I have looked at the code ex. you have provided, but it still don't help me with the checkup if custo,er 1 hve more then 56 chars i have no cal more lines and if then customer 2 also have morde then 56 chars then ......

I don't see how the array help me with that :D

jchd has offered to look at my code to see if there's another way to do that, my code (the entire of it) how ever is not for a public forum :D but i will if and when i way to slim down the func i ask about in this tropic, post it so if it should be of any ones interests to use it or part of it could do so :

Cheers

/Rex

Link to comment
Share on other sites

  • 7 months later...

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