Giter Club home page Giter Club logo

vb2js's People

Stargazers

 avatar  avatar

vb2js's Issues

Incorrect number of array elements in converted JS.

VBA:
Dim Array(5)

Actual JS:
var Array = new Array(5);

Expected JS:
var Array = new Array(6);

In VBA, Array(5) contains index 0 - 5, which creates 6 elements. In JS, 
Array(5) means index of 0 - 4, 
creates total of 5 elements.  If user change VBA to Dim Array (1 to 5) or Dim 
Array(0 to 5), it is not 
making any difference in JS. This is incorrect.  JS should be var Array = new 
Array(6)

Original issue reported on code.google.com by [email protected] on 16 May 2010 at 5:57

Run method is not translated correctly.

VBA Code:
Sub UserInput()
Dim iReply As Integer
   iReply = MsgBox(Prompt:="Do you wish to run the 'update' Macro", _
   Buttons:=vbYesNoCancel, Title:="UPDATE MACRO")
   If iReply = vbYes Then
       Run "TwoLine" ' Run some macro
   ElseIf iReply = vbNo Then
      'Do Other Stuff
      Run "message13" ' Run some macro
   Else 'They cancelled (VbCancel)
       Exit Sub
   End If
End Sub

Converted Code:
function UserInput() {
 var iReply; // Integer
 iReply = MsgBox("Prompt :=", "Do you wish to run the 'update' Macro", "Buttons :=", 
vbYesNoCancel, "Title :=", "UPDATE MACRO");
 if (iReply == vbYes) {
   Run("TwoLine"); // Run some macro
 } else if (iReply == vbNo) {
   // Do Other Stuff
   Run("message13"); // Run some macro
 } else { // They cancelled (VbCancel)
   return;
 }
}

Actual Js code:
function UserInput() {
 var iReply; // Integer
 iReply = confirm("Prompt :=");
 alert (iReply);
 if (iReply == true) {
   TwoLine(); // Run some macro
   alert ("True")
 } else if (iReply == false) {
   // Do Other Stuff
   disp_alert(); // Run some macro
   alert ("False")
 } else { // They cancelled (VbCancel)
   return;
 }
}


Note:
Run Sub/UserForm, Continue, and Run Macro Commands (Run Menu)

Run Sub/UserForm
Runs the current procedure if the cursor is in a procedure or runs the form if 
a form is currently 
active. This command becomes the Continue command when you are in break mode.
If neither Code window nor UserForm is active, this command becomes the Run 
Macro command.

Continue
Resumes running the current procedure or form.

Run Macro
Runs the macro. Syntax is --- Run "name of Macro"
**************************************************************
In JavaScript function can be called directly with it name.


So, Run "Macro-name" of VBA, should be converted to Macro-name(); in javascript

=====================

Run "macroName" ==> macroName()

Run("macroName", arg1, arg2) ==> macroName(arg1, arg2)

Original issue reported on code.google.com by [email protected] on 16 May 2010 at 6:00

Subroutine and Function declared with two access specifiers are not being converted

VBA code:
Public Static Sub test4()
MsgBox ("Public Static Subroutine")
End Sub
'
Private Static Sub test5()
MsgBox ("Private Static Subroutine")
End Sub
'
Public Static Function test6()
MsgBox ("Public Static Function")
End Function
'
Private Static Function test7()
MsgBox ("Private Static Function")
End Function


Converted Code:
var Dim;
MsgBox("Dim Dim Subroutine");
// End Sub; // UNTOUCHED

var Dim;
MsgBox("Dim Dim Subroutine");
// End Sub; // UNTOUCHED

var Dim;
MsgBox("Dim Dim Function");
// End Function; // UNTOUCHED

var Dim;
MsgBox("Dim Dim Function");
// End Function; // UNTOUCHED


Actual JS code:
function test4(){
  alert("Public Static Subroutine");
}

function test5() {
  alert ("Private Static Subroutine");
}

