Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

My ini is returning a string value to my VB application but it is bringing it back with a square block on the end of the string.

It is an db path like this "C:\irs\irs1.mdb"

trouble is it has the square symbol at th eend of it.

Anyone know a way to stop the square coming back with the string?

 

Andy

Posted

Dim strCon As String

Dim sString As String

Dim lSize As Long

Dim lReturn As Long

 

Dim sNull As String

sString = String$(16, "*")

lSize = Len(sString)

 

 

lReturn = GetPrivateProfileString("irsconnection", "irsconn", "", sString, lSize, sFile)

strCon = sString

Connect.ConStr = strCon

  • *Experts*
Posted

Well, I suppose it's possible that your buffer is a bit too large. Try

doing it like this:

Dim lSize As Long
Dim sString As String = New String(" ", 300) 'create the buffer; this is a better way than String$

lSize = GetPrivateProfileString("irsconnection", "irsconn", "", sString, 300, sFile)
sString = sString.SubString(0, lSize)

That dynamically gets the required size, rather than fixing it in one

spot.

 

Also, you should not use String$, as it is a VB6 compatability function

and is not CLR compliant.

  • *Experts*
Posted

Also, instead of using INI files, I would recommend using XML files

instead, as .NET has native support for them. Read in the MSDN about the System.Xml namespace.

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