• Welcome to Theos PowerBasic Museum 2017.

My vb6 translator is hitting roadblocks

Started by Murray Ruggiero, January 20, 2011, 02:33:35 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Murray Ruggiero

I have made a vb6 to powerbasic translator - and it has hit some roadblocks.

It generates a main file where I include all the other files.
So it might look like:
#COMPILE EXE
#DIM ALL
#include "c:\myfile1"
#include "c:\myfile2"

and then it has a PBMAIN function.

But I find several problems occur. First of all, if a class method in myFile1 refers to a class in myfile2, I get an error.  Its as if myfile2 has to be included before myfile1. 
Secondly, I get an error in "myfile1" (which contains a class) saying that a PBmain is required.  I don't see why it should be required, since I do supply one in the main file.
I also find that VB6 statements don't have Powerbasic equivalents.  For instance I have a line that converts a variant to a string, but the
translated version gives an error:
     Eachstr = STR$(EachVariant) 
So those are the roadblocks so far.
Eventually, I want to be able to refer to third party libraries, so I will need to be able to translate VB6 code such as:
   "dim MyConn as New ADO.Connection"
          and
    "fs = create.object("Microsoft.scripting")"
But first I have to deal with getting the above main bugs out.
Any help is appreciated.
-- Murray

José Roca

Quote
I also find that VB6 statements don't have Powerbasic equivalents.  For instance I have a line that converts a variant to a string, but the
translated version gives an error:
     Eachstr = STR$(EachVariant)

Use VARIANT$ instead of STR$.

ABout the other problems, can't say without seeing the code.

Murray Ruggiero

