Jump to content

Recommended Posts

Posted (edited)

Ok I was writing a script where variables change value and I need to find out which one is the smaller value but greater than 0.

I've tried out some codes in different ways but none work ): I don't know what I'm doing wrong since it's very simple math test.

Well I'm posting the diferent codes I wrote, hope to get some head ups...

BTW I'm new to Autoit, scripting and things.

                                                                                    

                                                                                           Test 1

;simple mathematics test to see which number is smaller but greater then zero


;whichever number is the smallest but greater than zero becomes true at the end
$seven = False
$ten = False
$fifteen = False

;in this test $7 and $15 cannot be true unless we change the value
Global $7 = 0,$10 = 10,$15 = 15
;
;
;
;test 1
If $7 > 0 And $7 < $10 And $7 < $15 Then $seven = True

If $10 > 0 and $10 < $7 and $10 < $15 Then $ten = True

If $15 > 0 And $15 < $7 And $15 < $10 Then $fifteen = True
;
if $seven = True Then

MsgBox(0,"Notice!", "Seven is True" & @LF & "$7 is greater than 0 but smaller than $10 y $15",0)

EndIf
;
if $ten = True Then

MsgBox(0,"Notice!", "Ten is True" & @LF & "$10 is greater than 0 but smaller than $7 y $15",0)

EndIf
;
if $fifteen = True Then

MsgBox(0,"Notice!", "Fifteen is True" & @LF & "$15 is greater than 0 but smaller than $7 y $10",0)

EndIf

 

                                                                                                    Test 2

 

;simple mathematics test to see which number is smaller but greater then zero


;whichever number is the smallest but greater than zero becomes true at the end
$seven = False
$ten = False
$fifteen = False

;in this test $7 and $15 cannot be true unless we change the value
Global $7 = 0,$10 = 10,$15 = 15
;
;
;
;test 2
If $7 <> 0 And $7 < $10 And $7 < $15 Then $seven = True
;
If $10 <> 0 and $10 < $7 and $10 < $15 Then $ten = True
;
If $15 <> 0 And $15 < $7 And $15 < $10 Then $fifteen = True
;
if $seven = True Then

MsgBox(0,"Notice!", "Seven is True" & @LF & "$7 is greater than 0 but smaller than $10 y $15",0)

EndIf
;
if $ten = True Then

MsgBox(0,"Notice!", "Ten is True" & @LF & "$10 is greater than 0 but smaller than $7 y $15",0)

EndIf
;
if $fifteen = True Then

MsgBox(0,"Notice!", "Fifteen is True" & @LF & "$15 is greater than 0 but smaller than $7 y $10",0)

EndIf

                                                                

                                                                                                     Test 3

 

;simple mathematics test to see which number is smaller but greater then zero


;whichever number is the smallest but greater than zero becomes true at the end
$seven = False
$ten = False
$fifteen = False

;in this test $7 and $15 cannot be true unless we change the value
Global $7 = 0,$10 = 10,$15 = 15
;
;
;
;test 3
If Not $7 = 0 And $7 < $10 And $7 < $15 Then $seven = True
;
If Not $10 = 0 and $10 < $7 and $10 < $15 Then $ten = True
;
If Not $15 = 0 And $15 < $7 And $15 < $10 Then $fifteen = True
;
if $seven = True Then

MsgBox(0,"Notice!", "Seven is True" & @LF & "$7 is greater than 0 but smaller than $10 y $15",0)

EndIf
;
if $ten = True Then

MsgBox(0,"Notice!", "Ten is True" & @LF & "$10 is greater than 0 but smaller than $7 y $15",0)

EndIf
;
if $fifteen = True Then

MsgBox(0,"Notice!", "Fifteen is True" & @LF & "$15 is greater than 0 but smaller than $7 y $10",0)

EndIf

 

                                                                                                Test 4

 

;simple mathematics test to see which number is smaller but greater then zero


;whichever number is the smallest but greater than zero becomes true at the end
$seven = False
$ten = False
$fifteen = False

;in this test $7 and $15 cannot be true unless we change the value
Global $7 = 0,$10 = 10,$15 = 15
;
;
;
;test 4
If Not $7 = 0 Then
if   $7 < $10 And $7 < $15 Then $seven = True
EndIf
;
If Not $10 = 0 Then
If   $10 < $7 and $10 < $15 Then $ten = True
EndIf
;
If Not $15 = 0 Then
If $15 < $7 And $15 < $10 Then $fifteen = True
EndIf
;
if $seven = True Then

MsgBox(0,"Notice!", "Seven is True" & @LF & "$7 is greater than 0 but smaller than $10 y $15",0)

EndIf
;
if $ten = True Then

MsgBox(0,"Notice!", "Ten is True" & @LF & "$10 is greater than 0 but smaller than $7 y $15",0)

EndIf
;
if $fifteen = True Then

MsgBox(0,"Notice!", "Fifteen is True" & @LF & "$15 is greater than 0 but smaller than $7 y $10",0)

EndIf

 

                                                                                                   Test 5

 

;simple mathematics test to see which number is smaller but greater then zero


