Function Format (byval valor, decimales)
		' Formatea el valor que se le pasa a la cantidad de decimales definidos
		dim Entero
		dim Decimal
		dim i
		dim strEntero
		dim fmtEntero
		dim Longitud
		dim strDecimal
		Dim IsNegative

		' Leo - Lun 10 Feb 2003  - 10:47:15 A
		' **********************************
		If isnull(valor) Then
			Format = ""
			Exit Function
		else
			Format = "Error!"
			if not isnumeric(cstr(valor)) then Exit Function
		End If
		' **********************************

		valor = cdbl(valor)
		valor = round(valor, decimales)
		Entero = int(valor)

		strEntero = cstr(Entero)
		If InStr(Entero, "-") > 0 Then
			IsNegative = true
			strEntero = replace(strEntero, "-", "")
		End If
		Longitud = len(strEntero)
		i = 0
		while i < Longitud
			if i > 0 and i mod 3 = 0 then fmtEntero = "." & fmtEntero
			fmtEntero = mid(strEntero, Longitud - i, 1) & fmtEntero
			i = i + 1
		wend
		
		If IsNegative Then fmtEntero = "-" & fmtEntero
		
		Format = fmtEntero

		if Valor <> Entero then
			strDecimal = cstr(valor)
			Longitud = len(strDecimal)
			i = 0
			while i < Longitud
				if not isnumeric(mid(strDecimal, Longitud - i, 1)) then
					strDecimal = right(strDecimal, i)
					i = Longitud
				end if
				i = i + 1
			wend
		end if
		
		if decimales > 0 then
			while len(strDecimal) < decimales
				strDecimal = strDecimal & "0"
			wend
			Format = Format & "," & strDecimal
		end if
	End Function

Function GetDecimalSeparator()
	dim a
	a = cstr(1.12)
	GetDecimalSeparator = mid(a, 2, 1)
End Function

Function OkMsgBox(ErrMsg, Title)
	Do While MsgBox(ErrMsg, 321, Title) <> 1
	Loop
End Function

Function GetControlValue(CtrlValue)
	GetControlValue = replace(CtrlValue, ".", GetDecimalSeparator)
End Function

Function SetControlValue(CtrlValue)
	SetControlValue = replace(CtrlValue, GetDecimalSeparator, ".")
End Function

Function MessageBox(Message, Style, Title)
  If Style = "" Then Style = vbInformation
  MessageBox = msgbox(Message, Style, Title)
End Function

Function BinarySearch(list, target)
	Dim middle
	Dim min
	Dim max

	min = LBound(list)
	max = UBound(list)

	' During the search, min <= target index <= max.
	Do While min <= max
		middle = (min + max) \ 2
		If target = list(middle) Then
			' We found it.
			BinarySearch = middle
			Exit Function
		ElseIf target < list(middle) Then
			' Search the left half.
			max = middle - 1
		Else
			' Search the right half.
			min = middle + 1
		End If
	Loop

	BinarySearch = -1
End Function

Function ValidateCuit(byval argCuit)
	' Valida que un número de C.U.I.T. sea válido
	Dim I, Crc, Resto, Factor, Checksum, CurCuit, StrCuit
	Dim ArrCuit(10)

	' Controlar valor significativo.
	argCuit = replace(argCuit, " ", "")	
	argCuit = replace(argCuit, "-", "")	
	if len(argCuit) <> 11 or not isnumeric(argCuit) then
		ValidateCuit = -1
		exit function
	end if

	CurCuit = ccur(argCuit)
	if IsNull(CurCuit) or CurCuit = 0 then
		ValidateCuit = 1
		exit function
	end if

	' Controles varios.
	if CurCuit < 10000000000. or CurCuit > 99999999999. or CurCuit <> fix(CurCuit) then
		ValidateCuit = -1
		exit function
	end if
	
	' Control Checksum.
	' Cargar array
	StrCuit = cstr(CurCuit)
	for I = 0 to len(StrCuit) - 1
		ArrCuit(I) = mid(StrCuit, I + 1, 1)
	next

	Factor = 5
	Checksum = 0
	for I = 0 to 9
		Checksum = Checksum + Factor * cint(ArrCuit(I))
		Factor = Factor - 1
		if Factor < 2 then Factor = 7
	next
	Resto = Checksum Mod 11
	if Resto = 0 then
		Crc = 0
	else
		Crc = 11 - Resto
		if Crc = 10 then Crc = 9
	end If
	if Crc <> cint(ArrCuit(10)) then
		ValidateCuit = -1
		exit function
	end If

	ValidateCuit = 1
End Function