Jump to content

check if variable has a value


Recommended Posts

hmmm not getting accurate results:

(what im trying to do is, if $status doesnt have anything set for it then set $compression)

For $x = 1 to $assets[0]

Ping($assets[$x])
If @error Then
$status = "OFFLINE"
$compression="???"
EndIf

RegRead ( "\\" & $assets[$x] & "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion", "ProgramFilesDir" )
If @error Then
$status = "NO_ADMIN_RIGHTS"
$compression="???"
EndIf


If Not $status <> "" Then
$compression = IniRead("\\" & $assets[$x] & "\c$\lotus\notes\notes.ini", "Notes", "TCPIP", "NotFound")

If $compression="TCP, 0, 15, 0,,12320" Then
   $compression="YES"
Else
   $compression="NO"
EndIf
EndIf
Edited by gcue
Link to comment
Share on other sites

hmmm not getting accurate results:

(what im trying to do is, if $status doesnt have anything set for it then set $compression)

For $x = 1 to $assets[0]

Ping($assets[$x])
If @error Then
$status = "OFFLINE"
$compression="???"
EndIf

RegRead ( "\\" & $assets[$x] & "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion", "ProgramFilesDir" )
If @error Then
$status = "NO_ADMIN_RIGHTS"
$compression="???"
EndIf


If Not $status <> "" Then
$compression = IniRead("\\" & $assets[$x] & "\c$\lotus\notes\notes.ini", "Notes", "TCPIP", "NotFound")

If $compression="TCP, 0, 15, 0,,12320" Then
   $compression="YES"
Else
   $compression="NO"
EndIf
EndIf

Are you ever initializing/declaring the $status variable? Working from only the snippet posted, that's one detail I'd check.

Plus in your example, is the "double negative" a mistype?

If Not $status <> "" Then

It reads as:

If $status isn't not equal to ""

- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

Link to comment
Share on other sites

right.

if $status does not have a value then....

is there a better way to say it?

Ping($assets[$x])
If @error Then
$status="OFFLINE"
$compression="???"
EndIf

RegRead ( "\\" & $assets[$x] & "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion", "ProgramFilesDir" )
If @error Then
$status="NO_ADMIN_RIGHTS"
$compression="???"
EndIf

Dim $status
If Not $status <> "" Then
$compression = IniRead("\\" & $assets[$x] & "\c$\lotus\notes\notes.ini", "Notes", "TCPIP", "NotFound")
$status=""


If $compression="TCP, 0, 15, 0,,12320" Then
   $compression="YES"
Else
   $compression="NO"
EndIf
EndIf
Edited by gcue
Link to comment
Share on other sites

No Monamo is right you have it backwards...

You can either have

If $status <> "" Then

or

If Not $status = "" Then

<> already makes it not equal, putting a not there puts it back to equal.

While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd
Link to comment
Share on other sites

Wouldn't the following also be valid?

If Not $status Then
    $compression = IniRead("\\" & $assets[$x] & "\c$\lotus\notes\notes.ini", "Notes", "TCPIP", "NotFound")
EndIf

Would it be in error to use it like this?

Dim $status
Ping($assets[$x])

If @error Then
    $status="OFFLINE"
    $compression="???"
EndIf
RegRead ( "\\" & $assets[$x] & "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion", "ProgramFilesDir" )
If @error Then
    $status="NO_ADMIN_RIGHTS"
    $compression="???"
EndIf
If Not $status Then
    $compression = IniRead("\\" & $assets[$x] & "\c$\lotus\notes\notes.ini", "Notes", "TCPIP", "NotFound")
    If $compression="TCP, 0, 15, 0,,12320" Then
       $compression="YES"
    Else
       $compression="NO"
    EndIf
EndIf

Thanks.

Link to comment
Share on other sites

If Not $status Then

If $status is Not True ....?

depends on how AutoIt handles if strings are true/false

- Some languages state all strings as "false" so I'm a little afraid to use that too much or I might mess up elsewhere :)

My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Link to comment
Share on other sites

Wouldn't the following also be valid?

If Not $status Then
    $compression = IniRead("\\" & $assets[$x] & "\c$\lotus\notes\notes.ini", "Notes", "TCPIP", "NotFound")
EndIf
That could work. When a string variable is used in AutoIt for a boolean operation, "" = False, and any string at all = True.

So all of the following strings are boolean True: "0", "1", "True", "False", "Nothing", "Something".

I don't like depending on mixed variable type operations to always keep working however they happen to now, though. So I would prefer:

If $status = "" Then

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...