Jump to content

Recommended Posts

Okay I am trying to make a giant if statement using or so I dont have to write a million if statements

here is my code

$Newness = 0
$Rating = 0


If $Newness == "1 secs" or "2 secs" or "3 secs" or "4 secs" or "5 secs" or "6 secs" or "7 secs" or "8 secs" or "9 secs" or "10 secs" or "11 secs" or "12 secs" or "13 secs" or "14 secs" or "15 secs" or "16 secs" or "17 secs" or "18 secs" or "19 secs" or "20 secs" or "21 secs" or "22 secs" or "23 secs" or "24 secs" or "25 secs" or "26 secs" or "27 secs" or "28 secs" or "29 secs" or "30 secs" or "31 secs" or "32 secs" or "33 secs" or "34 secs" or "35 secs" or "36 secs" or "37 secs" or "38 secs" or "39 secs" or "40 secs" or "41 secs" or "42 secs" or "43 secs" or "44 secs" or "45 secs" or "46 secs" or "47 secs" or "48 secs" or "49 secs" or "50 secs" or "51 secs" or "52 secs" or "53 secs" or "54 secs" or "55 secs" or "56 secs" or "57 secs" or "58 secs" or "59 secs" or "60 secs" or "1 minute" or "2 minutes" or "3 minutes" or "4 minutes" or "5 minutes" Then $Rating = $Rating + 10
If $Newness == "6 minutes" or "7 minutes" or "8 minutes" or "9 minutes" or "10 minutes" Then $Rating = $Rating + 9
If $Newness == "11 minutes" or "12 minutes" or "13 minutes" or "14 minutes" or "15 minutes" or "16 minutes" or "17 minutes" or "18 minutes" or "19 minutes" or "20 minutes" or "21 minutes" or "22 minutes" or "23 minutes" or "24 minutes" or "25 minutes" or "26 minutes" or "27 minutes" or "28 minutes" or "29 minutes" or "30 minutes" Then $Rating = $Rating + 8
If $Newness == "31 minutes" or "32 minutes" or "33 minutes" or "34 minutes" or "35 minutes" or "36 minutes" or "37 minutes" or "38 minutes" or "39 minutes"or "40 minutes" or "41 minutes" or "42 minutes" or "43 minutes" or "44 minutes" or "45 minutes" or "46 minutes" or "47 minutes" or "48 minutes" or "49 minutes" or "50 minutes" or "51 minutes" or "52 minutes" or "53 minutes" or "54 minutes" or "55 minutes"or "56 minutes" or "57 minutes" or "58 minutes" or "59 minutes" or "60 minutes" or "1 hour" or "2 hours" Then $Rating = $Rating + 7
If $Newness == "3 hours" or "4 hours" or "5 hours" Then $Rating = $Rating + 6
If $Newness == "6 hours" or "7 hours" or "8 hours" or "9 hours" or "10 hours" Then $Rating = $Rating + 5
If $Newness == "11 hours" or "12 hours" or "13 hours" or "14 hours" or "15 hours" Then $ProxyRating = $Rating + 4
If $Newness == "16 hours" or "17 hours" or "18 hours" or "19 hours" or "20 hours" Then $Rating = $Rating + 3
If $Newness == "21 hours" or "22 hours" Then $Rating = $Rating + 2
If $Newness == "23 hours" or "24 hours" Then $Rating = $Rating + 1
If $Newness = 0 Then $ProxyRating = $ProxyRating + 0

msgbox (0, "Rating", "Current Rating is " & $Rating);

but my issue is it isnt treating it as a if statement it is adding 10 + 9 + 8 +7 + 6 so on and equaling 51

Im sure its just a simple error but can you help me figure out what im doing wrong its confusing me alot.

thank you

Link to post
Share on other sites

I'm surprised it's giving you an output at all. $Newness is zero and nothing matches that, so it none of those statements should prove true. Also, I haven't ever used double equal signs in AutoIt. I know what they do in C++, but I have never ran into a need for them in AutoIt.

Thinking about it...

#include <ByteMe.au3>

Link to post
Share on other sites

To make the If statements work, they need to be like this If $newness = "this" Or $newness = "that", but a way that provides easier reading although just as much typing is with the Switch statement, see the Helpfile for a better explanation that won't confuse you like I would.. In short though, like this:

Switch $newness
 Case "1 sec", "2 sec"...
  ;do this
 Case "6 minutes", "7 minutes"..
  ;do this
EndSwitch

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Link to post
Share on other sites

Major boo-boo

If $x=0 or 1 Then
BAD

If $x=0 or $x=1 Then
GOOD

The above answer involving a Select/Case statement (or Switch/EndSwitch) would be the best way to go.

Edited by enaiman

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to post
Share on other sites

@sleepydvdr: double equal signs are used to test if strings are equal, case sensitive wise. See the Helpfile, Language Reference | Operators.

That's about what I figured. Again, though, I don't understand why his If statements were evaluating as true since he set the variable $Newness to numeric zero. Anyways, thanks for the tip.

#include <ByteMe.au3>

Link to post
Share on other sites

Much better:

Local $Newness = "9 hours"
Local $Rating = 0
Local $Value

If $Newness == 0 Then
    ; $Rating = $Rating + 0             ; doesn't do anything!
Else
    If StringInStr($Newness, " secs") Then
        $Value = Number($Newness)
    ElseIf StringInStr($Newness, " minutes") Then
        $Value = Number($Newness) * 60
    ElseIf StringInStr($Newness, " hours") Then
        $Value = Number($Newness) * 3600
    EndIf
    Switch $Value
        Case 1 To 5*60                  ; 1s to 5m
            $Rating += 10
        Case 5*60 + 1 To 10*60          ; >5m to 10m
            $Rating += 9
        Case 10*60 + 1 To 30*60         ; >10m to 30m
            $Rating += 8
        Case 30*60 + 1 To 2*3600        ; >30m to 2h
            $Rating += 7
        Case 2*3600 + 1 To 5*3600       ; >2h to 5h
            $Rating += 6
        Case 5*3600 + 1 To 10*3600      ; >5h to 10h
            $Rating += 5
        Case 10*3600 + 1 To 15*3600     ; >10h to 15h
            $Rating += 4
        Case 15*3600 + 1 To 20*3600     ; >15h to 20h
            $Rating += 3
        Case 20*3600 + 1 To 22*3600     ; >20h to 22h
            $Rating += 2
        Case 22*3600 + 1 To 24*3600     ; >22h to 24h
            $Rating += 1
    EndSwitch
EndIf
msgbox (0, "Rating", "Current Rating is " & $Rating)

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

    No registered users viewing this page.

×
×
  • Create New...