Jump to content

Help translating VB to AU3


devilyn
 Share

Recommended Posts

Hello all,

Thank you for reading my question.

i have the following VB code that i'm trying to translate to au3 but i'm unable to make it work.

VB Code:

VERSION 5.00
Object = "*\AvbalColumnTreeViewLib6.vbp"
Begin VB.Form frmMultiColumn 
   Caption         =   "vbAccelerator Multi-Column TreeView"
   ClientHeight    =   5340
   ClientLeft      =   3300
   ClientTop       =   3165
   ClientWidth     =   6120
   BeginProperty Font 
      Name            =   "Tahoma"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   Icon            =   "frmMultiColumn.frx":0000
   LinkTopic       =   "Form1"
   ScaleHeight     =   5340
   ScaleWidth      =   6120
   Begin vbalCTreeViewLib6.vbalColumnTreeView tvwColumns 
      Height          =   4215
      Left            =   180
      TabIndex        =   1
      Top             =   420
      Width           =   5715
      _ExtentX        =   10081
      _ExtentY        =   7435
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
   End
   Begin VB.CheckBox chkGridLines 
      Caption         =   "&Grid Lines"
      Height          =   195
      Left            =   180
      TabIndex        =   0
      Top             =   120
      Value           =   1  'Checked
      Width           =   3735
   End
End
Attribute VB_Name = "frmMultiColumn"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private m_cIml As cVBALSysImageList

Private Enum EItemIconTypes
   eItemIconArtist = 247
   eItemIconAlbum = 41
   eItemIconTrack = 260
End Enum

Private Sub setUpColumns()
Dim cCol As cCTreeViewColumn
   With tvwColumns
      With .Columns
         .Item(1).Width = 128
         Set cCol = .Add("TRACK", "Track")
         Set cCol = .Add("LENGTH", "Length")
         Set cCol = .Add("SIZE", "Size")
      End With
   End With
End Sub

