$INCLUDE "rapidq.inc"
TYPE varInf
name AS STRING*30
value AS STRING*20
primitive AS BYTE
END TYPE
DECLARE FUNCTION getthevalue(clave AS STRING) AS VARIANT
DIM oneVar AS varInf
DIM vars(1 TO 10) AS varInf
DIM fstream AS QFILESTREAM
IF fstream.OPEN("d:\bas-arch\varsave.txt", fmOpenWrite) = FALSE THEN
SHOWMESSAGE "No se pudo escribir"
END
END IF
fstream.position = 0
oneVar.name = "nombre"
oneVar.value = "Manuel"
oneVar.primitive = 0
fstream.writeUDT(oneVar)
oneVar.name = "salario"
oneVar.value = STR$(4700)
oneVar.primitive = 1
fstream.writeUDT(oneVar)
SHOWMESSAGE "Escrito.."
fstream.CLOSE
IF fstream.OPEN("d:\bas-arch\varsave.txt", fmOpenRead) = FALSE THEN
SHOWMESSAGE "No se pudo leer"
END
END IF
n% = fstream.size
i& = 1
WHILE fstream.position < n%
fstream.readUDT(vars(i&))
INC(i&, 1)
WEND
DIM nombre AS VARIANT, salario AS VARIANT
nombre = gettheValue("nombre")
salario = gettheValue("salario")
SHOWMESSAGE nombre +" ("+ salario +")" + " " + STR$(3)
fstream.CLOSE
FUNCTION getthevalue(clave AS STRING) AS VARIANT
j& = 1
getthevalue = ""
WHILE LEN(RTRIM$(vars(j&).name)) > 0
IF clave = RTRIM$(vars(j&).name) THEN
getthevalue = LEFT$(vars(j&).value, LEN(vars(j&).value)-1)
EXIT FUNCTION
END IF
INC(j&, 1)
WEND
END FUNCTION
|