Jump to content

ArrayMin not working


Recommended Posts

I have an array

[0] Filler

[1] 100.000

[2] 123.393

[3]

[4]

.....

[98]

[99]

_arraymax() returns the correct answer, but _arraymin is returning a blankstring, I have set to the compnumeric to 1 (numerical) but it still rates an empty array below a lower number, any ideas? I would like to keep the rest of the array blank, so I can add data to it in the app.

Link to comment
Share on other sites

What do you call "filler"? Is that a blank string or --equivalently-- an uninitialized element, then it will be evaluated as Number("") which is 0.

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

What do you call "filler"? Is that a blank string or --equivalently-- an uninitialized element, then it will be evaluated as Number("") which is 0.

Filler is just a string that is non-zero and non-numeric, the min function does not evaluate this value anyway.

Link to comment
Share on other sites

Number('filler') = 0 as well.

Can you post sample code showing us the issue?

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

Number('filler') = 0 as well.

Can you post sample code showing us the issue?

$baby1_graphic = GUICtrlCreateGraphic(254,37,177,177)

$stationeast = GUICtrlRead($baby1_1)

$stationnorth = GUICtrlRead($baby1_2)

$targeteast = GUICtrlRead($baby1_5)

$targetnorth = GUICtrlRead($baby1_6)

If $baby1_grapharray[1][0] = $stationeast And $baby1_grapharray[1][1] = $stationnorth Then

$pos = _ArraySearch($baby1_grapharray,"")

$baby1_grapharray[$pos][0] = $targeteast

$baby1_grapharray[$pos][1] = $targetnorth

Else

Dim $baby1_grapharray[100][2]

$baby1_grapharray[1][0] = $stationeast

$baby1_grapharray[1][1] = $stationnorth

$baby1_grapharray[2][0] = $targeteast

$baby1_grapharray[2][1] = $targetnorth

EndIf

Dim $eastarray[101]

Dim $northarray[101]

$eastarray[0] = "Filler"

$northarray[0] = "Filler"

For $a = 1 to 99

$eastarray[$a] = $baby1_grapharray[$a][0]

Next

For $a = 1 to 99

$northarray[$a] = $baby1_grapharray[$a][1]

Next

_ArrayDisplay($eastarray)

$mine = _ArrayMin($eastarray,1,1)

$maxe = _ArrayMax($eastarray,1,1)

$minn = _ArrayMin($northarray,1,1)

$maxn = _ArrayMax($northarray,1,1)

Basically I am producing two points with co-orinates, Station and Target. If the same Station is specified, a new target is added to the array, otherwise a new array is created, with the station as item 1 and the target as item 2.

so I end up with a master array like this

[0]

[1] 100.000 200.000

[2] 200.000 400.000

[3] 79.092 190.010

[4]

[5]

.....

[99]

I then want the lowest and highest values from each column

So I create two seperate arrays ($eastarray and $northarray) and find the min max of each

Edited by civilcalc
Link to comment
Share on other sites

You should probably be redimensioning (using ReDim) the arrays rather than having them filled with empty space which might be throwing off your search. Also, is there a reason that you're not using the 0 element in the arrays? If you used them you wouldn't have to put the "filler" information in there at all.

One other thing, you declared the arrays with 101 elements, yet you're only assigning something to 100 of them even without taking into account that you're not using the 0 elements for anything, is this intentional?

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

Link to comment
Share on other sites

What's this business about stations and targets? Smells like a game.

Its to do with setting out and GPS construction methods, kind of like a civil engineering calculator, hence my username, civilcalc......

Its nice to know the autoit police are still patrolling the forum, but I suggest you find someone who hasnt been here longer than you, and might not know the rules, so please dont insult my intellegence. Unless your here to help go find a newbie to harass.

It is better to be thought a fool, than open your mouth and remove all doubt.

Edited by civilcalc
Link to comment
Share on other sites

You should probably be redimensioning (using ReDim) the arrays rather than having them filled with empty space which might be throwing off your search. Also, is there a reason that you're not using the 0 element in the arrays? If you used them you wouldn't have to put the "filler" information in there at all.

One other thing, you declared the arrays with 101 elements, yet you're only assigning something to 100 of them even without taking into account that you're not using the 0 elements for anything, is this intentional?

Theres no real reason for not using the zero, other than to rule out the possibility of that causing the error, I am unfamiliar with Redim, but will check it out.

