scriptstopper Posted September 26, 2010 Share Posted September 26, 2010 How is everyone? Stuck on detecting if a variable is blank. If $Variablename has no value, has not been defined, then do .... In the head it's: If $Variable = Null Then Ideas? Thanks. don't think i'm a freeloader. your help has been effective! here's the script contributed - thank you creator and thank you members and thank you authors of autoit!Call Conference Dial-in Script updated from time to time. Link to comment Share on other sites More sharing options...
BrewManNH Posted September 26, 2010 Share Posted September 26, 2010 To check if a variable has been declared use the If IsDeclared("variablename") function. If the variable you're looking for is called $variable, use "variable" in the function. To see if the variable contains nothing in it, use If $Variable = "". 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 GudeHow 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 More sharing options...
wakillon Posted September 26, 2010 Share Posted September 26, 2010 (edited) Do you want a detecting function like this ? Global $_A = '', $_B = 0, $_C = ' ', $_D = 0.5 ConsoleWrite ( "Is $_A Null : " & _IsVarIsNull ( $_A ) & @Crlf ) ConsoleWrite ( "Is $_B Null : " & _IsVarIsNull ( $_B ) & @Crlf ) ConsoleWrite ( "Is $_C Null : " & _IsVarIsNull ( $_C ) & @Crlf ) ConsoleWrite ( "Is $_D Null : " & _IsVarIsNull ( $_D ) & @Crlf ) Exit Func _IsVarIsNull ( $_Var ) If Not $_Var Then Return True Else Return False EndIf EndFunc Edited September 26, 2010 by wakillon AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
JohnOne Posted September 26, 2010 Share Posted September 26, 2010 I dont think it can be null in autoit, even if it does not hold a value it is seen as a string Global $var MsgBox(0,"Var Type",VarGetType($var)) AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
trancexx Posted September 26, 2010 Share Posted September 26, 2010 Do you want a detecting function like this ? Global $_A = '', $_B = 0, $_C = ' ', $_D = 0.5 ConsoleWrite ( "Is $_A Null : " & _IsVarIsNull ( $_A ) & @Crlf ) ConsoleWrite ( "Is $_B Null : " & _IsVarIsNull ( $_B ) & @Crlf ) ConsoleWrite ( "Is $_C Null : " & _IsVarIsNull ( $_C ) & @Crlf ) ConsoleWrite ( "Is $_D Null : " & _IsVarIsNull ( $_D ) & @Crlf ) Exit Func _IsVarIsNull ( $_Var ) If Not $_Var Then Return True Else Return False EndIf EndFunc In AutoIt much better solution than: If Not somevar Then something Else somethingelse EndIf is:If somevar Then somethingelse Else something EndIf @JohnOne, VarGetType is irrelevant. That function shows type (vt) of the variant holding the value of the variable. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
JohnOne Posted September 26, 2010 Share Posted September 26, 2010 (edited) But is it safe to say that all autoit variables start their life as a string type? EDIT: Sorry scriptstopper, we are all being terribly rude. I'm fine, although I'm having a bit of trouble with my colon, nothing to worry about though, thanks for asking. You? Edited September 26, 2010 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
trancexx Posted September 26, 2010 Share Posted September 26, 2010 omg ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
JohnOne Posted September 26, 2010 Share Posted September 26, 2010 We're allowed a little bit of a giggle I hope. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
trancexx Posted September 26, 2010 Share Posted September 26, 2010 (edited) We're allowed a little bit of a giggle I hope. Maybe, maybe not. To answer that question of yours from the above - probably not. It depends if the variable is initialized. This is String type (VT_BSTR): Local $Var This is Int32 (VT_I4) Local $Var = 4 If internally AutoIt would make VT_BSTR and then change its type to VT_I4 and then assign the value, it would make one step more than it should because it always starts with VT_EMPTY as that's the result of variant initialization. So, logically it would be to start with VT_EMPTY (initialization) and then depending on the script code changing type to what's needed. Edited September 26, 2010 by trancexx ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
JohnOne Posted September 26, 2010 Share Posted September 26, 2010 What is confusing me, is what autoit classes the variable type as. I know you said vargettype was irrelevant but i would have expected that function to to be the judge of that very question. Local $var is seen as a string before it is initialzed, and then converted when assigned a value be that an object or a int. I cant speak about autoits internal enviroment, but in the scripting enviroment, it must start its life as string since there is no null. Im pretty crap at explaining myself, sorry. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Nates Posted October 30, 2018 Share Posted October 30, 2018 Just found out where this might apply! The _sql library that we use (from Chris Lambert) apparently brings in NULLS as "Default". I was trying to detect the NULL values using If $varName = "" Then ... EndIf Which was not working, so now I do If IsKeyword($varName) OR $varName = "" Then ... EndIf Which works as it should. Just thought I'd throw this note in here for anyone else using the _sql library and trying to detect empty (NULL) values. Skysnake, cetipabo and MWIProd 3 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