;whichever number is the smallest but greater than zero becomes true at the end
$seven = False
$ten = False
$fifteen = False

;in this test $7 and $15 cannot be true unless we change the value
Global $7 = 0,$10 = 10,$15 = 15
;
;
;
;test 5
If ($7 > 0) And ($7 < $10) And ($7 < $15) Then $seven = True

If ($10 > 0) and ($10 < $7) and ($10 < $15) Then $ten = True

If ($15 > 0) And ($15 < $7) And ($15 < $10) Then $fifteen = True
;
if $seven = True Then

MsgBox(0,"Notice!", "Seven is True" & @LF & "$7 is greater than 0 but smaller than $10 y $15",0)

EndIf
;
if $ten = True Then

MsgBox(0,"Notice!", "Ten is True" & @LF & "$10 is greater than 0 but smaller than $7 y $15",0)

EndIf
;
if $fifteen = True Then

MsgBox(0,"Notice!", "Fifteen is True" & @LF & "$15 is greater than 0 but smaller than $7 y $10",0)

EndIf

 

                                                                                                              Test 6

 

;simple mathematics test to see which number is smaller but greater then zero


;whichever number is the smallest but greater than zero becomes true at the end
$seven = False
$ten = False
$fifteen = False

;in this test $7 and $15 cannot be true unless we change the value
Global $7 = 0,$10 = 10,$15 = 15
;
;
;

;test 6
If ($7 <> 0) And ($7 < $10) And ($7 < $15) Then $seven = True
;
If ($10 <> 0) and ($10 < $7) and ($10 < $15) Then $ten = True
;
If ($15 <> 0) And ($15 < $7) And ($15 < $10) Then $fifteen = True
;
if $seven = True Then

MsgBox(0,"Notice!", "Seven is True" & @LF & "$7 is greater than 0 but smaller than $10 y $15",0)

EndIf
;
if $ten = True Then

MsgBox(0,"Notice!", "Ten is True" & @LF & "$10 is greater than 0 but smaller than $7 y $15",0)

EndIf
;
if $fifteen = True Then

MsgBox(0,"Notice!", "Fifteen is True" & @LF & "$15 is greater than 0 but smaller than $7 y $10",0)

EndIf

 

                                                                                                 Test 7

 

;simple mathematics test to see which number is smaller but greater then zero


;whichever number is the smallest but greater than zero becomes true at the end
$seven = False
$ten = False
$fifteen = False

;in this test $7 and $15 cannot be true unless we change the value
Global $7 = 0,$10 = 10,$15 = 15
;
;
;
;test 7
If Not ($7 = 0) And ($7 < $10) And ($7 < $15) Then $seven = True
;
If Not ($10 = 0) and ($10 < $7) and ($10 < $15) Then $ten = True
;
If Not ($15 = 0) And ($15 < $7) And ($15 < $10) Then $fifteen = True
;
if $seven = True Then

MsgBox(0,"Notice!", "Seven is True" & @LF & "$7 is greater than 0 but smaller than $10 y $15",0)

EndIf
;
if $ten = True Then

MsgBox(0,"Notice!", "Ten is True" & @LF & "$10 is greater than 0 but smaller than $7 y $15",0)

EndIf
;
if $fifteen = True Then

MsgBox(0,"Notice!", "Fifteen is True" & @LF & "$15 is greater than 0 but smaller than $7 y $10",0)

EndIf

 

                                                                                                     Test 8

 

;simple mathematics test to see which number is smaller but greater then zero


;whichever number is the smallest but greater than zero becomes true at the end
$seven = False
$ten = False
$fifteen = False

;in this test $7 and $15 cannot be true unless we change the value
Global $7 = 0,$10 = 10,$15 = 15
;
;
;
;test 8
If Not $7 = 0 Then
if   $7 < $10 And $7 < $15 Then $seven = True
EndIf
;
If Not $10 = 0 Then
If   $10 < $7 and $10 < $15 Then $ten = True
EndIf
;
If Not $15 = 0 Then
If $15 < $7 And $15 < $10 Then $fifteen = True
EndIf
;
if $seven = True Then

MsgBox(0,"Notice!", "Seven is True" & @LF & "$7 is greater than 0 but smaller than $10 y $15",0)

EndIf
;
if $ten = True Then

MsgBox(0,"Notice!", "Ten is True" & @LF & "$10 is greater than 0 but smaller than $7 y $15",0)

EndIf
;
if $fifteen = True Then

MsgBox(0,"Notice!", "Fifteen is True" & @LF & "$15 is greater than 0 but smaller than $7 y $10",0)

EndIf

 

                                                                                                      Test 9

 

;simple mathematics test to see which number is smaller but greater then zero


;whichever number is the smallest but greater than zero becomes true at the end
$seven = False
$ten = False
$fifteen = False

;in this test $7 and $15 cannot be true unless we change the value
Global $7 = 0,$10 = 10,$15 = 15
;
;
;
;test 9
If Not $7 = 0 Then
if   ($7 < $10) And ($7 < $15) Then $seven = True
EndIf
;
If Not $10 = 0 Then
If   ($10 < $7) and ($10 < $15) Then $ten = True
EndIf
;
If Not $15 = 0 Then
If ($15 < $7) And ($15 < $10) Then $fifteen = True
EndIf
;
if $seven = True Then

