Jump to content
Macro Express Forums

If variable is blank or null


randallf

Recommended Posts

I've had a few problems trying to detect if a variable has a null value.

 

I've tried

 

If string = "" but this doesn't seem to be reliable.

 

Is there an easy way in me3 to tell if a variable has not been assigned a value?

 

How do I strip the value from a particular variable to make it null?

Link to comment
Share on other sites

Is there an easy way in me3 to tell if a variable has not been assigned a value?

How do I strip the value from a particular variable to make it null?

There is not an 'If Null' in Macro Express or Macro Express Pro. However, you can assign values that you decide mean 'NULL' or unassigned. Like these:

 

Variable Set Integer %N1% to -1

Variable Set String %T1% "NULL"

Variable Set String %T1% "**Null**"

Variable Set String %T1% "UNASSIGNED"

Variable Set Decimal %D1% to -1.01

Link to comment
Share on other sites

There is not an 'If Null' in Macro Express or Macro Express Pro. However, you can assign values that you decide mean 'NULL' or unassigned. Like these:

 

Variable Set Integer %N1% to -1

Variable Set String %T1% "NULL"

Variable Set String %T1% "**Null**"

Variable Set String %T1% "UNASSIGNED"

Variable Set Decimal %D1% to -1.01

 

 

Good point, thanks kevin. I'll just have to get back in the habit of front-end declaration when I need this feature.

Link to comment
Share on other sites

Now I'm confused.

With text variables I have always used commands like

Variable Set String %T1% ""

and

If Variable %T1% = ""

Text Box Display: T1 is null

End If

Are you saying this "should" not work?

 

Granted, I would not try it with an integer or a decimal variable.

Link to comment
Share on other sites

Now I'm confused.

With text variables I have always used commands like

Variable Set String %T1% ""

and

If Variable %T1% = ""

Text Box Display: T1 is null

End If

Are you saying this "should" not work?

 

Granted, I would not try it with an integer or a decimal variable.

Also confused, as I've done the same thing.

Link to comment
Share on other sites

In programming languages a value of NULL or NIL is different than blank or empty. Blank or empty means a defined variable has been assigned and is empty. NULL or NIL means that a defined variable has not been assigned.

 

The Macro Express and Macro Express Pro script language is not meant to be a replacement or substitute for a full programming language. Thus, it does not support NULL variables. It does, of course, support blank or empty variables.

 

In short, this example will work the same way you have always used it:

Variable Set String %T1% ""
If Variable %T1% = ""
 Text Box Display: T1 is null
End If

but technically it is slightly incorrect. In this case T1 is not NULL, it is empty. But the difference does not matter in the macro script.

 

Here are a couple of resources if if you want to learn more:

Link to comment
Share on other sites

To clarify, the reason perhaps that I am encountering problems with this and others may not is that I am using things like

 

