Question C# to VB.Net

ElmoRocks

New member
Joined
Sep 22, 2008
Messages
2
Programming Experience
Beginner
Hi Guys

Im new to the forum, and VB.Net programming in general

can you please help me to convert the foreach loop highlighted in bold below to VB.Net (its currently C#)

Thanks ever so much :)

VB.NET:
private int file_count = 0;
///
/// Get the file count of a given directory recursively.
///
public void GetDirectoryFileCount(string dir)
{
dir = dir + @”\”;
//get all the directories and files inside a directory
String[] all_files=Directory.GetFileSystemEntries(dir);
//loop through all items
[B]foreach(string file in all_files)[/B]
{
//check to see if the file is a directory if not increment the count
if(Directory.Exists(file))
{
//recursive call
GetDirectoryFileCount(file);
}
else
{
//increment file count
file_count++;
}
}
}
 
Try a conversion site like:

ConvertCSharp2VB

VB.NET:
Private file_count As Integer =  0 
'/
'/ Get the file count of a given directory recursively.
'/
Public  Sub GetDirectoryFileCount(ByVal dir As String)
dir = dir + @”\”
'get all the directories and files inside a directory
Dim all_files() As String = Directory.GetFileSystemEntries(dir) 
'loop through all items
Dim file As String
For Each file In all_files
'check to see if the file is a directory if not increment the count
If Directory.Exists(file) Then
'recursive call
GetDirectoryFileCount(file)
 
Why would you need to convert that simple code? Just write it in vb.net from scratch, should be able to do it faster than using a conversion site
 
Why would you need to convert that simple code? Just write it in vb.net from scratch, should be able to do it faster than using a conversion site

I wrote it in C# !!

New to the VB.NET language .... it slipped my mind how to declare the For loop ... I almost had it in VB minus that one line !!
 

Latest posts

Back
Top