Results 1 to 9 of 9

Thread: Translation VB->C++

  1. #1

    Thread Starter
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Can someone translate this code i got from Jop to C++. I am having most trouble with the dinamyc arrays.
    Code:
    Public Sub GetAllFilesAPI(StartDir As String)
    Dim d$, dr As Boolean, dts As Boolean, dirs() As String
    Dim FindData As WIN32_FIND_DATA, c%, file&
    If Right(StartDir, 1) <> "\" Then StartDir = StartDir & "\"
        
    ReDim dirs(0)
    file = FindFirstFile(StartDir & "*", FindData)
    c = 1
    
    Do While c <> 0
    
       c = FindNextFile(file, FindData)
       d = StripNulls(FindData.cFileName)
    dts = d <> "." And d <> ".." And Len(d) > 0
        If dts Then dr = (GetFileAttributes(StartDir & d) And FILE_ATTRIBUTE_DIRECTORY)
            
            If dr = False And dts Then Form1.List1.AddItem StartDir & d 'add to list
                
                If dr And dts Then 'dir found
                    ReDim Preserve dirs(UBound(dirs) + 1)
                    dirs(UBound(dirs)) = d
                End If
                
    Loop
    
    Dim x&
    FindClose file
    For x = 1 To UBound(dirs)
        GetAllFilesAPI StartDir & dirs(x)
    Next x
    End Sub
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  2. #2
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341

  3. #3
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Use a vector.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  4. #4
    Guest
    this is a good a time as any to ask........... how do you use a vector?

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    vector is a template class, so you can make a vector of anything:
    Code:
    vector<int> viArray;
    
    for(int j = 0; j < 10; j++) {
        viArray.push_back(j);
    }
    
    for(j = 0; i < viArray.size(); j++) {
        cout << " " << viArray[j];
    }
    
    cout << endl;
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  6. #6
    Guest
    I pretty much tought my self how to use vectors in the past.. day... but what is push_back and push_forward(or whatever it's called) ??

  7. #7
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    push_back appends an item to the vector.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  8. #8

    Thread Starter
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Thanks parksie. I finally translated that VB code. This vector stuff really helped a lot. Thanks again.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  9. #9
    Guest
    :doh!:

    so I've been resizing and adding to my vectors for no reason?

    well, thanks parksie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width