NDog Posted August 31, 2011 Share Posted August 31, 2011 Hi all I would like some help with logic of a script. I have a text file which I am reading values from. I want to compare if the value equals 'unknown' or 'System Serial Number' or any other amount of values. I want to check that it doesn't equal one of these values and if it doesn't equal such value then return. What I am doing at the moment is probably a stupid way, I am adding a number to a variable and then checking the value if they match the undesired results. Each time it doesn't match it increments a value of 1. At the end if the total value equals the amount of undesired values (in this case 2) then return the "good" value. Here is the code so you can understand more easily. ... $sStr = FileRead(@TempDir &"\mysystem.txt") ; First pass, try to get DMI System Information Serial $aDMI = StringRegExp($sStr, "(?is)dmi\s+system\s+information\h*\v+(.+?)\v{3,}", 1) If NOT @Error Then $aData = StringRegExp($aDMI[0], "(?i)(?:serial)\h+(.+?)(?:\v)+", 3) If Not @Error Then $sID = $aData[0] EndIf EndIf $var = 0 If $sID <> "unknown" Then $var += 1 If $sID <> "System Serial Number" Then $var += 1 ConsoleWrite("UUID = " & $sID &" = "& $var & @LF) If $var = 2 Then Return $sID ;this number corresponds to the amount of entries placed here! ... Thanks for advice! Link to comment Share on other sites More sharing options...
martin Posted August 31, 2011 Share Posted August 31, 2011 Maybe something like this? $posvals = StringSplit("unknown|System Serial Number|another option", "|") $sStr = FileRead(@TempDir & "\mysystem.txt") ; First pass, try to get DMI System Information Serial $aDMI = StringRegExp($sStr, "(?is)dmi\s+system\s+information\h*\v+(.+?)\v{3,}", 1) If Not @error Then $aData = StringRegExp($aDMI[0], "(?i)(?:serial)\h+(.+?)(?:\v)+", 3) If Not @error Then $sID = $aData[0] EndIf EndIf $var = 0 For $n = 1 To $posvals[0] If $sID <> $posvals[$n] Then $var += 1 ConsoleWrite("UUID = " & $sID & " = " & $var & @LF) Next If $var = 2 Then Return $sID ;? Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
NDog Posted August 31, 2011 Author Share Posted August 31, 2011 Thanks martin. I did not need to consolewrite $var, i just put that as a kind of debug. But your logic is making sense. I see you made an array of bad values and then go through them one at a time. I would like to do something like this but the logic is not right. Remember I need to go through all the bad values first and then if they all are not bad values, then return the good value.. I am just trying to get my head around this.... $sStr = FileRead(@TempDir &"\mysystem.txt") ; First pass, try to get DMI System Information Serial $badvalues = StringSplit("unknown|System Serial Number|another option", "|") $aDMI = StringRegExp($sStr, "(?is)dmi\s+system\s+information\h*\v+(.+?)\v{3,}", 1) If NOT @Error Then $aData = StringRegExp($aDMI[0], "(?i)(?:serial)\h+(.+?)(?:\v)+", 3) If Not @Error Then $sID = $aData[0] EndIf EndIf For $n = 1 To $badvalues[0] If Not $sID <> $badvalues[$n] Then ConsoleWrite("UUID = " & $sID & " = " & @LF) Return $sID EndIf Next Link to comment Share on other sites More sharing options...
martin Posted August 31, 2011 Share Posted August 31, 2011 More of the same I suppose. $badvals = StringSplit("unknown|System Serial Number|another option", "|") $goodvals = stringsplit"one good|two good|three goood | as many good as you want", "|") $sStr = FileRead(@TempDir & "\mysystem.txt") ; First pass, try to get DMI System Information Serial $aDMI = StringRegExp($sStr, "(?is)dmi\s+system\s+information\h*\v+(.+?)\v{3,}", 1) If Not @error Then $aData = StringRegExp($aDMI[0], "(?i)(?:serial)\h+(.+?)(?:\v)+", 3) If Not @error Then $sID = $aData[0] EndIf EndIf $var = 0 For $n = 1 To $badvals[0] If $sID <> $badvals[$n] Then $var += 1 Next If $var > 0 Then Return $var For $n = 1 To $goodvals[0] If $sID <> $goodvals[$n] Then $var += 1 Next Return -$var; negative value means good? Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now