Thursday, January 3, 2013

VB Script to Javascript Conversions(Basic)

Converting basic language syntaxs,

1. UCase()  => toUpperCase()

ex:-
UCase(string) => string.toUpperCase();


2. InStr() => indexOf()

ex:-
inStr(string1, string2) => string1.indexOf("string2");

InStr([start,]string,searchvalue[,compare]) => string.indexOf(searchvalue,start);



3. Mid() => substr()

ex:-
Mid(string, 2, 3) => string.substr(2-1,3);

4. Replace() => .replace()

ex:-
Replace(string, "textToReplace", "newText") => string.replace("textToReplace", "newText");

5. CStr() => String()


ex:-
CStr(expressionToString) => String(expressionToString);


6. cInt() => Math.round()

ex:-
cInt(anyNumber) => Math.round(anyNumber);


7. CDbl() => parseFloat()

ex:-
CDbl(134.345) => parseFloat(134.345);


8.object.Exists(keyvalue) -> $.inArray(value, array)

    The Exists method is used to determine whether a key already exists in the specified Dictionary. Returns True if it does and False otherwise.

Code: 
<%
dim mdsTeam
set mdsTeam=CreateObject("Scripting.Dictionary")
mdsTeam.Add "k", "Kushan"
mdsTeam.Add "b", "Bandu"
mdsTeam.Add "m", "Madura"
mdsTeam.Add "v", "Vijitha"
If
guitars.Exists("v") Then
   guitars.Item("v") = "Thilina"
End If
%> 


Output: 
"Kushan"
"Bandu"
"Madura"
"Thilina"
 

javascript ex:-
solutions
jQuery has a utility function for this.
$.inArray(value, array)
   Returns index of value in array. Returns -1 if array does not contain value.
9.
MsgBox() => confirm()
ex:-
If MsgBox("Are you sure you want to delete ") <> vbYes Then
   Validate = False
End If
if(!confirm("Are you sure you want to delete ?")) {
   return false;
}
10. Round(decimalNumber,decimalPoints) => decimalNumber.toFixed(decimalPoints);
ex:-
Round(2.123,2) => 2.123.toFixed(2);




No comments:

Post a Comment