Strip Comments Off Strings Returned by GetPrivateProfileString

Strip Comments Off Strings Returned by GetPrivateProfileString

Windows doesn’t treat comments in INI files the same way VB does in code. Typically, comments must be on a single line of their own. When calling the GetPrivateProfileString function, if the requested entry contains a Rem statement-such as “; this is a rem’d statement”-the entire entry, value and comment, will be returned.

If your code anticipates the entry without comment, confusion could result from a user entering a comment following the entry rather than on a separate line. Use this VB code example to properly receive a return using the GetPrivateProfileString function call under any circumstance:

 Private Declare Function GetPrivateProfileString _	Lib "kernel32" Alias _	"GetPrivateProfileStringA" (ByVal _	lpApplicationName As Any, ByVal lpKeyName As _	Any, ByVal lpDefault As String, ByVal _	lpReturnedString As String, ByVal nSize As _	Long, ByVal lpFileName As String) As LongPrivate Sub Form_Click()	Dim IniString As String	Dim sDefault As String	Dim lReturn As Long	sDefault = "n/a"	' allocate sufficient buffer	IniString = String$(260, 0)	lReturn = GetPrivateProfileString("DB", _		"Path", sDefault, IniString, _		Len(IniString), "c:	est.ini")	If lReturn > 0 Then		IniString = Left$(IniString, lReturn)		Debug.Print IniString		' added to strip out trailing comments		If InStr(IniString, ";") > 0 Then			IniString = Trim$(Left$(IniString, _				InStr(IniString, ";") - 1))			If InStr(IniString, vbTab) > 0 Then				IniString = Trim$(Left$(IniString, _					InStr(IniString, vbTab) - 1))			End If		End If	Else		IniString = sDefault	End If	Debug.Print IniStringEnd Sub
Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several