The basics are I have a station point with co-ords (real life) and a target point. The code works out the distance between the points and the whole circle bearing (0-360 degrees), then it plots a small version of the points on a graphic. I have to work out the min and max values, I then addjust the real values by deducting the min values, so one value becomes zero, I then work out the maximum height or width, and scale it to fit the graphic (currently 150 pixels wide). The graphic functions are not my forte, but if this makes any sense to anyone, I would love some help.

Imagine a station point with the co-ords 100,120

Now imagine a point with the co-ords 200,220, this point would be 141.141mm away at an angle of 45 degrees (50 grads for the US among us),

The graphic would plot the station at the value 0,150 (bottom left corner) and the target 150,0 top right corner.

It does this by first reducing the points by the min values, the min value on the "easting" is 100, the min vlaue on the northing would be 120. To give reduced values of 0,0 and 100,100, we now swich the "northing values" as the graphic control draws for the top left corner and not the bottom left corner, to give values of 0,100 and 100,0, we now scale them up by working out the diffs, the ediff is abs(100-0) = 100 and the ndiff is abs(0-100) = 100 as this value is less than the 150x150 graphic control we scale it up 1.5 or the larger of the two diffs divided by 150 to give plot points of 0,150 150,0.

I hope someone understands this, its very clear in my head, but very difficult to explain to someone who doesnt deal with it every day

Edited by civilcalc
Link to comment
Share on other sites

A quick and dirty method of finding the minimum value in an array (that you're not concerned with the layout of) is to use _ArraySort and grab the 0 element because it is going to be the lowest value. As long as the elements in the array don't have to be in a specific order it should work.

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

Link to comment
Share on other sites

We get that (indeed I guessed what it was being used for) but the question remains: why on earth :huh2: do you insist on populating a fixed-size array with only few values, leaving you with hard-to-manage stuff where you have empty cells everywhere which make your simple X-Y enveloppe computation unduly complex and error-prone.

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

A quick and dirty method of finding the minimum value in an array (that you're not concerned with the layout of) is to use _ArraySort and grab the 0 element because it is going to be the lowest value. As long as the elements in the array don't have to be in a specific order it should work.

I like that method, I will give it a go. Thanks

Link to comment
Share on other sites

We get that (indeed I guessed what it was being used for) but the question remains: why on earth :huh2: do you insist on populating a fixed-size array with only few values, leaving you with hard-to-manage stuff where you have empty cells everywhere which make your simple X-Y enveloppe computation unduly complex and error-prone.

I would say that 90% of the time, the array will only have two lines of data in it, and I had a working script that managed just one station and one target, but I want to give the user the ability of using multiple targets, which can occur in the field, so I want to be able to compile a list of the values (the order is mostly irrellevent, but the first value is use to determine if the station is new (requiring a re-draw and a fresh array) or a previously used station, and therefore a new target needs adding to the array, I assumed an array was the easiest way of remembering an undefined amount of historical data. Do you have a cleaner easier way? I forgot to mention I use the diffs to 'center' the graphic within the area, so if the ediff is smal (a long tall thin graphic) I use the ediff to adjust the co-ords to center them, $adjusteast = (150 - $ediff) / 2 for example, and similar for the north values.

Link to comment
Share on other sites

Yes, use arrays as much as you can, but simply use ReDim (see help) to adjust their size to the exact size needed. This way you won't have empty cells, nor "filler" nor "" and your sort will work like a charm in milliseconds.

As an alternative, (cleaner in my view) keep the min and max X and Y values in four separate variables when user enter points coordinates. When they are finished entering points, you have the X and Y boundaries of the rectangle containing all points.

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

Yes, use arrays as much as you can, but simply use ReDim (see help) to adjust their size to the exact size needed. This way you won't have empty cells, nor "filler" nor "" and your sort will work like a charm in milliseconds.

As an alternative, (cleaner in my view) keep the min and max X and Y values in four separate variables when user enter points coordinates. When they are finished entering points, you have the X and Y boundaries of the rectangle containing all points.

Love it, thanks guys, I think I got what I needed, sometimes its hard to see it, and a fresh view works wonders.

Link to comment
Share on other sites

Hah, I've seen users here for as long as you post like they were newbs. I do apologize.

You have been forgiven. I am well aware of the capabilities of AutoIt, and know that it is a perfect tool for automating games. But I totally understand the view of the AutoIt gods, and respect their wishes. I just write software for work, and hope to make a few £'s by passing it on to like minded people. I dont have time for games, and if I did, I'd actually play them, bold idea I know, but call me Old Skool ;-)

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