PDA

Click to See Complete Forum and Search --> : Translation VB->C++


Vlatko
Dec 24th, 2000, 02:25 PM
Can someone translate this code i got from Jop to C++. I am having most trouble with the dinamyc arrays.

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

PsyVision
Dec 24th, 2000, 03:13 PM
http://www.softseek.com

parksie
Dec 24th, 2000, 03:55 PM
Use a vector.

Dec 24th, 2000, 04:12 PM
this is a good a time as any to ask........... how do you use a vector?

parksie
Dec 25th, 2000, 12:04 PM
vector is a template class, so you can make a vector of anything:

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;

Dec 25th, 2000, 12:11 PM
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) ??

parksie
Dec 25th, 2000, 01:32 PM
push_back appends an item to the vector.

Vlatko
Dec 25th, 2000, 04:06 PM
Thanks parksie. I finally translated that VB code. This vector stuff really helped a lot. Thanks again.

Dec 25th, 2000, 04:15 PM
:doh!:

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

well, thanks parksie :D