String

Salat

Regular
Joined
Mar 5, 2002
Messages
81
Location
Poland, Silesia
In VB6 there is a function String which has two arguments 'number of arguments' and 'character code. This function inserts a number of specified character in to the string

it's called like this:

String(16,32) ' what means: insert 16 space (code32)

I would like to use this function in VB.Net but with parameters (16,0). I found out that there is a StrDup function, but when I use this parameters there is an exception, thet there have to be more then zero length charater.

I need it to use this string with 16-length string with zero coded character to get some values from API functions.

I've try to searched some similar function in Microsoft.VisualBasic class, but I can't find it.

Have You got any ideas?

thanks for help...
 
.Net gets very upset about using null length strings(or Chr(0))
Try Space(16), usually you can use spaces
 
Well a String is nothing more then an Array of characters. So you could create an Array of 16 chars, initialize them to space, then instantiate a String using that Array.

Or as a matter of fact, you could probably just pass that Array of chars into the API call itself. It's worth a try, and I don't see why it wouldn't work that way.
 
maybe I show You some code:
Visual Basic:
    Public hConnection As Long
    Public hOpen, hFind As Long
    Const MAX_PATH = 260
    Private Structure typeFILETIME
        Dim dwLowDateTime As Long
        Dim dwHighDateTime As Long
    End Structure
    Private Structure WIN32_FIND_DATA
        Dim dwFileAttributes As Long
        Dim ftCreationTime As typeFILETIME
        Dim ftLastAccessTime As typeFILETIME
        Dim ftLastWriteTime As typeFILETIME
        Dim nFileSizeHigh As Long
        Dim nFileSizeLow As Long
        Dim dwReserved0 As Long
        Dim dwReserved1 As Long
        Dim cFileName As String
        Dim cAlternate As String
    End Structure

    Public Function OpenConnection(ByVal Adres As String, ByVal Username As String, ByVal Password As String) As Long
        Dim hOpen As Long
        hOpen = InternetOpen("FTP Connection" & Adres, InternetOpenType, vbNullString, vbNullString, 0)
        hConnection = InternetConnect(hOpen, Adres, INTERNET_DEFAULT_FTP_PORT, Username, Password, INTERNET_SERVICE_FTP, IIf(PassiveConnection, INTERNET_FLAG_PASSIVE, 0), 0)
        OpenConnection = hConnection
    End Function

    Public Function GetFirstFile(Optional ByVal Filter As String = "*.*") As String
        Dim r As String
        Dim pData As WIN32_FIND_DATA, lRet As Long
        pData.cFileName = StrDup(MAX_PATH, " ")
        hFind = FtpFindFirstFile(hConnection, Filter, pData, 0, 0)
        r = Left(pData.cFileName, InStr(1, pData.cFileName, StrDup(1, " "), vbBinaryCompare) - 1)
        GetFirstFile = r
    End Function

    Public Function GetNextFile() As String
        Dim r As String
        Dim pData As WIN32_FIND_DATA, lRet As Long
        pData.cFileName = StrDup(MAX_PATH, " ")
        lRet = InternetFindNextFile(hFind, pData)
        r = Left(pData.cFileName, InStr(1, pData.cFileName, StrDup(1, " "), vbBinaryCompare) - 1)
        GetNextFile = r
    End Function
at this time I'm useing a StrDup function.

This code has to connect the FTP, and return all files of current ftp directory.
 
From the vb help files
Visual Basic:
Dim MyString As String
' Returns a string with 10 spaces.
MyString = Space(10)
' Inserts 10 spaces between two strings.
MyString = "Hello" & Space(10) & "World"
hope it helps
 
You can redefine the API to whatever you want. For example:
Visual Basic:
'Change
    Private Declare Function FtpFindFirstFile Lib "wininet.dll" Alias "FtpFindFirstFileA" (ByVal hFtpSession As Long, ByVal lpszSearchFile As String, ByVal lpFindFileData As WIN32_FIND_DATA, ByVal dwFlags As Long, ByVal dwContent As Long) As Long
'to
    Private Declare Function FtpFindFirstFile Lib "wininet.dll" Alias "FtpFindFirstFileA" (ByVal hFtpSession As Long, ByVal lpszSearchFile As Byte(), ByVal lpFindFileData As WIN32_FIND_DATA, ByVal dwFlags As Long, ByVal dwContent As Long) As Long

(Hope my byte array syntax is right in VB... I'm used to C#)
Then you can pass a byte array and convert it back to a string.

-Nerseus
 
Back
Top