function test6() {
  alert ("Public Static Function");
}

function test7() {
  alert ("Private Static Function");
}
 ashishs on March 05 2009 16:51 (New)
Notes
VBA code:
Private Function test8(x, y) As Integer
test8 = x * y
MsgBox (test8)
test8 = test8 + 4
MsgBox (test8)
End Function

Converted code:
function test8(x, y) { // Integer
 var _test8 = ""; // Stores return value
 _test8 = x * y;
 MsgBox(test8);
 _test8 = test8 + 4;
 MsgBox(test8);
 return _test8;
}

Actual java script code:
function test8(x, y) { // Integer
 var _test8 = ""; // Stores return value
 _test8 = x * y;
 alert(_test8);
 _test8 = _test8 + 4;
 alert(_test8);
 return _test8;
}

Note: converter is not changing all the variables.

Original issue reported on code.google.com by [email protected] on 8 Jun 2010 at 9:48

Vba- Js conversion : Issue on converting into Bitwise operators

Enter the following VB script code to convert

  Dim a As Integer
  a = 10:
  temp = 10 And 20
  temp = a Or 10

  Actual Js :
                   var a; // Integer
                   a = 10;

                   temp = 10 && 20;
                   temp = a || 10;

  Expected Js:
                   var a; // Integer
                   a = 10;

                   temp = 10 & 20;
                   temp = a | 10;

  Note : In Vba the AND, OR and XOR functions as boolean operator as well as bit wise operator. 
FYI http://visualbasic.about.com/od/usingvbnet/l/bldykand_or_not.htm

=======

The same issue is applicable While converting Boolean operators

  Try converting this Vba to Js
     e = 23 > 67 Xor 11 > 8
     f = 23 > 14 Xor 11 > 8
     g = 14 > 23 Xor e
     g = e Xor 11 > 8
     g = e Xor f

  Actual Js :
     e = 23 > 67 ^ 11 > 8;
     f = 23 > 14 ^ 11 > 8;
     g = 14 > 23 ^ e;
     g = e ^ 11 > 8;
     g = e ^ f;

     Note : '^' is a bitwise operator in Js

  Expected Js; Since Js does not have 'Xor' operator or it's equivalent, we can create a login to 
build 'Xor' functionality. Hope this link may helpl 
http://www.howtocreate.co.uk/xor.html
                      if( ( foo && !bar ) || ( !foo && bar ) ) {
                        ...
                      }

Original issue reported on code.google.com by [email protected] on 16 May 2010 at 5:58

Exponent operator (' ^ ') is not converted into equivalent Js function Math.pow()

Enter the following VB script code to convert

  c = 2 ^ 2
  c = 10.01 ^ 2
  c = 10.9 ^ 1.1
  c = 10 ^ a
  c = a ^ 10
  c = a ^ b

3. Actual JS :  operator '^' is being converted into exp() but there is no 
function 'exp' in Javascript
  c = exp(2, 2);
  c = exp(10.01, 2);
  c = exp(10.9, 1.1);
  c = exp(10, a);
  c = exp(a, 10);
  c = exp(a, b);

  Expected.JS:
  c = Math.pow(2, 2);
  c = Math.pow(10.01, 2);
  c = Math.pow(10.9, 1.1);
  c = Math.pow(10, a);
  c = Math.pow(a, 10);
  c = Math.pow(a, b);

Original issue reported on code.google.com by [email protected] on 16 May 2010 at 6:02

Variable Declaration format.

In VBA and javascript, we can declare variables in single line for example.

VBA:
Dim Father, Mother
Dim Son, Daughter, Nephew, Niece

Java Script:
var Father, Mother;
varSon, Daughter, Nephew, Niece;

********************************************************************************
************************************************
But, converter is changing the format, change in format is not a problem for  
javascript execution. But change is format is a cosmetic relative change.

VBA code:
Dim Father, Mother
Dim Son, Daughter, Nephew, Niece