Clipboard copy (from like, an excel cell or a 'blank' line (which might have a CR/LF on it)

Set String

If string =""

 

So my strings just might not be totally blank. The solution presented solves the problem, except when using text file process because you can't cram it all into the loop (it would just overwrite the variable and front-end declaration would only work for the first line). In these I have to use strip cr/lf and trim on the variables to get them to work where if string ="" is required.

Link to comment
Share on other sites

  • 4 weeks later...
I've had a few problems trying to detect if a variable has a null value.

 

I've tried

 

If string = "" but this doesn't seem to be reliable.

 

Is there an easy way in me3 to tell if a variable has not been assigned a value?

 

How do I strip the value from a particular variable to make it null?

 

 

 

What about trimming the variable before the comparison? The code above wouldn't catch an "empty" variable with spaces.

 

 

Side note:

Copying from excel I have found to be a pain. My solution was to either use <F2> to open the cell then have the macro select the contents or I have a macro that will select the entire spread sheet and convert it to a tabbed delimited csv file on my desktop. When reads much better into macro express.

 

It only takes about 40 lines of code to do this and produces much better results when working with excel. I left my headings in, you will notice I spent too much time creating the flowerbox :D

 

<REM2:++==========================================================++><REM2:*-^*-^*-^*-^*-^*-^*-^*-^*-^*-Macro Title-^*-^*-^*-^*-^*-^*-^*-^*-^*-^*-^*-^><REM2:     Macro Title Create CSV From Excel><REM2: ><REM2: ><REM2:*-^*-^*-^*-^*-^*-^*-^*-^*-^*-Description-^*-^*-^*-^*-^*-^*-^*-^*-^*-^*-^*-^><REM2:     Macro Description ><REM2:        1.  Get claim information from spreadsheet><REM2:        2.  Format to Comma Delimited><REM2:        3.  Ouput to CSV File><REM2: ><REM2:~`~`~`~`~`~`~`~`~`~`~`~`Author`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`><REM2:.-*´¨) ¸.-*¨) ¸.-´¸.-*´¨) ¸.-*¨) ¸.-¸.-*´¨)¸.-*¨).-*´¨) ¸.-*¨) ¸.-´¸.-*´¨) ¸.-*¨) ¸.-¸.-*´¨)¸.-*¨)><REM2:(¸.-´ (¸.-´ (¸.-` (¸.-´(¸.-´ (¸.- First Name  (¸.-´ (¸.-´-´(¸.- (¸.-´(¸.-´ -´(¸.- (¸.-´(¸.-´-´(¸.-><REM2:.-*´¨) ¸.-*¨) ¸.-´¸.-*´¨) ¸.-*¨) ¸.-¸.-*´¨)¸.-*¨).-*´¨) ¸.-*¨) ¸.-´¸.-*´¨) ¸.-*¨) ¸.-¸.-*´¨)¸.-*¨)><REM2: (¸.-´ (¸.-´-´(¸.- (¸.-´Last Name (¸.-´-´(¸.-´ (¸.-´-´(¸.-(¸.-´ -´(¸.- (¸.-´(¸.-´-´(¸.-(¸.-´(¸.-´><REM2:.-*´¨) ¸.-*¨) ¸.-´¸.-*´¨) ¸.-*¨) ¸.-¸.-*´¨)¸.-*¨).-*´¨) ¸.-*¨) ¸.-´¸.-*´¨) ¸.-*¨) ¸.-¸.-*´¨)¸.-*¨)><REM2: (¸.-´(¸.-(¸.-´-´(¸.- (¸.-´ (¸.-´-´04/29/09 -´ (¸.-´(¸.- (¸.-´ -´(¸.-(¸.-´(¸.-´ -´(¸.-(¸.-´(¸.-><REM2:.-*´¨) ¸.-*¨) ¸.-´¸.-*´¨) ¸.-*¨) ¸.-¸.-*´¨)¸.-*¨).-*´¨) ¸.-*¨) ¸.-´¸.-*´¨) ¸.-*¨) ¸.-¸.-*´¨)¸.-*¨)><REM2:~`~`~`~`~`~`~`~`~`~`~`~`Mods`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`><REM2:     MOD: User Name, Date, Description of Mod><REM2: ><REM2: ><REM2:++==========================================================++><REM2:><REM2:><REM2:><REM2:><REM2:-=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=-><REM2:                                           Variables><REM2:-=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=-><REM2:T70: File Location><REM2:T70: Ouput Folder><REM2:T72: Data location><REM2:-=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=-><REM2:                                           Variables><REM2:-=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=--=+=-><REM2:><REM2:><REM2:><REM2:><REM2:><REM2:************************************************************************
***************><REM2:                                                   Initalization><REM2:************************************************************************
***************><REM2:><REM2:+=--=+=--=+=--=+=File Path Setups+=--=+=--=+=--=+=><REM2:T70: File Location><VSETMISC:T70:Path to Desktop><REM2:T70: Ouput Folder><TMVAR2:07:70:00:000:000:\Excel To CSV Output><REM2:T72: Data location><TVAR2:72:01:%T70%\Excel SpreadSheet CSV.csv><REM2:><REM2:><REM2:+=--=+=--=+=--=+=Create CSV File+=--=+=--=+=--=+=><GETCONTROL:01:EXCEL.EXE:001:bosa_sdm_XL9Go To><TEXTTYPE:<F5>><WAITCONTROL:000010:000000:01:02><TEXTTYPE:A1<ENTER>><WAITPB><TEXTTYPE:<CTRL>a><WAITPB><REM2:><CLIPC><REM2:cannot empty clipboard!!!! excel crashes long wait needed><MSD:500><REM2:><REM2:><TVAR2:01:03:><REM2:><REM2:><REP3:08:000001:000001:0003:0:01:A><REM2:><TBOX4:T:3:Center000Top001158000332:000:Copied Contents%T1%><MENU2:2:T:03:000553Center:Verify SelectionIs the Above Screen The Proper Selected Excel Document? (Formatting too)

Note: The columns may not line up. Just verify that the information is there from the spread sheet.1: Yes 
2: No><TBCLOSE:Copied Contents><REM2:><IFVAR2:1:03:1:B><REM2:><TBOX4:T:4:Center000Top000278000200:000:Correct SelectionSelected the cells that are to be looked up.

Press OK when done><REM2:><CLIPC><MSD:500><REM2:><TVAR2:01:03:><ENDIF><ENDREP><REM2:><REM2:><REM2:+=--=+=--=+=--=+=Output Excel to Readable Spread Sheet+=--=+=--=+=--=+=><TBOX4:T:3:CenterCenter000278000200:000:Please WaitFormatting Copied Information...

Processing><REM2:This allows for Comma Delimited, Standard is tab delimited><DIS:<TMVAR2:21:01:01:000:000:	,><REM2:><TMVAR2:17:01:00:000:000:%T72%F><TBCLOSE:Please Wait><REM2:><REM2:><REM2:><REM2:><REM2:><REM2:><REM2:><REM2:><REM2:><REM2:*************************************-END-*******************************************><REM2:                                                   Initalization><REM2:*************************************-END-*******************************************>

 

 

Cheers,

 

Don

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...