Sunday, October 28, 2007

Utilizing AppSettings

In web.config create a key and value:

<add key="keyName" value="keyValue" />


Access the AppSetting by calling it in your code behind:

ConfigurationManager.AppSettings.Get("keyName")

Tuesday, October 16, 2007

Hex to Dec (VbScript)

Convert hexidecimal color codes (ie #C0C0C0) to decimal RGB (ie 255,255,255) in vbscript

Public Function GiveDec(Hex)
  if Hex = "A" then
    Value = 10
  elseif Hex = "B" then
    Value = 11
  elseif Hex = "C" then
    Value = 12
  elseif Hex = "D" then
    Value = 13
  elseif Hex = "E" then
    Value = 14
  elseif Hex = "F" then
    Value = 15
  else
    Value = Hex
  end if
  GiveDec = Value
End Function

Public Function HexToDec(Hex)
  Dim a,b,c,d,e,f,x,y,z,fHex
  fHex = Replace(Hex,"#","")

  a = Left(fHex,1)
  a = GiveDec(a)
  b = Mid(fHex,2,1)
  b = GiveDec(b)
  c = Mid(fHex,3,1)
  c = GiveDec(c)
  d = Mid(fHex,4,1)
  d = GiveDec(d)
  e = Mid(fHex,5,1)
  e = GiveDec(e)
  f = Right(fHex,1)
  f = GiveDec(f)

  x = (a * 16) + b
  y = (c * 16) + d
  z = (e * 16) + f

  HexToDec = """" & x & "," & y & "," & z & """"
End Function

Monday, October 15, 2007

Limit text input to numbers (Javascript)

Limit the text field to only numbers (with decimals)

function format(input){
 var num = input.value.replace(/\,/g,'');
  if(!isNaN(num)){
   if(num.indexOf('.') > -1){
   num = num.split('.');
   num[0] = num[0].toString().split('').reverse().join('').replace(/(?=\d*\.?)(\d{3})/g,'$1,').split('').reverse().join('').replace(/^[\,]/,'');
   if(num[1].length > 2){
    alert('You may only enter two decimals!');
    num[1] = num[1].substring(0,num[1].length-1);
   } input.value = num[0]+'.'+num[1];
  } else {
   input.value = num.toString().split('').reverse().join('').replace(/(?=\d*\.?)(\d{3})/g,'$1,').split('').reverse().join('').replace(/^[\,]/,'') };
  } else {
   alert('You may enter only numbers in this field!');
   input.value = input.value.substring(0,input.value.length-1);
  }
}


Limit the text field to only numbers (no decimals)

function formatInt(input){
 var num = input.value.replace(/\,/g,'');
  if(!isNaN(num)){
   if(num.indexOf('.') > -1) {
    alert("You may not enter any decimals.");
    input.value = input.value.substring(0,input.value.length-1);
   }
  } else {
   alert('You may enter only numbers in this field!');
   input.value = input.value.substring(0,input.value.length-1);
  }
}


Call the function within the html input

<input id="text" name="text" size="5" onkeyup="format(this);">