Conversion done by Converter:
var Father;
var Mother;
var Son;
var Daughter;
var Nephew;
var Niece;
var GrandMa;

Actual conversion would be:
var Father, Mother;
varSon, Daughter, Nephew, Niece;


********************************************************************************
*********
If we declare the data type in the single line like:
VBA code:
Dim FirstName As String, LastName As String
Dim Address As String, City As String, State As String

Conversion done by converter:
var FirstName; // String
var LastName; // String
var Address; // String
var City; // String
var State; // String

Actual conversion would be:
var FirstName // String, LastName // String, Address // String, City // String, 
State // String;

---------

Variable can be declared as String by two types:
1. With "As String" to the variable
2. Using the $ character at the end of the variable.

VBA --- JS converter should discard the $ character at the end.

Converter code is working fine for other character
% for Integer
@ for long & currency
! for Single
# for double


VBA code:
Dim CountryName As String
' The type character for the String data type is $
Dim CountryName$

Conveterd output:
var CountryName; // String
// The type character for the String data type is $
var CountryName$;

Actual Output
var CountryName; // String
// The type character for the String data type is $
var CountryName;

Original issue reported on code.google.com by [email protected] on 8 Jun 2010 at 9:46

Does VBA --- > JS converter take care of the reserved keywords of javascript

I am not sure about, how vba -- > js converter is handling the javascript 
reserved keywords.
If a macro in VBA is written, without taking care of the reserved keywords of 
javascript.
Then after conversion javascript will show errors, as variables are defined 
with the keywords.

Here is the converted sample, all the variables are the reserved keywords in 
javascript .

Dim catch As String
Dim class As String
Dim const As String
Dim debugger As String
Dim enum As String
Dim extends As String
Dim finally As String
Dim is As String
Dim namespace As String
Dim super As String
Dim throw As String
Dim try As String
Dim use As String
Dim volatile As String
Dim break As String
Dim continue As String
Dim do As String
Dim for As String
Dim import As String
Dim new As String
Dim this As String
Dim void As String
Dim case As String
Dim default As String
Dim else As String
Dim function As String
Dim in As String
Dim return As String
Dim typeof As String
Dim while As String
Dim comment As String
Dim delete As String
Dim export As String
Dim if As String
Dim label As String
Dim switch As String
Dim var As String
Dim with As String

var As; // String
var catch; // String
var class; // String
var Const; // String
var debugger; // String
var enum; // String
var extends; // String
var finally; // String
var Is; // String
var namespace; // String
var super; // String
var throw; // String
var try; // String
var use; // String
var volatile; // String
var break; // String
var continue; // String
var Do; // String
var For; // String
var import; // String
var New; // String
var this; // String
var void; // String
var Case; // String
var default; // String
var Else; // String
var Function; // String
var in; // String
var return; // String
var typeof; // String
var While; // String
var comment; // String
var delete; // String
var export; // String
var If; // String
var label; // String
var switch; // String
var var; // String
var With; // String


actually for javascript reserved keywords converter should complain, or during 
conversion it should assign some different variable name's.
It's just a suggestion, they may be many ways to resolve.
Like, we can add "_" underscore to the starting of the variable name, or change 
the case for the first character in the variable name.



That's an interesting test case... I hadn't thought of this one. Turns out
some of these are invalid though. But we need a way to handle it for the
rest.


I think, the keywords that you marked as invalid in VBA, is incorrect.
Reason, the VBA keywords start (First letter) with uppercase, not with the
lower case.
Could you please check once.

Here, are few VBA keywords, all has the uppercase as first letter of the
keyword.
VBA key Words:

And          As         Boolean      ByRef          Byte            ByVal
Call         Case       CBool         CByte         CDate          CDbl
CInt         CLng       Const         CSng          CStr            Date
Declare    Dim         Do             Double        Each           Else
ElseIf       End         EndIf         Error            False          For
Function   Get         GoTo         If                 Integer         Let
Lib           Long       Loop          Me              Mid             Mod
New         Next       Not            Nothing        Option         Or
Private     Public     ReDim       REM            Resume      Select
Set          Single     Static        Step            String          Sub
Then        To           True          Until            vbCrLf          When
Where      With       While



