August 22, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

My Favourite Functions - Part 1

  • November 17, 2002
  • By Karl Moore
  • Send Email »
  • More Articles »

IsNumeric Function

You can check if a string or variant is a number by using the IsNumeric() function. Here's how it works:

If IsNumeric(Text1.Text) = True Then   MsgBox("That's a number!")Else   MsgBox("That is NOT a number!")End If

You can use IsDate() in much the same way.

-- "Micro" Maria, Ohio.

Remove Redundant Spaces

The Trim() function is one of my favourites. It removes all the leading and trailing spaces within a string. It goes like this:

MsgBox Trim( _ "  this is my string with surrounding spaces  ")

And it returns "this is my string with surrounding spaces", minus the excess baggage! Very useful indeed.

-- James Matthews, an MCP from Down Under.

Is your Program Running Twice?

Check out the PrevInstance property of the intrinsic App object to check if an instance of your program is currently running. Here's a code snippet:

If App.PrevInstance = True Then   MsgBox "Application already running!"   EndEnd If

-- Peter Potter, Anonymous-by-the-Sea

Extracting Numbers

You can use the Val() function to extract numbers from a string, like this:

MsgBox Val("40 years old")

This returns the number 40. Basically, if it sees a number at the beginning of the string, it carries on and grabs it all. If it finds no number at the beginning, it returns 0.

-- Ben Davis, Teenage Programmer from Istanbul.





Page 2 of 4



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel