Se esperaba un objeto

Manoli
01 de Septiembre del 2003
Hola a todos!

Tengo este codigo para que me corte trozos de un textarea pero me dice que se esperaba un objeto al darle al bot贸n que llama a la funci贸n.

<script language="JavaScript" type="text/javascript">
function transformar()
{
cadena=form.txtIntroducir.value
Trim (cadena)
longitud = Len(cadena)
temp1 = InStr(cadena, "Cuenta de mayor facturaci贸n:")
strTemp = Left(cadena, temp1 - 4)
temp2 = InStr(strTemp, "NIF/CIF:")
Largetemp = Len(strTemp)
strTemp = Right(strTemp, Largetemp - (temp2 + 8))
strTemp = Replace(strTemp, "NIF/CIF:", "")
NIF_CIF = LTrim(strTemp)

cadena = Right(cadena, longitud - temp1)
longitud = Len(cadena)
temp1 = InStr(cadena, "Contacto:")
strTemp = Left(cadena, temp1 - 3)
temp2 = InStr(strTemp, "Nombre:")
Largetemp = Len(strTemp)
strTemp = Right(strTemp, Largetemp - (temp2 + 6))
strTemp = Replace(strTemp, "Nombre:", "")
Nombre = Trim(strTemp)
function transformar()
{
cadena=form.txtIntroducir.value
Trim (cadena)
longitud = Len(cadena)
temp1 = InStr(cadena, "Cuenta de mayor facturaci贸n:")
strTemp = Left(cadena, temp1 - 4)
temp2 = InStr(strTemp, "NIF/CIF:")
Largetemp = Len(strTemp)
strTemp = Right(strTemp, Largetemp - (temp2 + 8))
strTemp = Replace(strTemp, "NIF/CIF:", "")
NIF_CIF = LTrim(strTemp)

cadena = Right(cadena, longitud - temp1)
longitud = Len(cadena)
temp1 = InStr(cadena, "Contacto:")
strTemp = Left(cadena, temp1 - 3)
temp2 = InStr(strTemp, "Nombre:")
Largetemp = Len(strTemp)
strTemp = Right(strTemp, Largetemp - (temp2 + 6))
strTemp = Replace(strTemp, "Nombre:", "")
Nombre = Trim(strTemp)
}
</scrip>

Alguien podr铆a decirme como puedo hacerlo. Un saludo y muchas gracias.

Juan
01 de Septiembre del 2003
Est谩s mezclando JavaScript y VBScript, las funciones Left,
Right, Trim, Replace... son de VBScript. Tu script
tiene la propiedad language="javascript" y el encabezado
de la funcion tiene sintaxis javascript, mientras que el
cuerpo de la funci贸n utiliza VBScript. Soluciona eso
antes de seguir peleando con la funci贸n.

Manoli
01 de Septiembre del 2003
Hola!

Ya he cambiado eso pero me continua dando error de caracter no v谩lido y algunos mas.

Mi codigo ahora es:

<script language="VBScript">

function transformar()
{
cadena=form.txtIntroducir.value
Trim (cadena)
longitud = Len(cadena)
temp1 = InStr(cadena, "Cuenta de mayor facturaci贸n:")
strTemp = Left(cadena, temp1 - 4)
temp2 = InStr(strTemp, "NIF/CIF:")
Largetemp = Len(strTemp)
strTemp = Right(strTemp, Largetemp - (temp2 + 8))
strTemp = Replace(strTemp, "NIF/CIF:", "")
NIF_CIF = LTrim(strTemp)

cadena = Right(cadena, longitud - temp1)
longitud = Len(cadena)
temp1 = InStr(cadena, "Contacto:")
strTemp = Left(cadena, temp1 - 3)
temp2 = InStr(strTemp, "Nombre:")
Largetemp = Len(strTemp)
strTemp = Right(strTemp, Largetemp - (temp2 + 6))
strTemp = Replace(strTemp, "Nombre:", "")
Nombre = Trim(strTemp)

cadena = Right(cadena, longitud - temp1)
longitud = Len(cadena)
temp1 = InStr(cadena, "Cargo:")
strTemp = Left(cadena, temp1 - 3)
temp2 = InStr(strTemp, "Contacto:")
Largetemp = Len(strTemp)
strTemp = Right(strTemp, Largetemp - (temp2 + 10))
strTemp = Replace(strTemp, "Contacto:", "")
Contacto = Trim(strTemp)

cadena = Right(cadena, longitud - temp1)
longitud = Len(cadena)
temp1 = InStr(cadena, "C贸digo postal:")
strTemp = Left(cadena, temp1 - 3)
temp2 = InStr(strTemp, "Direcci贸n:")
Largetemp = Len(strTemp)
strTemp = Right(strTemp, Largetemp - (temp2 + 10))
strTemp = Replace(strTemp, "Direcci贸n:", "")
Direccion = Trim(strTemp)
cadena = Right(cadena, longitud - temp1)

longitud = Len(cadena)
temp1 = InStr(cadena, "Provincia:")
strTemp = Left(cadena, temp1 - 3)
temp2 = InStr(strTemp, "C贸digo postal:")
Largetemp = Len(strTemp)
strTemp = Right(strTemp, Largetemp - (temp2 + 15))
strTemp = Replace(strTemp, "C贸digo postal:", "")
codigo_postal = Trim(strTemp)
cadena = Right(cadena, longitud - temp1)

longitud = Len(cadena)
temp1 = InStr(cadena, "Localidad:")
strTemp = Left(cadena, temp1 - 3)
temp2 = InStr(strTemp, "Provincia:")
Largetemp = Len(strTemp)
strTemp = Right(strTemp, Largetemp - (temp2 + 10))
strTemp = Replace(strTemp, "Provincia", "")
Provincia = Trim(strTemp)
cadena = Right(cadena, longitud - temp1)

longitud = Len(cadena)
temp1 = InStr(cadena, "Tel茅fono:")
strTemp = Left(cadena, temp1 - 3)
temp2 = InStr(strTemp, "Localidad:")
Largetemp = Len(strTemp)
strTemp = Right(strTemp, Largetemp - (temp2 + 10))
strTemp = Replace(strTemp, "Localidad:", "")
Localidad = Trim(strTemp)
cadena = Right(cadena, longitud - temp1)

longitud = Len(cadena)
temp1 = InStr(cadena, "Equipo m谩s pr贸ximo :")
strTemp = Left(cadena, temp1 - 3)
temp2 = InStr(strTemp, "Tel茅fono:")
Largetemp = Len(strTemp)
strTemp = Right(strTemp, Largetemp - (temp2 + 10))
strTemp = Replace(strTemp, "Tel茅fono:", "")
telefono = Trim(strTemp)
cadena = Right(cadena, longitud - temp1)

txtDni.value = NIF_CIF
txtNombre.value = Nombre
txtContacto.value = Contacto
txtDireccion.value= Direccion
txtCodigo_postal.value= codigo_postal
txtLocalidad.value= Localidad
txtProvincia.value = Provincia
txtTelefono.value = telefono %>
}
</script>
Muchas gracias y un saludo.

Juan
01 de Septiembre del 2003
Todav铆a no has cambiado la sintaxis en la cabecera de
la funci贸n. Donde pones "function Transformar(){" ,
pon "Sub Transformar()" , sin la llave, y para cerrar la
funci贸n en lugar de una llave cerrada "}" pon
"End Sub".

A parte de eso te he visto algunos fallos, por ejemplo
en la 2ª linea pones Trim(cadena) y no recoges el valor
de retorno, si quieres quitar los espacios a cadena
deber铆as hacer cadena=Trim(cadena).

En la 煤ltima linea tienes estos caracteres "%>" , que no deber铆an estar ah铆.

Adem谩s no declaras ninguna variable, creo que no es
necesario pero ser铆a conveniente que lo hicieras.

A parte de eso no he detectado m谩s errores.

Manoli
01 de Septiembre del 2003
Muchas gracias!
Ya me ha salido pero no puedo ver los datos que obtengo porque me actualiza la p谩gina, para verlos tengo que irme hacia atr谩s.
¿C贸mo puedo hacer para que los datos como nombre, NIF_CIF,..., visualizarlos en unas cajas de texto de otra p谩gina por si el usuario quiere modificarlos antes de introducirlos en la base de datos??
Muchas gracias.