Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Intermediate
Oct 9, 1998

Add User Properties to Controls

To add user-defined properties to controls, use this code to store them in the control's tag. You can define multiple additional properties at design or run time. You can easily retrieve the value stored:

 Control.Tag = AddParam((Control.Tag), _
	"tooltip", "Close this window.")
Control.Tag = AddParam((Control.Tag), "user", "True")
Tooltip = GetParam((Control.Tag), "tooltip")

Function AddParam (Text As String, _
	Param As String, Value) As String
Dim Text1 As String
If Not IsNull(GetParam(Text, Param)) Then
	Text1 = DelParam(Text, Param)
Else
	Text1 = Text
End If
If Text1 <> "" Then
	Text1 = Text1 & ";"
End If
AddParam = Text1 & Param & "=" & (Value)
End Function
Function DelParam (Text As String, _
	Param As String) As String
Dim i As Integer
Dim j As Integer
Dim s1 As String
Dim s2 As String
Dim Text1 As String
Text1 = Text
i = InStr(UCase(Text), UCase(Param) & "=")
If i > 0 Then
	If i = 1 Then
		s1 = ""
	Else
		s1 = Left(Text, i - 2)
	End If
	j = InStr(i, Text, ";")
	If j > 0 Then
		s2 = Mid(Text, j + 1)
	Else
		s2 = ""
	End If
	If s1 = "" Or s2 = "" Then
		Text1 = s1 & s2
	Else
		Text1 = s1 & ";" & s2
	End If
End If
DelParam = Text1
End Function
Function GetParam (Text, Param)
Dim i As Integer
Dim j As Integer
Dim Text1 As String
If Len(Text) Then
	If Left(Text, 1) <> "'" Then
		Text1 = ";" & Text & ";"
		i = InStr(LCase(Text1), ";" _
			& LCase(Param) & "=")  + 1
		If i > 1 Then
			j = InStr(i + Len(Param), Text1, ";")
			GetParam = Mid(Text1, i + Len(Param) + 1, _
				j - i - Len(Param) - 1)
		Else
			GetParam = Null
		End If
	Else
		GetParam = Null
	End If
Else
	GetParam = Null
End If
End Function
Dean Genner
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date