VBA Migration



VBA.Chr

Chr(90) 
String.fromCharCode(90)


VBA.Instr

INSTR - Returns the position of a substring within a larger string.
VBA - Returns 0 when the substring cannot be found.
JavaScript - Returns -1 when the substring cannot be found.

If VBA.InStr(sVariable, "find this") > 0 Then 

'// JavaScript
if (sVariable.indexOf("find this") > 0) {

VBA.Left

LEFT - Returns a number of characters from the left of a string.

VBA.Left(sVariable, 4) 

'// JavaScript
sVariable.substring(0,4)

VBA.Len

LEN - Returns the number of characters in a string.

VBA.Len(sVariable) 

'// JavaScript
sVariable.length

VBA.Mid

MID - Returns the text string which is a substring of a larger string.
VBA - Start position is 1 based.
JavaScript - Start position is 0 based.
JavaScript - substr method does take the length.
JavaScript - substring method does not take the length but the end character position.

VBA.Mid(sVariable,1,1) 

'// JavaScript
sVariable.substring(0,1)
sVariable.substr(

More Examples:

VBA.Mid(sVariable,2,1) = sVariable.substring(1,1) 
VBA.Mid(sVariable,3,1) = sVariable.substring(2,3)
VBA.Mid(sVariable,3) = sVariable.substring(2,sVariable.length)

VBA.Mid(sVariable,Len(sVariable),1) = sVariable.substring(sVariable.length - 1,1)
VBA.Mid(sVariable,Len(sVariable),1) = sVariable.substring(sVariable.length - 1)
VBA.Mid(sVariable,Len(sVariable)) = sVariable.substring(sVariable.length - 1)

VBA.Mid(sVariable,Len(sVariable),1) = sVariable.substring(sVariable.length - 1,1)
VBA.Mid(sVariable,Len(sVariable) - 1,1) = sVariable.substring(sVariable.length - 2,1)
VBA.Mid(sVariable,Len(sVariable) - 2,1) = sVariable.substring(sVariable.length - 3,1)

VBA.Right

RIGHT - Returns the number of characters from the right of a text string.

VBA.Right(sVariable,1) 

'// JavaScript
sVariable.substring(sVariable.length - 1)

More Examples:

VBA.Right(sVariable, 2) = sVariable.substring(sVariable.length - 2) 

VBA.Right(sVariable,Len(sVariable), 1) = sVariable.substring(sVariable.length - 1, 1)
VBA.Right(sVariable,Len(sVariable), 1) = sVariable.substring(sVariable.length - 1)

VBA.Right(sVariable,Len(sVariable) - 1) = sVariable.substring(sVariable.length - 2)
VBA.Right(sVariable,Len(sVariable) - 5) = sVariable.substring(sVariable.length - 6)

If (VBA.Right(sVariable, 4) = "Text") Then
If sVariable.endsWith("Text") = True Then

Dim sText As String = "some text"
sText.substring(sText.length - 1) = "some tex" 'removes the last character
sText.substring(0, sText.length - 1) = "some tex" 'removes the last character

VBA.Trim

TRIM - Returns the text string removing leading and trailing spaces (String).

Trim(sVariable) 
sVariable.trim()

© 2020 Better Solutions Limited. All Rights Reserved. © 2020 Better Solutions Limited TopPrev