Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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...

Posted

.Net gets very upset about using null length strings(or Chr(0))

Try Space(16), usually you can use spaces

.Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?
Posted

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.

Gamer extraordinaire. Programmer wannabe.
Posted

maybe I show You some code:

   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.

  • *Experts*
Posted

From the vb help files

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

  • *Experts*
Posted

You can redefine the API to whatever you want. For example:

'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

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...