Tools html

Description

C'est un petit exemple d'utilisation d'objet en ASP.
Le but étant de se simplifier la vie en ayant des objets formulaires prêts à l'emploi et de pouvoir facilement changer l'aspect d'un site sans se retaper tout le html.
Le zip comprend un fichier test qui utilise ces objets

Happy coding !

Source / Exemple :


<%
'Toutes licences accordées à zappy

class typeItem
	public key
	public caption
end class

class optiComboBox
	public SelectName
	
	private myItem()
	private ItemCount
	public activeKey
	
	
	public function AddItem(key, caption)
		redim preserve myItem(ItemCount)
		set myItem(ItemCount) = new typeItem
		myItem(ItemCount).key = key
		myItem(ItemCount).caption = caption
		ItemCount = ItemCount + 1
	end function

	public sub Clear()
		erase MyItem
		ItemCount = 0
	end sub
		
	public function getStringHTML()
		dim strBuffer, i
		if ItemCount > 0 then
			for i=0 to (ItemCount - 1) step 1
				strBuffer = strBuffer & "<option value=" & chr(34) & myItem(i).key & chr(34)
				if myItem(i).key = activeKey then
					strBuffer = strBuffer & " selected"
				end if
				strBuffer = strBuffer & ">" & myItem(i).caption & "</option>" & VbCrLf
			next
			strBuffer = "<select name=" & chr(34) & SelectName & chr(34) & ">" & VbCrLf & strBuffer & "</select>"
		end if
		getStringHTML = strBuffer
	end function
end class

class optiDateComboBox
	public intMinYear
	public intMaxYear
	public dtValue
	public strName
	
	private sub class_initialize()
		intMinYear = year(now()) - 100
		intMaxYear = year(now()) + 1
	end sub
	
	public function SetNewValue(strDay, strMonth, strYear)
		dim strBuffer
		strBuffer = strDay & "/" & strMonth & "/" & strYear
		if isdate(strbuffer) then
			dtValue = CDate(strBuffer)
			SetNewValue = true
		else
			SetNewValue = false
		end if
	end function
	
	public function getStringHTML()
		Dim strBuffer
		Dim i
		
		If intMinYear > intMaxYear Then Exit Function
		if not isdate(dtValue) then dtValue = #01/01/1950#
		'Les jours
		strBuffer = "<select name=" & Chr(34) & strName & "jj" & Chr(34) & ">" & VbCrLf
		For i = 1 To 31 Step 1
		   strBuffer = strBuffer & "<option value=" & Chr(34) & CStr(i) & Chr(34)
		   If CInt(Day(dtValue)) = i Then strBuffer = strBuffer & " selected"
		   strBuffer = strBuffer & ">" & CStringNombre(i,2) & "</option>" & VbCrLf
		Next
		strBuffer = strBuffer & "</select>" & VbCrLf & "/" & VbCrLf
		
		'Les mois
		strBuffer = strBuffer & "<select name=" & Chr(34) & strName & "mm" & Chr(34) & ">" & VbCrLf
		For i = 1 To 12 Step 1
		   strBuffer = strBuffer & "<option value=" & Chr(34) & CStr(i) & Chr(34)
		   If CInt(Month(dtValue)) = i Then strBuffer = strBuffer & " selected"
		   strBuffer = strBuffer & ">" & CStringNombre(i,2) & "</option>" & VbCrLf
		Next
		strBuffer = strBuffer & "</select>" & VbCrLf & "/" & VbCrLf
		
		
		'Les annees
		strBuffer = strBuffer & "<select name=" & Chr(34) & strName & "aa" & Chr(34) & ">" & VbCrLf
		For i = intMinYear To intMaxYear Step 1
		   strBuffer = strBuffer & "<option value=" & Chr(34) & CStr(i) & Chr(34)
		   If CInt(Year(dtValue)) = i Then strBuffer = strBuffer & " selected"
		   strBuffer = strBuffer & ">" & CStringNombre(i,4) & "</option>" & VbCrLf
		Next
		strBuffer = strBuffer & "</select>" & VbCrLf
		
		getStringHTML = strBuffer
	end function
end class

class optiRadioBox
	public RadioName
	private myItem()
	private ItemCount
	public activeKey
	
	
	public function AddItem(key, caption)
		redim preserve myItem(ItemCount)
		set myItem(ItemCount) = new typeItem
		myItem(ItemCount).key = key
		myItem(ItemCount).caption = caption
		ItemCount = ItemCount + 1
	end function

	public sub Clear()
		erase MyItem
		ItemCount = 0
	end sub
	
	public property get CountItem()
		CountItem = ItemCount
	end property
	
	public function GetStringHTML(itemKey)
		for i = 0 to ItemCount - 1 step 1
			if myItem(i).key = itemKey then
				GetStringHTML = GetStringHTMLItem(i)
				exit for
			end if
		next
	end function
	public function GetStringHTMLItem(indexItem)
		dim strBuffer
		strBuffer = "<input type=""radio"" name=""" & RadioName & """ value=""" & cstr(myItem(indexItem).key) & """"
		if myItem(indexItem).key = activeKey then
			strBuffer = strBuffer & " CHECKED"
		end if
		GetStringHTMLItem = strBuffer & ">" & myItem(indexItem).caption
	end function	
end class

public function CStringNombre(value, nbrChiffre)
	if len(cstr(value)) < nbrChiffre then
		CStringNombre = string(nbrChiffre - len(cstr(value)),"0") & cstr(value)
	else
		CStringNombre = cstr(value)
	end if
end function

function opt_processArray(inArray, inStringRow)
	
	returnString = ""
	bufferString = ""
	on error resume next
	
	nbrRow = ubound(inArray) - lbound(inArray) 
	nbrField = ubound(inArray, 2) - lbound(inArray, 2)
	if err.number <> 0 then exit function
	
	on error goto 0
	
	for i = lbound(inArray) to ubound(inArray) step 1
		bufferString = inStringRow
		for n=lbound(inArray,2) to ubound(inArray,2) step 1
			bufferString = replace(bufferString, "{" & CStr(n) & "}",CStr(inArray(i,n)))
		next
		returnString = returnString & bufferString 'Retour charriot dans la string passée en argument !!
	next
	
	opt_processArray = returnString
end function
%>

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.