Announcement

Collapse
No announcement yet.

VB6 to PB

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • VB6 to PB

    studying PB, porting the program from VB6 to PB, I ran into the problem that Object(ListBox, TextBox, Label...) and Boolean(True/False) data types are missing in PB,

    And what should I replace them now, well, Boolean, I will replace "Long", but - "object", how can I refer to the ListBox Object on the form, from inside Functions?
    Please tell me, but better, if possible, provide a piece of code with syntax, please.

    For Sample, how to convert such a strings?

    Code:
    Function ReadList (ByRef objList As Object)
    ...
    End Function

  • #2
    Nickon,
    Boolean would be:
    Code:
    %TRUE  = 1
    %FALSE = 0
    %NULL  = 0
    To answer your other pressing issue...you will need to ask yourself "How am I creating the Listbox object?" Is it something like oListBox or pListbox or cListbox? Just throwing spit here and guessing it is a COM object.

    Comment


    • #3
      "How am I creating the Listbox object?" Is it something like oListBox or pListbox or cListbox?
      What is the name of such an variant to create ListBox?

      Code:
      FUNCTION ShowfrmDataInspector(BYVAL hParent AS DWORD) AS LONG
          LOCAL lRslt AS LONG
      
      #PBFORMS BEGIN DIALOG %frmDataInspector->->
          LOCAL hDlg  AS DWORD
      
          DIALOG NEW hParent, "Inspector", 269, 222, 385, 278, %WS_POPUP OR _
              %WS_BORDER OR %WS_DLGFRAME OR %WS_CAPTION OR %WS_SYSMENU OR _
              %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR _
              %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT _
              OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
          CONTROL ADD LABEL,    hDlg, %lblPath, "Path:", 5, 4, 20, 15
          CONTROL ADD TEXTBOX,  hDlg, %txtPath, "", 26, 2, 100, 13
          CONTROL ADD LABEL,    hDlg, %lblMask, "Mask:", 135, 4, 25, 10
          CONTROL ADD TEXTBOX,  hDlg, %txtPattern, "", 161, 2, 35, 13
          CONTROL ADD CHECKBOX, hDlg, %chkIncSubFolders, "SubFolders", 26, _
              16, 100, 10
          CONTROL ADD BUTTON,   hDlg, %cmdAudition, "Audit", 199, 2, 49, 13
          CONTROL ADD LISTBOX,  hDlg, %lstFiles, , 1, 27, 166, 246
      #PBFORMS END DIALOG
      
          DIALOG SHOW MODAL hDlg, CALL ShowfrmDataInspectorProc TO lRslt
      
      #PBFORMS BEGIN CLEANUP %frmDataInspector
      #PBFORMS END CLEANUP
      
          FUNCTION = lRslt
      END FUNCTION

      Comment


      • #4
        SDK instead of DDT?
        https://forum.powerbasic.com/forum/u...e-in-a-listbox

        If you want to use classes then Jose Roca Forums https://forum.powerbasic.com/forum/jose-s-corner


        If you have trouble finding things on this BBS, you can google like this:
        Code:
        site:powerbasic.com  jose roca listbox
        site:powerbasic.com  VB6
        https://duckduckgo.com instead of google

        Comment


        • #5
          Check the example in the PBWin10\Samples\DDT\Listbox\Synclist.bas
          Rod
          "To every unsung hero in the universe
          To those who roam the skies and those who roam the earth
          To all good men of reason may they never thirst " - from "Heaven Help the Devil" by G. Lightfoot

          Comment


          • #6
            Originally posted by Jim Fritts View Post
            Nickon,
            Boolean would be:
            Code:
            %TRUE = 1
            %FALSE = 0
            %NULL = 0
            Technically, that's not correct.

            There's basically just one "hardcoded" definition involded, that's %False = 0. Anything <> %False is considered to be True. May that be 1, -1 or 5. See below:

            Code:
            %False = 0
            %True = Not %False
            
            Function PBMain () As Long
            
               Con.StdOut "** %False = 0 - %True = Not %False **"
               Con.StdOut
            
               Con.StdOut "%False: " & Format$(%False)
               Con.StdOut "%True : " & Format$(%True)
            
               Con.StdOut "IsTrue(%False): " & Format$(IsTrue(%False))
               Con.StdOut "IsTrue(%True) : " & Format$(IsTrue(%True))
            
               Con.StdOut "IsFalse(%False): " & Format$(IsFalse(%False))
               Con.StdOut "IsFalse(%True) : " & Format$(IsFalse(%True))
            
            
               Local lTrue As Long
               lTrue = 5   ' Anything but %False
            
               Con.StdOut "** %False = 0 - lTrue = 5 **"
               Con.StdOut
            
               Con.StdOut "%False: " & Format$(%False)
               Con.StdOut "lTrue : " & Format$(lTrue)
            
               Con.StdOut "IsTrue(%False): " & Format$(IsTrue(%False))
               Con.StdOut "IsTrue(lTrue) : " & Format$(IsTrue(lTrue))
            
               Con.StdOut "IsFalse(%False): " & Format$(IsFalse(%False))
               Con.StdOut "IsFalse(lTrue) : " & Format$(IsFalse(lTrue))
            
               WaitKey$
            
            
            End Function
            Output:
            Code:
            ** %False = 0 - %True = Not %False **
            
            %False: 0
            %True : -1
            IsTrue(%False): 0
            IsTrue(%True) : -1
            IsFalse(%False): -1
            IsFalse(%True) : 0
            ** %False = 0 - lTrue = 5 **
            
            %False: 0
            lTrue : 5
            IsTrue(%False): 0
            IsTrue(lTrue) : -1
            IsFalse(%False): -1
            IsFalse(lTrue) : 0

            Comment


            • #7
              Knuth,
              Correct. I was only using what I posted as examples of Booleans. He didn't seem confused about that. It was just there to reinforce his understanding. The real problem he was having was the LISTBOX part. It looks like Mike and Rodney helped him out with a solution for that.

              Comment


              • #8
                Yes, thank you so much for all the help and links. I try to figure it out. Complicated. I have to adapt to think differently than I used to, but I try to understand the essence. Thanks again!

                Comment


                • #9
                  VB6 and PowerBASIC can be used at the same time.
                  New code in PowerBASIC can be compiled into a DLL(s) and called from VB6 or compiled to executables and shelled to.
                  This gives you the best of both worlds.

                  The secret is to prevent VB6 programs from ending until PowerBASIC DLL is finished with a check in Form_QueryUnload of VB6.
                  Explained here: https://forum.powerbasic.com/forum/u...ic-dll?t=41675




                  %TRUE and %FALSE is optional. In help see: ISFALSE and ISTRUE operators where it is explained in detail.

                  This works in many situations:
                  IF X THEN MSGBOX "Not Zero" ELSE MSGBOX "Zero"

                  IF MyFunction THEN ' only if you know what returning 0 represents in the function. Success could be 0 in some functions and failure in others.

                  Look at the CHOOSE function in help and See Also at the bottom for other related functions.





                  Press F1 in the PB editor at any time for help. If over a keyword when pressing F1, it goes to help on that keyword.

                  It has been said many times to write a SDK program at least once to see what is going on.
                  If sticking to DDT be sure to check out PowerForms or other coding environments like Phoenix and Firefly for VB6-like environments.




                  Like short and easy examples?
                  Gary Beene:
                  http://www.garybeene.com/power/code/

                  Jose Roca:
                  http://www.jose.it-berater.org/smfforum/index.php


                  There are more sites ...
                  https://duckduckgo.com instead of google

                  Comment


                  • #10
                    Hi Nickon,

                    I don't know VB but in PB the ListBox and other controls are manipulated by their parent Handle and the control ID.

                    eg.
                    Code:
                    ' ReadList(Cb.Hndl, %lstFiles) To sList     ' Cb.Hndl = parent handle in callback
                    
                    Function ReadList (hDlg As Dword, Id As Long) As String
                     Local count, i As Long
                     Local sTemp, sList As String
                    
                      ListBox Get Count hDlg, Id To Count       ' ** see help for ListBox statement
                    
                      For i = 1 To Count
                        ListBox Get Text hDlg, Id, i To sTemp   ' **
                        sList += sTemp + $CR
                      Next
                      Function = sList                          ' return ListBox values
                    End Function
                    '------------------/ReadList
                    Rgds, Dave

                    Comment


                    • #11
                      Nickon,
                      I didn't notice any reference to this
                      Code:
                       
                      Function ReadList (ByRef objList As Object) ... End Function
                      in your example code. Or provide more info on what you were trying to achieve other than a translation.

                      Comment


                      • #12
                        Reading (a lot!) between the lines I reckon Nickon is trying to do something like this..
                        Code:
                        #PBForms Created V2.01
                        #Compile Exe
                        #Dim All
                        
                        #PBForms Begin Includes
                        #Resource "FormTest1.pbr"
                        #Include Once "WIN32API.INC"
                        #Include Once "COMMCTRL.INC"
                        #Include Once "PBForms.INC"
                        #PBForms End Includes
                        
                        #PBForms Begin Constants
                        %IDD_DIALOG1      =  101
                        %lblPath          = 1001
                        %txtPath          = 1002
                        %lblMask          = 1003
                        %txtPattern       = 1004
                        %chkIncSubFolders = 1005
                        %cmdAudition      = 1006
                        %lstFiles         = 1007
                        #PBForms End Constants
                        
                        Declare CallBack Function ShowfrmDataInspectorProc()
                        Declare Function ShowfrmDataInspector(ByVal hParent As Dword) As Long
                        #PBForms Declarations
                        '------------------/
                        
                        Function PBMain()
                          PBFormsInitComCtls (%ICC_WIN95_CLASSES Or %ICC_DATE_CLASSES Or %ICC_INTERNET_CLASSES)
                        
                          ShowfrmDataInspector %HWND_Desktop
                        End Function
                        '------------------/PBMain
                        
                        CallBack Function ShowfrmDataInspectorProc()
                          Select Case As Long Cb.Msg
                            Case %WM_InitDialog
                             Static IncSubFldrs, DDL As Long
                             Static sPath, sMask As String
                              sPath = Exe.Path$                               ' initially set path to app folder
                              Control Set Text Cb.Hndl, %txtPath, sPath
                              sMask = "*.*"                                   ' mask initially *.*
                              Control Set Text Cb.Hndl, %txtPattern, sMask
                              DDL = %DDL_READWRITE                            ' Initial list w'out sub folders
                            Case %WM_Command
                              Select Case As Long Cb.Ctl
                        
                                Case %txtPath
                                  Control Get Text Cb.Hndl, %txtPath To sPath
                                  Dialog Set Text Cb.Hndl, sPath
                        
                                Case %txtPattern
                                  Control Get Text Cb.Hndl, %txtPattern To sMask
                                  Dialog Set Text Cb.Hndl, sMask
                        
                                Case %chkIncSubFolders
                                  Control Get Check Cb.Hndl, %chkIncSubFolders To IncSubFldrs     ' state of checkbox
                                  DDL = IIf(IncSubFldrs, DDL Or %DDL_DIRECTORY, %DDL_READWRITE)   ' add sub folders?
                        
                                Case %cmdAudition, %IDOK
                                  If Cb.CtlMsg = %BN_Clicked Or Cb.CtlMsg = 1 Then
                                   Local szDir As AsciiZ * %Max_Path
                                    If InStr(sMask, "*") = 0 Then  sMask = "*.*"
                                    sPath = PathName$(Path, sPath)
                                    If IsFolder(sPath) Then
                                      szDir = sPath + sMask
                                    Else
                                      szDir = Exe.Path$ + sMask
                                    End If
                                    ListBox Reset Cb.Hndl, %lstFiles
                                    ' Populate ListBox
                                    Control Send Cb.Hndl, %lstFiles, %LB_DIR, DDL, VarPtr(szDir)  ' Use API LB_DIR message
                                     ' Get listbox items
                                     Local sList As String
                                      ReadList(Cb.Hndl, %lstFiles) To sList
                                      MsgBox sList, %MB_IconMask Or %MB_Topmost, "ListBox entries"
                                    End If
                        
                                Case %lstFiles
                                  If Cb.CtlMsg = %BN_Clicked Or Cb.CtlMsg = 1 Then
                                   Local sTemp As String
                                    Listbox Get Text Cb.Hndl, %lstFiles To sTemp
                                    If Instr(sTemp, "[") > 0 Then                   ' folder selected
                                      Replace "[" With ""In sTemp
                                      Replace "]" With "\"In sTemp
                                      sTemp = sPath + sTemp
                                      Control Set Text Cb.Hndl, %txtPath, sTemp
                                    Else
                                      Dialog Set Text Cb.Hndl, sTemp                ' file selected
                                    End If
                                  End If
                        
                              End Select
                          End Select
                        End Function
                        '------------------/Callback Function
                        
                        Function ReadList (hDlg As Dword, Id As Long) As String
                         Local Count, i As Long
                         Local sTemp, sList As String
                        
                          ListBox Get Count hDlg, Id To Count       ' ** see help for ListBox statement
                        
                          For i = 1 To Count
                            ListBox Get Text hDlg, Id, i To sTemp   ' **
                            sList += sTemp + $Cr
                          Next
                          Function = sList                          ' return ListBox values
                        End Function
                        '------------------/ReadList
                        
                        FUNCTION ShowfrmDataInspector(BYVAL hParent AS DWORD) AS LONG
                            LOCAL lRslt AS LONG
                        
                        #PBFORMS BEGIN DIALOG %frmDataInspector->->
                            LOCAL hDlg  AS DWORD
                        
                            DIALOG NEW hParent, "Inspector", 269, 222, 385, 278, %WS_POPUP OR _
                                %WS_BORDER OR %WS_DLGFRAME OR %WS_CAPTION OR %WS_SYSMENU OR _
                                %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR _
                                %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT _
                                OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
                            CONTROL ADD LABEL,    hDlg, %lblPath, "Path:", 5, 4, 20, 15
                            CONTROL ADD TEXTBOX,  hDlg, %txtPath, "", 26, 2, 100, 13
                            CONTROL ADD LABEL,    hDlg, %lblMask, "Mask:", 135, 4, 25, 10
                            CONTROL ADD TEXTBOX,  hDlg, %txtPattern, "", 161, 2, 35, 13
                            CONTROL ADD CHECKBOX, hDlg, %chkIncSubFolders, "SubFolders", 26, _
                                16, 100, 10
                            CONTROL ADD BUTTON,   hDlg, %cmdAudition, "Audit", 199, 2, 49, 13
                            CONTROL ADD LISTBOX,  hDlg, %lstFiles, , 1, 27, 166, 246
                        #PBFORMS END DIALOG
                        
                            DIALOG SHOW MODAL hDlg, CALL ShowfrmDataInspectorProc TO lRslt
                        
                        #PBFORMS BEGIN CLEANUP %frmDataInspector
                        #PBFORMS END CLEANUP
                        
                            FUNCTION = lRslt
                        END FUNCTION
                        '------------------/Show Form
                        Rgds, Dave

                        Comment


                        • #13
                          A recommondation from a longtime (and still) VB6 and PB/Win user: do the UI stuff in VB, do the actual "work" in PB (DLLs).

                          I've forgot about your "object" question: In PB, you could use a VARIANT to receive an object from VB. This ofc, depends on what type of objects you're passing around and what you want to do with them.

                          If everything else fails, create the object in PB as a COM object and pass that to VB instead of vice versa.

                          Code:
                          ' ** PB **
                          
                          #Compile Dll "ObjFromVB.dll"
                          
                          Function ObjFromVB Alias "ObjFromVB" (ByVal vnt As Variant) Export As Long
                          
                             Function = VariantVT(vnt)
                             '  From the help for VariantVT: 9 = %VT_DISPATCH, IDispatch
                          
                          End Function
                          Code:
                          ' ** VB6 **
                          Option Explicit
                          DefLng A-Z
                          
                          Public Declare Function ObjFromVB Lib "ObjFromVB.dll" (ByVal vnt As Variant) As Long
                          
                          Sub Main()
                          
                          
                          Dim o As Object, v As Variant
                          
                          Debug.Print "VB VarType: ", VarType(o)
                          Debug.Print "VB VarType: ", VarType(v)
                          
                          Set v = o
                          Debug.Print "VB VarType: ", VarType(v)
                          
                          Debug.Print "PB VarType: ", ObjFromVB(o)
                          Debug.Print "PB VarType: ", ObjFromVB(v)
                          
                          End Sub
                          
                          ' Result:
                          
                          ' VB VarType:    9
                          ' VB VarType:    0
                          ' VB VarType:    9
                          ' PB VarType:    9
                          ' PB VarType:    9

                          Comment

                          Working...
                          X