DBNull Parser for VBScript

Function ParseDBNull(objVal,strDataType)

         If ISNull(objVal) = True Then

               Select Case  lcase(strDataType)

                           Case “string”,”datetime”

                                       ParseDBNull = “”

                          Case “numeric”

                                    ParseDBNull = 0

                         Case “boolean”

                                    ParseDBNull = False

                         Case Else

                                     ParseDBNull = “”

                    End Select

             Else

                      ParseDBNull = objVal

              End If

End Function

Adding PopUpMenu Items dynamically to the DataGrid’s PopUpMenu in SalesLogix6.2

Hi All,

You can use the following method to add menu items dynamically to the PopUpMenu of the DataGrid control of the SalesLogix6.2 LAN Client.

Sub PupulateMenu()

dim objMnu,i
dim arrMenuItems

 arrMenuItems = Array(“Menu Item1″,”Menu Item2″,”Menu Item3″,”Menu Item4”)
 set objMnu = <DataGrid Control Name>.PopupMenu

 For i=0 to Ubound(arrMenuItems)
 objMnu.Add
 objMnu.Items(i+1).Caption = arrMenuItems(i)
 Next

End Sub

Sub <DataGrid Control Name>MenuClick(Sender,Item) 

Select case  <DataGrid Control Name>.PopupMenu.MenuIndex
        case 1
             msgbox “Menu Item1 Selected”
        case 2
             msgbox “Menu Item2 Selected”
        case 3
             msgbox “Menu Item3 Selected”
        case 4
             msgbox “Menu Item4 Selected”
        case else
             msgbox “Invalid Menu Option”
 End Select

End Sub

Happy Coding!! 🙂

Convert to numeric

I wrote following function in VBScripts to over come the fundamental problem that I faced when trying to convert any valid numeric value through an ADODB Recordset. Basically the VBScripts IsNumeric() is not working appropriately, it does not parse any valid numeric value. Maybe this is because of some internal issue with the VBScript engine, any way I wrote the following function to convert the given value to its corresponding numeric format. The NULLs, Alpha or Alpha numeric and Empty values will get converted to zero. The function will return either zero or the passed value, only if it can convert to any other numeric type without generating a runtime errors

Function ConvertTonumber(strVal)

on error resume next
  dim numberVal

  numberVal = 0

  if not isnull(strVal) then
     numberVal = cdbl(strVal)
  else
      numberVal=0
  end if

if Err.Number<>0 then
   numberVal=0
end if
ConvertTonumber = numberVal
End Function