What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Determining Empty variables

Pages: (2): « First [ 1 ] 2 » Last »
Determining Empty variables
Author: Message:
le-foot
New Member
*


Posts: 9
Joined: Apr 2008
O.P. Determining Empty variables
How do I determine if a variable is empty?

For example, in PHP it is empty($variable), what is it in the script?

Thanks
04-28-2008 10:36 AM
Profile E-Mail PM Find Quote Report
Skarbo
New Member
*


Posts: 7
38 / Male / Flag
Joined: Apr 2008
RE: Determining Empty variables
Some methods:
($variable == null)
or just
(!$variable)
04-28-2008 10:41 AM
Profile E-Mail PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Determining Empty variables
code:
var myVariable;

if ( typeof myVariable === 'undefined' ) Debug.Trace ( 'Your variable is empty' );
else Debug.Trace( typeof myVariable );

Each variable has a "type" if the variable is empty it will be undefined.

This checks if the veriable has been initialized as a specific type. Mattike's post is more correct

This post was edited on 04-28-2008 at 04:16 PM by matty.
04-28-2008 01:20 PM
Profile E-Mail PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
31 / Male / Flag
Joined: Apr 2004
RE: Determining Empty variables
To make a function which acts exactly like the empty() function in PHP, you'll have to go a bit further, as stated in the PHP documentation:
quote:
Source: http://www.php.net/manual/en/function.empty.php

The following things are considered to be empty:
  • "" (an empty string)
  • 0 (0 as an integer)
  • "0" (0 as a string)
  • NULL
  • FALSE
  • array() (an empty array)
  • var $var; (a variable declared, but without a value in a class)

Depending on what you want to do, you can choose which "kind of emptiness" you want to check:
  • If it's a number, boolean, undefined or NULL variable, you can simply use if(!variable)
  • If it's a string, you can compare it to an empty string with if(variable === "")
  • If it's an array, you can check if it's empty with if(variable.length === 0)
  • etc...

This post was edited on 04-28-2008 at 04:14 PM by Matti.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
04-28-2008 04:14 PM
Profile E-Mail PM Web Find Quote Report
vikke
Senior Member
****

Avatar

Posts: 900
Reputation: 28
31 / Male / Flag
Joined: May 2006
RE: Determining Empty variables
Mattike: == is the equal operator, not ===.
4 8 15 16 23 42
04-28-2008 04:41 PM
Profile E-Mail PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Determining Empty variables
quote:
Originally posted by vikke
Mattike: == is the equal operator, not ===.
=== Is the bitwise-equal operator.

This post was edited on 04-28-2008 at 06:00 PM by matty.
04-28-2008 05:55 PM
Profile E-Mail PM Find Quote Report
John Anderton
Elite Member
*****

Avatar

Posts: 3908
Reputation: 80
37 / Male / Flag
Joined: Nov 2004
Status: Away
RE: Determining Empty variables
quote:
Originally posted by matty
quote:
Originally posted by vikke
Mattike: == is the equal operator, not ===.
=== Is the bitwise-equal operator.
Also used to type specificity.
vikke, in php if you evaluate 0==false, the value would be true. Because its not testing the type of operands stored. doing 0===false would make it test the type as well which as matty correctly pointed out, is done by checking equality bitwise :-)
[

KarunAB.com
]

[img]http://gamercards.exophase.com/459422.png[
/img]
04-28-2008 06:00 PM
Profile E-Mail PM Web Find Quote Report
MeEtc
Patchou's look-alike
*****

Avatar
In the Shadow Gallery once again

Posts: 2200
Reputation: 60
38 / Male / Flag
Joined: Nov 2004
Status: Away
RE: Determining Empty variables
I recommend checking out the PHP.js project site, there are many PHP equivalents posted that are available

http://kevin.vanzonneveld.net/techblog/article/ja...nt_for_phps_empty/
[Image: signature/]     [Image: sharing.png]
I cannot hear you. There is a banana in my ear.
04-28-2008 10:10 PM
Profile PM Web Find Quote Report
Stigmata
Veteran Member
*****



Posts: 3520
Reputation: 45
20 / Other / Flag
Joined: Jul 2003
RE: Determining Empty variables
I normally use (!$variable)?

or is this bad practice?
04-28-2008 10:49 PM
Profile PM Web Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
31 / Male / Flag
Joined: Apr 2004
RE: Determining Empty variables
quote:
Originally posted by Stigmata
I normally use (!$variable)?

or is this bad practice?
It totally depends of what you want to do with it. If you're working with arrays which may be empty or strings which may equal "0", you're better off with empty(). In normal cases however, (!$variable) will do just fine. :)
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
04-29-2008 04:30 PM
Profile E-Mail PM Web Find Quote Report
Pages: (2): « First [ 1 ] 2 » Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On