OK, with the above errors in mind:
Here is the code produced by my vb6 translator:
(it also has another error I just encountered:
MAINFILE :
#COMPILE EXE
#DIM ALL

#INCLUDE ONCE "WIN32API.INC"  ' include windows api calls
#INCLUDE ONCE "C:\ROUGHSETSCONTAINERLAPTOP\translatedOutput\c_ClassTryTranslatingThis.bas"
#INCLUDE ONCE "C:\ROUGHSETSCONTAINERLAPTOP\translatedOutput\c_ClassCallThis.bas"
#INCLUDE ONCE "C:\ROUGHSETSCONTAINERLAPTOP\translatedOutput\m_ModuleTryPublicTypes.bas"
#INCLUDE ONCE "C:\ROUGHSETSCONTAINERLAPTOP\translatedOutput\c_ClassOneFeature.bas"
#INCLUDE ONCE "C:\ROUGHSETSCONTAINERLAPTOP\translatedOutput\c_Class1GideonDir.bas"

Function PBMAIN() as LONG
    Function = 15
END FUNCTION

====================================================MY NEXT FILE:
FILE c_ClassTryTranslatingThis.bas:

' produced by Vb6ToPowerBasicTranslate on 1/20/2011 9:37:38 AM do not export the class

MACRO BOOLEAN = INTEGER  ' bad method: will be replaced
MACRO TRUE = -1
MACRO FALSE = 0


MACRO enumNumbers = INTEGER
MACRO enumSpanishNumbers = INTEGER
' ***********STRUCTURES AND CLASSES**********
CLASS mystructWithDynamicArray
    INSTANCE m_DynamicArray() AS INTEGER
    INSTANCE m_pontine AS INTEGER

CLASS METHOD CREATE()
DIM m_DynamicArray(0)
END METHOD
INTERFACE i_mystructWithDynamicArray
    INHERIT IUNKNOWN
PROPERTY GET DynamicArray(BYVAL index AS INTEGER) AS INTEGER
   PROPERTY = m_DynamicArray(index)
END PROPERTY
PROPERTY SET DynamicArray (BYVAL index AS INTEGER,BYVAL value AS INTEGER)
   m_DynamicArray(index) = value
END PROPERTY
PROPERTY GET pontine AS INTEGER
   PROPERTY = m_pontine
END PROPERTY
PROPERTY SET pontine (BYVAL value AS INTEGER)
   m_pontine = value
END PROPERTY
END INTERFACE
END CLASS

CLASS myStructTypeWithString
   INSTANCE m_strfield AS STRING
   INSTANCE m_intField AS INTEGER

CLASS METHOD CREATE()
END METHOD
INTERFACE i_myStructTypeWithString
    INHERIT IUNKNOWN
PROPERTY GET strfield AS STRING
   PROPERTY = m_strfield
END PROPERTY
PROPERTY SET strfield (BYVAL value AS STRING)
   m_strfield = value
END PROPERTY
PROPERTY GET intField AS INTEGER
   PROPERTY = m_intField
END PROPERTY
PROPERTY SET intField (BYVAL value AS INTEGER)
   m_intField = value
END PROPERTY
END INTERFACE
END CLASS

TYPE mystructTypeWithInts
    int_one AS INTEGER
    int_two AS INTEGER
END TYPE
TYPE mystructWithFixedArray
    FixedArray(5) AS INTEGER
    pontine AS INTEGER
    bridge AS INTEGER
END TYPE
TYPE myStructWithFixedString
fixstr AS STRING * 5
END TYPE
TYPE privatetype
   appalling AS BYTE
END TYPE

%enumNumbers_one=1
%enumNumbers_two=2

%enumSpanishNumbers_uno=1
%enumSpanishNumbers_dos=2


CLASS ClassTryTranslatingThis

INSTANCE X AS Boolean
INSTANCE VariantX AS VARIANT
INSTANCE y AS INTEGER
INSTANCE z AS STRING

CLASS METHOD MYPRIVATESUB()
DIM cct AS LOCAL i_ClassCallThis
LET cct = CLASS ClassCallThis
cct.TryToUnderstand
' ORIGINAL -- End Sub
END METHOD


CLASS METHOD UseEnum(BYVAL ernie AS enumNumbers)
DIM mort AS LOCAL enumSpanishNumbers
DIM acur AS LOCAL CURRENCY
STATIC localstatic AS INTEGER
DIM strPea AS LOCAL STRING
DIM str5 AS LOCAL STRING
DIM mswfs AS LOCAL myStructWithFixedString
' first comment
' second comment
' ORIGINAL -- str5 = "Has5"
str5 = "Has5"
' ORIGINAL -- mswfs.fixstr = "*ABCD*"
mswfs.fixstr = "*ABCD*"
' ORIGINAL -- acur = 3#   ' third comment
acur = 3#    ' third comment
' ORIGINAL -- mort = enumSpanishNumbers.uno
mort = %enumSpanishNumbers_uno
' ORIGINAL -- ernie = two
ernie = %enumNumbers_two
' ORIGINAL -- strPea = "yahoo! peace may reign!!!"
strPea = "yahoo! peace may reign!!!"
' ORIGINAL -- End Sub ' fourth comment
END METHOD
CLASS METHOD getCurrency(BYVAL MyEnumVariable AS enumNumbers)   AS CURRENCY
  DIM dollars AS LOCAL CURRENCY
DIM mystruct AS LOCAL i_myStructTypeWithString
LET mystruct = CLASS myStructTypeWithString       ' STRING CONSTANT EXPECTED  -- ERROR*************************
DIM mystruct2 AS LOCAL i_myStructTypeWithString
LET mystruct2 = CLASS myStructTypeWithString
dollars = 2.6
  ' ORIGINAL -- getCurrency = dollars
METHOD = dollars
  ' ORIGINAL -- If dollars < 10000.5 Then ' low amount
IF dollars < 10000.5 THEN  ' low amount
       ' ORIGINAL -- getCurrency = -9
METHOD = -9
       ' ORIGINAL -- Exit Function
EXIT METHOD
  ' ORIGINAL -- End If
END IF
  ' ORIGINAL -- MyEnumVariable = one
MyEnumVariable = %enumNumbers_one
  ' ORIGINAL -- MsgBox App.Path & Str$(59.7)
MSGBOX EXE.PATH$ & STR$(59.7)
  ' ORIGINAL -- With mystruct

     ' ORIGINAL -- .strfield = "so what"
mystruct.strfield = "so what"
     ' ORIGINAL -- .intField = 8
mystruct.intField = 8
      ' no code on this line
  ' ORIGINAL -- End With

  ' ORIGINAL -- With mystruct2

     ' ORIGINAL -- .strfield = "so what"
mystruct2.strfield = "so what"
     ' ORIGINAL -- .intField = 8
mystruct2.intField = 8
      ' no code on this line
  ' ORIGINAL -- End With

  ' ORIGINAL -- dollars = 0.8
dollars = 0.8

' ORIGINAL -- End Function
END METHOD

  INTERFACE i_ClassTryTranslatingThis
  INHERIT IUNKNOWN













   ' fourth comment
' ORIGINAL -- Public Sub sayHello(ByVal Q As Integer)
METHOD sayHello(BYVAL Q AS INTEGER)
STATIC N AS INTEGER
DIM myVariant1 AS LOCAL VARIANT
DIM myVariant2 AS LOCAL VARIANT
DIM strstar5 AS LOCAL STRING
DIM MyArr( 5 ) AS LOCAL STRING
DIM EachVar AS LOCAL VARIANT
DIM MyvariantNoType AS LOCAL VARIANT
DIM j AS LOCAL CURRENCY
DIM k AS LOCAL CURRENCY
DIM l AS LOCAL CURRENCY
DIM Eachstr AS LOCAL STRING
N = -5 * Q
    DIM EachVar_countx AS LOCAL INTEGER
DIM EachVar_indexx AS LOCAL INTEGER
EachVar_countx = UBOUND(MyArr)
FOR EachVar_indexx = 0 TO EachVar_countx
EachVar = MyArr(EachVar_indexx)


    ' ORIGINAL -- Eachstr = CStr(EachVar)
Eachstr = VARIANT$(EachVar)
' ORIGINAL -- Next
NEXT
' ORIGINAL -- N = 0
N = 0
   ' ORIGINAL -- MsgBox ("hello world") 'test a comment too.
MSGBOX ("hello world")    'test a comment too.
' ORIGINAL -- End Sub
END METHOD
' ORIGINAL -- Private Function getCurrency(ByVal MyEnumVariable As enumNumbers) As Currency

' ORIGINAL -- Sub NeitherPrivateNorPublic(ByRef t1 As Integer)
METHOD NeitherPrivateNorPublic(BYREF t1 AS INTEGER)
' ORIGINAL -- t1 = 5
t1 = 5
' ORIGINAL -- End Sub
END METHOD
' ORIGINAL -- Static Function Myfunc() As Boolean ' comment about static
METHOD Myfunc()   AS Boolean  ' comment about static
DIM j AS LOCAL INTEGER
' j comment
DIM strq AS LOCAL STRING
DIM MyArr( 5 ) AS LOCAL mystructTypeWithInts
DIM MyArr2( 4 ) AS LOCAL i_myStructTypeWithString
DIM IND_MAKEPVB_1 AS  INTEGER
FOR IND_MAKEPVB_1 = 0 TO UBOUND(MyArr2)
LET MyArr2(IND_MAKEPVB_1) = CLASS myStructTypeWithString
NEXT
DIM MyArr3( 9 ) AS LOCAL i_mystructWithDynamicArray
DIM IND_MAKEPVB_2 AS  INTEGER
FOR IND_MAKEPVB_2 = 0 TO UBOUND(MyArr3)
LET MyArr3(IND_MAKEPVB_2) = CLASS mystructWithDynamicArray
NEXT
DIM MyArrOfInt( 5 ) AS LOCAL INTEGER
DIM MyArrOfDouble( 3 ) AS LOCAL DOUBLE
DIM elt AS LOCAL VARIANT
DIM elt2 AS LOCAL VARIANT
DIM elt3 AS LOCAL VARIANT
j = CINT(59.7)    ' roundoff comment
' ORIGINAL -- strq = "this is a quote" ' comment with quote
strq = "this is a quote"  ' comment with quote
' ORIGINAL -- strq = strq & " append more"
strq = strq & " append more"
' ORIGINAL -- strq = CStr(j) & strq
strq = STR$(j)   & strq
' ORIGINAL -- MyArr(0).int_one = 34
MyArr(0)  .int_one = 34
' ORIGINAL -- MyArr2(1).strfield = "hey jude"
MyArr2(1)  .strfield = "hey jude"
' ORIGINAL -- ReDim MyArr3(2).DynamicArray(17) As Integer
REDIM MyArr3(2)  .DynamicArray(17)   AS INTEGER
' ORIGINAL -- MyArr3(2).DynamicArray(3) = 199
MyArr3(2)  .DynamicArray(3)   = 199
' ORIGINAL -- MyArr3(0).pontine = 7
MyArr3(0)  .pontine = 7
    DIM elt2_countx AS LOCAL INTEGER
DIM elt2_indexx AS LOCAL INTEGER
elt2_countx = UBOUND(MyArrOfDouble)
FOR elt2_indexx = 0 TO elt2_countx
elt2 = MyArrOfDouble(elt2_indexx)


   ' ORIGINAL -- MsgBox elt2
MSGBOX elt2
' ORIGINAL -- Next
NEXT
    DIM elt_countx AS LOCAL INTEGER
DIM elt_indexx AS LOCAL INTEGER
elt_countx = UBOUND(MyArrOfInt)
FOR elt_indexx = 0 TO elt_countx
elt = MyArrOfInt(elt_indexx)


   ' ORIGINAL -- j = j + elt
j = j + elt
' ORIGINAL -- Next
NEXT
    DIM elt3_countx AS LOCAL INTEGER
DIM elt3_indexx AS LOCAL INTEGER
elt3_countx = UBOUND(MyArrOfDouble)
FOR elt3_indexx = 0 TO elt3_countx
elt3 = MyArrOfDouble(elt3_indexx)


   ' ORIGINAL -- MsgBox elt3 & " so now 3 for eaches"
MSGBOX elt3 & " so now 3 for eaches"
' ORIGINAL -- Next
NEXT
' ORIGINAL -- Myfunc = True ' return comment
METHOD = True  ' return comment

' ORIGINAL -- End Function ' end function comment
END METHOD  ' end function comment

' ORIGINAL -- Sub UseLocalClass()
METHOD UseLocalClass()
DIM ShouldBeVariant AS LOCAL VARIANT
DIM mylocalclass AS LOCAL i_ClassCallThis
DIM mylocalclassWithNew AS LOCAL i_ClassCallThis
LET mylocalclassWithNew = CLASS ClassCallThis
mylocalclass = CLASS ClassCallThis
' ORIGINAL -- mylocalclass.TryToUnderstand
mylocalclass.TryToUnderstand
' ORIGINAL -- End Sub
END METHOD
' ORIGINAL -- Sub ThatUsesADO()
METHOD ThatUsesADO()
' THIS HAS TO BE DONE BUT FOR NOW COMMENT OUT
'Dim ado1 As adodb.Command
'Dim ado2newone As New adodb.Command
'Dim adoCollection As New adodb.Recordset
'Dim fld As adodb.Field
'  Dim mycat As ADOX.Catalog
'  Set mycat = New ADOX.Catalog
'For Each fld In adoCollection.Fields
'   MsgBox (fld.Name)
'Next
'   Set ado1 = New adodb.Command

' ORIGINAL -- End Sub
END METHOD
' ORIGINAL -- Private Sub MYPRIVATESUB()

' ORIGINAL -- Public Sub MYPUBLICSUB()
METHOD MYPUBLICSUB()

' ORIGINAL -- End Sub
END METHOD
' ORIGINAL -- Friend Sub myfriendsub()
METHOD myfriendsub()

' ORIGINAL -- End Sub
END METHOD
   END INTERFACE
END CLASS
==========================MY NEXT FILE:  ClassCallThis.bas
' produced by Vb6ToPowerBasicTranslate on 1/20/2011 9:37:38 AM do not export the class



' ***********STRUCTURES AND CLASSES**********


CLASS ClassCallThis



  INTERFACE i_ClassCallThis
  INHERIT IUNKNOWN


' ORIGINAL -- Friend Sub TryToUnderstand()
METHOD TryToUnderstand() 
     ' ORIGINAL -- MsgBox "local class"
MsgBox "local class"
' ORIGINAL -- End Sub
End METHOD
   END INTERFACE
END CLASS


José Roca

Quote
LET mystruct = CLASS myStructTypeWithString       ' STRING CONSTANT EXPECTED  -- ERROR*************************

As the error message says, it must be a string constant. Use:


mystruct = CLASS "myStructTypeWithString"


Theo Gottwald

And think about marking your "Code" as Code, using the appropriate tags.
This will help people to read it.

See here:

' using CODE Tags

 WHILE Alive()
   PRINT IIF$(t1.Alive(), "[T1 is alive]", "[T1 is no more]")+ " "
   PRINT IIF$(t2.Alive(), "[T2 is alive]", "[T2 is no more]")+ " "
   SLEEP 500
 WEND
           


' No Code Tags!

 WHILE IsAlive()
   PRINT IIF$(t1.Alive(), "[T1 is alive]", "[T1 is no more]")+ " "
   PRINT IIF$(t2.live(), "[T2 is alive]", "[T2 is no more]")+ " "
   SLEEP 500
 WEND
           

Frederick J. Harris

I hope you aren't working on translating VB Types with variable length strings in them to PowerBASIC anymore Murray!  Just thinking about that makes my head hurt!

A bunch of us tried some here about two years back to come up with a translator for converting VB to PowerBASIC.  That was before PB 9.  We gave it up.  I had a prototype working though that would convert a simple VB form with a couple simple controls on it to PowerBASIC that would actually run.  Its quite a job.


Murray Ruggiero

Actual I am.  I am also going to put my code for this translator written in VB.NET up here for people to share and help us get as close as possible. See my problem is I have 250,000-400,000 lines of code to translate from VB 6.0.   I have ported some of my VB 6.0 code to C++ COM before and 5000 lines takes about 250 hrs to do. I am hoping that I can translate 200,000 lines of this code to Power basic and only take 30-50 hrs per 5000 lines to get the code running correctly.  I have two part time  programmers working on this job. They currently do other projects for me.

  If we all work together we can make this dream come true.

;D

Bob Zale

Quote from: Frederick J. Harris on January 21, 2011, 03:16:46 AM
I had a prototype working though that would convert a simple VB form with a couple simple controls on it to PowerBASIC that would actually run.  Its quite a job.

To convert VB forms to PowerBASIC, you might take a look at PowerBASIC Forms, our visual designer.  It will convert most VB forms in seconds.  It isn't 100.0% perfect in every case, but it does quite a good job overall.  This feature has been available for several years.

Regards,

Bob Zale
PowerBASIC Inc.

Frederick J. Harris

#8
Quote
This feature has been available for several years.

Didn't know that Mr. Zale.  

I had been interested in converting the vb code to sdk style, but it was only something of a 'lark' for me.  I didn't really have any vb code I wanted to convert as Murray does.  I guess I was interested in it because I spent so much time in the 90s with Visual Basic, that is, before I discovered PowerBASIC.