Private Function iconIndex(ByVal eType As EItemIconTypes)
Dim sFile As String
   sFile = App.Path
   If (Right(sFile, 1) <> "\") Then sFile = sFile & "\"
   sFile = sFile & eType & ".ico"
   iconIndex = m_cIml.ItemIndex(sFile)
End Function

Private Function addArtist(ByVal sArtist As String) As cCTreeViewNode
   Set addArtist = tvwColumns.Nodes.Add(, , sArtist, sArtist, iconIndex(eItemIconArtist), iconIndex(eItemIconArtist))
End Function
Private Function addAlbum(cArtistNode As cCTreeViewNode, ByVal sAlbum As String) As cCTreeViewNode
   Set addAlbum = cArtistNode.AddChildNode(sAlbum, sAlbum, iconIndex(eItemIconAlbum), iconIndex(eItemIconAlbum))
End Function
Private Function addTracks(cAlbumNode As cCTreeViewNode, ParamArray vTracks() As Variant)
Dim nod As cCTreeViewNode
Dim i As Long
Dim min As Long
Dim sec As Long
Dim size As Long

   For i = LBound(vTracks) To UBound(vTracks)
      Set nod = cAlbumNode.AddChildNode(vTracks(i), vTracks(i), iconIndex(eItemIconTrack), iconIndex(eItemIconTrack))
      nod.SubItem(1).Text = i + 1
      min = Rnd * 5 + 1
      sec = Rnd * 60
      nod.SubItem(2).Text = Format(TimeSerial(0, min, sec), "nn:ss")
      size = 1024 * 1.4 * (min + sec / 60#)
      nod.SubItem(3).Text = Format(size, "#,##0 KB")
   Next i
   
End Function

Private Sub setUpData()
Dim nodArtist As cCTreeViewNode
Dim nodAlbum As cCTreeViewNode
   
   Set nodArtist = addArtist("Autechre")
   
   Set nodAlbum = addAlbum(nodArtist, "AE5")
   addTracks nodAlbum, _
      "acroyear2", "777", "rae", "maleve", "in", _
      "wrap5", "Under BOAC", "corc", "caliper remote", _
      "arch carrier", "drane2"
   nodAlbum.Expanded = True
   
   Set nodAlbum = addAlbum(nodArtist, "Amber")
   addTracks nodAlbum, _
      "Foil", "Montreal", "Silverside", "Slip", "Glitch", _
      "Piezo", "Nine", "Further", "Yulquen", "Nil", "TearTear"
   nodAlbum.Expanded = True
      
   Set nodAlbum = addAlbum(nodArtist, "Chiassic Slide")
   addTracks nodAlbum, _
      "cipater", "rettic ac", "trewe", "chicli", _
      "hub", "calsruc", "recury", "pule", "muane"
   nodAlbum.Expanded = True
      
   Set nodAlbum = addAlbum(nodArtist, "Confield")
   addTracks nodAlbum, _
      "VI scose pose", "cfern", "per expers", "sim gishel", _
      "parhelic triangle", "bine", "eidetic casein", "uviol", _
      "lentic catachresis"
   nodAlbum.Expanded = True
      
   Set nodAlbum = addAlbum(nodArtist, "Draft 7.30")
   addTracks nodAlbum, _
      "Xylin Room", "IV VV IV VV VII", "6ie.cr", "Tapr", _
      "Surripere", "Theme Of Sudden Roundabouts", _
      "VL AI 5", "P.-NTIL", "V-Proc", "Reniform Puls"
   nodAlbum.Expanded = True

   Set nodAlbum = addAlbum(nodArtist, "tri repetae")
   addTracks nodAlbum, _
      "dael", "clipper", "leterel", "rotar", "stud", _
      "eutow", "c-pach", "gnit", "overand", "rsdio"
   nodAlbum.Expanded = True
   
   nodArtist.Expanded = True
   
   Set nodArtist = addArtist("Plaid")
   Set nodAlbum = addAlbum(nodArtist, "Double Figure")
   addTracks nodAlbum, _
      "Eyen", "Squance", "Assault on Precinct Zero", _
      "Zamami", "Silversum", "Ooh Be Do", _
      "Light Rain", "Tak 1", "New Family", "Zala", _
      "Twin Home", "Tak 2", "Sincetta", "Tak 3", _
      "Porn Coconut Co", "Tak 4", "Ti Bom", "Tak 5", "ManyMe"
   nodAlbum.Expanded = True
   
   Set nodAlbum = addAlbum(nodArtist, "Spokes")
   addTracks nodAlbum, _
      "Even Spring", "Crumax Rias", "Upona", "Zeal", _
      "Cedar City", "B Bora Droid", "Marry", "Get What You Gave", _
      "Bunz", "Quick Emix"
   nodAlbum.Expanded = True
   
   Set nodAlbum = addAlbum(nodArtist, "Rest Proof Clockwork")
   addTracks nodAlbum, _
      "Shackblu", "Ralome", "Little People", "3 Recurring", _
      "Buddy", "Dead Sea", "Gel Lab", "Tearisci", "Dang Spots", _
      "Pino Pomo", "Last Remembered Thing", "Lambs Eye", _
      "New Bass Hippo", "Churn Maiden", "Air Locked"
   nodAlbum.Expanded = True
   
   nodArtist.Expanded = True
      
End Sub

Private Sub setUpImageList()
   Set m_cIml = New cVBALSysImageList
   m_cIml.IconSizeX = 16
   m_cIml.IconSizeY = 16
   m_cIml.Create
   tvwColumns.ImageList = m_cIml.hIml
End Sub

Private Sub chkGridLines_Click()
   tvwColumns.GridLines = (chkGridLines.Value = vbChecked)
End Sub

Private Sub Form_Load()
   setUpImageList
   setUpColumns
   setUpData
End Sub

Private Sub Form_Resize()
   tvwColumns.Move tvwColumns.left, tvwColumns.tOp, _
      Me.ScaleWidth - tvwColumns.left * 2, _
      Me.ScaleHeight - tvwColumns.tOp - tvwColumns.left
End Sub

AU3 Code (What i got until now):

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>


Create()

Func Create()
    Local $obj, $GUIActiveX, $GUI_Button_Back, $GUI_Button_Forward
    Local $GUI_Button_Home, $GUI_Button_Stop, $msg

    ;$obj = ObjCreate("TList.TList.8")
    ;$obj = ObjCreate("TListTreeView.TListTreeView.3")
    ;$obj = ObjCreate("BROWSERAPP.BrowserAppCtrl.1")
    $obj = ObjCreate("vbalCTreeViewLib6.vbalColumnTreeView")
    ;$obj2 = ObjCreate("vbalCTreeViewLib6.cCTreeViewColumns")



    ; Create a simple GUI for our output
    GUICreate("Embedded Web control Test", 640, 580, (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS, $WS_CLIPCHILDREN))
    $GUIActiveX = GUICtrlCreateObj($obj, 10, 40, 600, 360)
    ConsoleWrite(">Debug>:"&$GUIActiveX & @CRLF)
    $GUI_Button_Test1 = GUICtrlCreateButton("Test1", 10, 420, 100, 30)
    $GUI_Button_Test2 = GUICtrlCreateButton("Test2", 120, 420, 100, 30)
    $GUI_Button_Test3 = GUICtrlCreateButton("Test3", 230, 420, 100, 30)
    $GUI_Button_Test4 = GUICtrlCreateButton("Test4", 330, 420, 100, 30)

    GUISetState() ;Show GUI



    ; Waiting for user to close the window
    While 1
        $msg = GUIGetMsg()

        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $GUI_Button_Test1
                $obj.Columns()
            Case $msg = $GUI_Button_Test2

            Case $msg = $GUI_Button_Test3

            Case $msg = $GUI_Button_Test4

        EndSelect

    WEnd

    GUIDelete()
EndFunc   ;==>Create

I cant figure out how to create columns and items.

Please help.

Thanks in advance

Lior.

Link to comment
Share on other sites

I looked at the like the first line of each...

WHAT HAPPENED TO USING GUI CONTROLS NATIVE TO AUTOIT? GUICTRLCREATELISTVIEW?

Look in the helpfile for ever GUI control. They start with GUICTRLCREATE.... Don't bother creating objects and all that crap, you are making it harder than it really is.

EDIT:

Actually now I read it again. Take a look at the UDFs.

Edited by BrettF
Link to comment
Share on other sites

You can almost directly translate a VBScript to AutoIt. The same is NOT true for VB (Visual Basic, distinct from VBScript). VB uses manages libraries that are not available to AutoIt. That doesn't mean you can't achieve the same functionality, but it is not just a matter of translation.

As BrettF pointed out: Learn to use the native and UDF functions that are available in AutoIt to achieve the same end, like the native GuiCtrlCreateTreeView() and the UDF _GuiCtrlTreeView_Create().

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I don't even know what that would look like. Sounds like a SysListView instead.

When you try ObjCreate("vbalCTreeViewLib6.vbalColumnTreeView"), does it even return an object? That seems to be very specific to some VB library that AutoIt wouldn't use.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

it's seems that it does return an object. i base my assumption on the objectID that i getting from GUICtrlCreateObj and the fact that "$obj.Columns()" is not failing also indicate that the object is receiving the call.

also i have added this piece of code:

if IsObj($obj) Then
    ConsoleWrite(">Debug>:OBJ_Created"&@CRLF)
Else
    ConsoleWrite(">Debug>:Cannot_Create_OBJ"&@CRLF)
EndIf

and it returns 1.

Thanks for all your help.

Lior.

Link to comment
Share on other sites

I guess you have to install their VBAccelerator library. I don't get an object back running this:

$obj = ObjCreate("vbalCTreeViewLib6.vbalColumnTreeView")
    If IsObj($obj) Then
        ConsoleWrite("Debug:  $obj is Object, Name = " & ObjName($obj) & @LF)
    Else
        ConsoleWrite("Debug:  $obj is not an Object" & @LF)
    EndIf

A quick search of the forum turns up a few references to VBAccelerator, but no working code with it.

'Fraid I'm not much help.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...