JavaScript Reserved Words
break           continue        do      for             import          new     
        this            void
case            default         else    function        in              return  
        typeof          while
comment         delete          export  if              label           switch  
        var             with




Java Keywords (Reserved by JavaScript)
abstract        implements      protected
boolean         instanceOf      public
byte            int             short
char            interface       static
double          long            synchronized
false           native          throws
final           null            transient
float           package         true
goto            private
as              catch           class
const           debugger        enum
extends         finally         is
namespace       super           throw
try             use             volatile


Other JavaScript Keywords
alert           eval            Link            outerHeight     scrollTo
Anchor          FileUpload      location        outerWidth      Select
Area            find            Location        Packages        self
arguments       focus           locationbar     pageXoffset     setInterval
Array           Form            Math            pageYoffset     setTimeout
assign          Frame           menubar         parent          status
blur            frames          MimeType        parseFloat      statusbar
Boolean         Function        moveBy          parseInt        stop
Button          getClass        moveTo          Password        String
callee          Hidden          name            personalbar     Submit
caller          history         NaN             Plugin          sun
captureEvents   History         navigate        print           taint
Checkbox        home            navigator       prompt          Text
clearInterval   Image           Navigator       prototype       Textarea
clearTimeout    Infinity        netscape        Radio           toolbar
close           innerHeight     Number          ref             top
closed          innerWidth      Object          RegExp          toString
confirm         isFinite        onBlur          releaseEvents   unescape
constructor     isNan           onError         Reset           untaint
Date            java            onFocus         resizeBy        unwatch
defaultStatus   JavaArray       onLoad          resizeTo        valueOf
document        JavaClass       onUnload        routeEvent      watch
Document        JavaObject      open            scroll          window
Element         JavaPackage     opener          scrollbars      Window
escape          length          Option          scrollBy

Original issue reported on code.google.com by [email protected] on 16 May 2010 at 6:06

"vbCrLf" is not being converted to \r\n

VBA code:
msgbox "Hi" & vbcrlf & "midi25"
codeLines = vbCrLf & vbCrLf & "Sub showAmessage()" & vbCrLf & _
      "    Msgbox ""This is a macro created by a macro""" & vbCrLf & _
      "End Sub"


Converted code by VBA --- > js Converter:
msgbox("Hi" + vbcrlf + "midi25");
codeLines = vbCrLf + vbCrLf + "Sub showAmessage()" + vbCrLf + "Msgbox \"This is 
a macro 
created by a macro\"" + vbCrLf + "End Sub";