MsgBox(0,"Notice!", "Seven is True" & @LF & "$7 is greater than 0 but smaller than $10 y $15",0)

EndIf
;
if $ten = True Then

MsgBox(0,"Notice!", "Ten is True" & @LF & "$10 is greater than 0 but smaller than $7 y $15",0)

EndIf
;
if $fifteen = True Then

MsgBox(0,"Notice!", "Fifteen is True" & @LF & "$15 is greater than 0 but smaller than $7 y $10",0)

EndIf

 

Well that's all I got I've finally finished copying..... I know I'm provably doing so much lines for a simple thing but again I'm a noob. 

Edited by Mannyfresh15
Typo
  • Moderators
Posted

Mannyfresh15,

I would use an array like this:

#include <MsgBoxConstants.au3>

Global $aValues[20]

$aValues[7] = 0
$aValues[10] = 10
$aValues[15] = 15

Local $iResult = 9999, $iIndex

For $i = 0 To UBound($aValues) - 1
    $iValue = Number($aValues[$i])
    If $iValue > 0 And $iValue < $iResult Then
        $iResult = $iValue
        $iIndex = $i
    EndIf
Next

MsgBox($MB_SYSTEMMODAL, "Lowest value", $iIndex & @CRLF & $iResult)

I think the code is self-explanatory. but please ask if you have any questions.

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

 

Posted

I'll just deal with test1, the rest being left as "an exercise to the reader".

There, you test whether $7 is greater than 0, which it is not ($7 = 0 and 0 0) so the whole condition is false and the first msgbox never shows.
Then you test whether $10 < $7, which boils down to ask if 10 < 0, an obvious NO, so again the condition is false and nothing shows.
Same for the third test, asking whether $15 < $7 (i.e. 15 < 0) and same as above.

If you want to determine the smallest positive value from a bunch of variables, just do like Melba posted, use an array.

 

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)

Posted

M23, thanks for your example. However, it's quite confusing for a noob like me though. On the other hand I'm looking for something a lil more simple IDK if there is. You see in my test I just to identify the lowest value out of three different variables but exclude the one containing 0 is there is one.

  • Moderators
Posted

Mannyfresh15,

if you only ever have 3 variables then you can simplify the code a bit:

#include <MsgBoxConstants.au3>

; Create an array with 3 elements
Global $aValues[3]
$aValues[0] = 0     ; Set these elements to your 3 values
$aValues[1] = 10
$aValues[2] = 15

; These are the placeholders for the value and its index within the array
; We set a ridiculously high value for the max value to start
Local $iResult = 9999, $iIndex

; Loop through the array and check each value
For $i = 0 To 2
    ;This is the value we are checking
    $iValue = Number($aValues[$i])
    ; if it is greater then zero and less that the current max
    If $iValue > 0 And $iValue < $iResult Then
        ; Store the value and its index
        $iResult = $iValue
        $iIndex = $i
    EndIf
Next

; Display the lowest value that is greater then zero
MsgBox($MB_SYSTEMMODAL, "Lowest value", $iIndex & @CRLF & $iResult)

Clearer now?

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

 

Posted
8 minutes ago, jchd said:

I'll just deal with test1, the rest being left as "an exercise to the reader".

There, you test whether $7 is greater than 0, which it is not ($7 = 0 and 0 0) so the whole condition is false and the first msgbox never shows.
Then you test whether $10 < $7, which boils down to ask if 10 < 0, an obvious NO, so again the condition is false and nothing shows.
Same for the third test, asking whether $15 < $7 (i.e. 15 < 0) and same as above.

If you want to determine the smallest positive value from a bunch of variables, just do like Melba posted, use an array.

 

Then I just gonna do something different 

 

3 minutes ago, Melba23 said:

Mannyfresh15,

if you only ever have 3 variables then you can simplify the code a bit:

#include <MsgBoxConstants.au3>

; Create an array with 3 elements
Global $aValues[3]
$aValues[0] = 0     ; Set these elements to your 3 values
$aValues[1] = 10
$aValues[2] = 15

; These are the placeholders for the value and its index within the array
; We set a ridiculously high value for the max value to start
Local $iResult = 9999, $iIndex

; Loop through the array and check each value
For $i = 0 To 2
    ;This is the value we are checking
    $iValue = Number($aValues[$i])
    ; if it is greater then zero and less that the current max
    If $iValue > 0 And $iValue < $iResult Then
        ; Store the value and its index
        $iResult = $iValue
        $iIndex = $i
    EndIf
Next

; Display the lowest value that is greater then zero
MsgBox($MB_SYSTEMMODAL, "Lowest value", $iIndex & @CRLF & $iResult)

Clearer now?

M23

Yes! It's a lot clearer now, thank you so much!

  • Moderators
Posted

Mannyfresh15,

Delighted to hear it.

But when you reply, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - we know what we wrote and it just pads the thread unnecessarily.

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

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...