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:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

technology leadership

Why the World Needs More Technology Leadership

As a fact, technology has touched every single aspect of our lives. And there are some technology giants in today’s world which have been frequently opined to have a strong influence on recent overall technological influence. Moreover, those tech giants have popular technology leaders leading the companies toward achieving greatness.

iOS app development

The Future of iOS App Development: Trends to Watch

When it launched in 2008, the Apple App Store only had 500 apps available. By the first quarter of 2022, the store had about 2.18 million iOS-exclusive apps. Average monthly app releases for the platform reached 34,000 in the first half of 2022, indicating rapid growth in iOS app development.

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job