Actual converted code should be:
alert("Hi" + '\r\n' + "midi25")
codeLines = '\r\n\r\n' + "Sub showAmessage()" + '\r\n' +  "alert(""This is a 
macro created by a 
macro""" + '\r\n' +  "}" + '\r\n\r\n');

Observation:
 1. "msgbox" is not being converted to "alert"
 2. "vbcrlf " is not being converted to "\r\n"


Note:vbcrlf represents a carriage return line feed.
In java script  these are represented as:
\n      new line
\r      carriage return


VBA constant --------- javascript conversion
*********************************************
vbCrLf                  '\r\n'
vbCr                            '\r'
vbLf                            '\n'
vbTab                   '\t'

Original issue reported on code.google.com by [email protected] on 16 May 2010 at 6:09

Optional function parameter

Are parameters specified as Optional correctly handled? What is the correct 
behavior for these 
anyway? How does this play with our handling of named parameters (where we 
split each param into 
2 params - one is the name part and the second is the value part)?

Original issue reported on code.google.com by [email protected] on 16 May 2010 at 6:15

Option Compare String/Binary in VB

What steps will reproduce the problem?
1.
2.
3.

What is the expected output? What do you see instead?


Please use labels and text to provide additional information.


Original issue reported on code.google.com by [email protected] on 16 May 2010 at 6:12

VBA "REM" and "multiple" line comment is not being converted to JS comment

In VBA comment for a line can be done using "Rem" or ' (Single quotes) .
To comment comment multiple lines use the line continuation character, " _".

In java Script comment for a line can be done using "//" to end of line.
For commenting the multiple line, use the " /* comment */ " may span multiple 
lines, but cannot 
be nested

Note:
You cannot continue a REM statement by using a line-continuation sequence ( _).
Once a comment begins, the compiler does not examine the characters for special 
meaning.
For a multiple-line comment, use another REM statement or a comment symbol (') 
on each line.

Observation:
1. REM is not working
2. Multiple lines comments in VBA, is being treated as single line comment in 
javascript.

Example for REM:
VBA code :
REM This entire line is a comment.

converted js code:
REM(Thisentireline == acomment.);

Actual js code would be:
// This entire line is a comment.


Example for Multiple commented line (Note line continuation character, " _" is 
applied at the end 
of every line):
VBA code:
' SystemInfo class for Advanced System Monitor _
 This class reads Windows system information _
 ©2002 Developer Name, Company Name, www.company.com _
  _
 Requirements: _
 Requires advapi.dll and Windows 98/NT+ _
  _
 Usage: _
 Dim WithEvents SystemInfo As SystemInfo ' as a class-level object variable _
 Call Init _
 Handle the events. _
 Destroy to release system resources when no longer required. _
  _
 Limitations: _
 Does not support multi-processor systems.


converted js code:
// SystemInfo class for Advanced System Monitor This class reads Windows system 
information 
©2002 Developer Name, Company Name, www.company.com Requirements: Requires 
advapi.dll 
and Windows 98/NT+ Usage: Dim WithEvents SystemInfo As SystemInfo ' as a 
class-level object 
variable Call Init Handle the events. Destroy to release system resources when 
no longer required. 
Limitations: Does not support multi-processor systems.

Actual js code would be:
/*SystemInfo class for Advanced System Monitor
 This class reads Windows system information
 ©2002 Developer Name, Company Name, www.company.com

 Requirements:
 Requires advapi.dll and Windows 98/NT+

 Usage:
 Dim WithEvents SystemInfo As SystemInfo ' as a class-level object variable
 Call Init
 Handle the events.
 Destroy to release system resources when no longer required.

 Limitations:
 Does not support multi-processor systems.
*/


About use of REM. Rem can be written in three format:
1. Rem
2. rem
3. REM

Anything on the right side of "rem", "Rem", or "REM"  would not be read.


Only "Rem" can be used ,not the "REM" or "rem".

Example:

MyStr1 = "Hello": Rem Comment after a statement separated by a colon.

Rem statement. If the Rem keyword follows other statements on a line, _
it must be separated from the statements by a colon (:).


I don't think I can fix the multi-line comment part of it trivially because of 
the design of the 
converter. I'll leave that as-is for now and fix the Rem part of this bug.

Original issue reported on code.google.com by [email protected] on 16 May 2010 at 6:08

VBA Inbuilt function conversion to javascript objects

VBA --- JS Converter is not converting the VBA inbuilt functions to javascript 
object.
VBA functions details can be found at : 
http://msdn.microsoft.com/en-us/library/3ca8tfek%28VS.85%29.aspx
Javascript Objects  http://www.w3schools.com/JS/js_obj_date.asp

Example:
VBA code:
Dim MyVar
MyVar = Now ' This will return the current date and time

Java script:
var d = new Date(); // This will return the date object, which will have the 
current date and time. display Format (date and time) is different.

It's very easy to subtract, from the current date in VBA, but it is bit 
difficult to subtract, from the current date in JavaScript.
eg:
VBA code:
MsgBox (Now -1)

But we cannot perform
alert(d-1)

Original issue reported on code.google.com by [email protected] on 8 Jun 2010 at 9:49

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.