Javascript Is Numeric? Use parseInt() to test!

Category : JQuery/JScript

You can use JavaScript’s built-in parseInt() function to easily test for a numeric value:

if (myTextboxValue != parseInt(myTextboxValue))
alert(myTextboxValue + ' is not a whole number');

parseFloat will also allow you to get test if the data is a number (including floats)

NUGGET – Send a Ping using vb.net

Category : VB.Net

Check for a ping inside of a vb.net application with this amazingly simple code:

If My.Computer.Network.Ping("www.google.com", 1000) Then
  		MsgBox("Server pinged successfully.")
	Else

NUGGET – Change column order in a dataTable

Category : ADO / SQL, VB.Net

I had a dataTable with three columns

Name |  Rank  |  Percentage

For my own personal reasons, I needed the Percentage to be the second column and not the third.  Here’s the code to do the trick.

myDataTable.Columns(2).SetOrdinal(1)

NUGGET – Copying one row in a datatable to another row in different datatable.

Category : VB.Net

Sounds easy enough… of course, NOT!  Try it a normal way and you will be scolded for trying to add a row that already belongs to another table… JEEZ WHAT WERE YOU THINKING!  (God forbid, it just know that I want it copied….freaking reference types.)

Anyway,  here’s how you make add a new row to a datatable that is the same as the row in a different datatable.

‘CREATE THE ROW
Dim newRow As DataRow = finalTable.NewRow
‘COPY the ITEMS from your OLD ROW
newRow.ItemArray = OLDrow.ItemArray
‘ADD THE ROW (again… I mean what the heck does finaltable.NewRow do!?!?!?!)
finalTable.Rows.Add(newRow)

===================================================

And that’s it… another nugget.

NUGGET – Excel chart object in .Net – Novice to Ninja in seconds!

Category : VB.Net

Wanna be a .Net / Excel GENIUS CODE MONKEY in seconds? Well let me show you how….

If you would like to know how to create sweet Charts on your excel spreadsheet straight from your code (especially if you are using VB) – do this.

  1. Open your excel spreadsheet.
  2. Record a macro and do all your cool charting stuff
  3. Open the Macro box from the Tools
  4. Choose your newly created Macro and click EDIT

Whalah – the Script editor will open up will all the proper VB code in there for you.  Simply cut and paste this code into your code and then tell your PM that you are a friggin CODING genius and that you need a raise or you’re WALKING!  (ok, that last part might be a bit much).

IF YOU do not know how to create an Excel doc in the first place from Code – check out my previous post entitled: EXCEL : Run, Fill, and Execute Macro… with .Net

** FINALLY you might have to do some small changes to the way the code is formatted… look below to see how I created my own chart object, added it to my workbook and then simply added my NINJA (ahem, macro) code:

‘   Generating the graph
Dim chart As Excel.Chart
chart = wkbk.Charts.Add()

With chart
.ChartType = Excel.XlChartType.xlColumnClustered
.SetSourceData(wksheet.Range(“C1:E11″), 2)

.SeriesCollection(1).Name = “=”"In Range”"”
.SeriesCollection(2).Name = “=”"Attempts”"”

.Location(Where:=Excel.XlChartLocation.xlLocationAsNewSheet, Name:=”Charted Data”)
.HasTitle = True
.ChartTitle.Characters.Text = “HFZ STATE REPORT”

.Axes(1, Excel.XlAxisGroup.xlPrimary).HasTitle = True
.Axes(1, Excel.XlAxisGroup.xlPrimary).AxisTitle.Characters.Text = “Tests”
.Axes(2, Excel.XlAxisGroup.xlPrimary).HasTitle = True
.Axes(2, Excel.XlAxisGroup.xlPrimary).AxisTitle.Characters.Text = “Attempts”

End With

NUGGET – Removing substring from end of String

Category : VB.Net

Ok, you know what you want to remove from the end of a string but for whatever reason you do not know how long the string is (maybe you built it dynamically) -

Here’s my solution – use the .Remove method of the String object and use the .Length method as the first parameter.

i.e. – say I want to remove “<br>” from the end of my string but I am not sure how long it is.  Well I can get the length this way  myString.Length and I want the starting position to be 4 from that total.  So my statement would be:

myString = myString.Remove(myString.Length – 4, 4) — 4 being the amount of places to remove — and whalah… you just removed the last 4 characters of your string!