Guides/RosettaVBtoJ

From J Wiki
Jump to navigation Jump to search

Here's a list of common Visual Basic commands (from this PDF) so that we can show J equivalents. This may help those more familiar with VB to learn J.

Strings

Here's a general guide to string-handling in J.

VB J Example
Left n{.string    3{.'antenna'
ant
Right -n{.string    _3{.'pleasant'
ant
Base 0 & 1 Always base 0    0{'ABC'
A
Trim dltb    '<',(dltb ' fore and aft '),'>'
<fore and aft>
LTrim dlb    dlb ' only leading'
only leading
RTrim dtb    (dtb 'only trailing '),'.'
only trailing.
LCase tolower    tolower 'QUIET'
quiet
UCase toupper    toupper 'shout'
SHOUT
FormatCurrency, Percent & Number
FormatDateTime
Mid function
Chr Function
Len Function
InStr
String function
InstrRev
Asc Function
Space Function
Replace Function
StrComp
StrConv function

Math

VB J Example
Val Function
Round
Int and Fix functions
Rnd & Randomize
Sgn
Sin, Cos, Tan, Log, Atn & Exp Functions
Abs function
Other Math Functions

Logic

VB J Example
Mod Operator
And
Or Operator
Xor Operator
If Not
Like Operator
Is Operator

Arrays

VB J Example
Erase Statement
Dim
ReDim
Array Function

Files/Folders

VB J Example
Dir
ChDir
ChDrive
CurDir
MkDir
RmDir Function
Kill Function
FileDateTime
FileLen
FileCopy
Cut, Copy & Pasting Text
GetAttr
SetAttr
FreeFile function
Open Function
Close Statement
Line Input
EOF Function
Lof Function
Print Function

Error Handling

VB J Example
On Error Statement
Resume, Resume Next, Resume Line
Error Function

Declarations

VB J Example
Function Procedures
Const
Call Statement
CallByName
Option Explicit
Option Private
Option Compare
Type…End Type
GetObject
CreateObject
Let Statement
TypeName
VarType
DefType

Date/Time

VB J Example
Date
Time
Now
Timer
DateAdd
DateDiff
DateSerial
DateValue
Year
Month
MonthName
WeekDayName
Day
Hour
Minute
TimeSerial
TimeValue
WeekDay

Miscellaneous

VB J Example
MsgBox
Shell
RGB
QBColor
Beep
InputBox
Load
UnLoad
SendKeys
LoadPicture
AppActivate

Values

VB J Example
IsNull
IsEmpty
IsNumeric

Loops and Conditional

VB J Example
If...Then...Else
End Statements
Stop Statement
Switch
GoTo Statement
On...GoSub, On...GoTo Statements
GoSub...Return Statement
With Statement
For...Next Statement
While...Wend Statement
Do...Loop Statement
IIf Statement
For Each...Next Statement
Select Case Statement