Guidance
指路人
g.yi.org
software / rapidq / Examples / File & Directory / SaveVar.bas

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
'From:  Manuel Candela   Mon Feb 17, 2003  4:51 am
'  Save/retrieve variables
' a workaround to save/retrieve variables to/from
' text files.

'Begin
     $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 'String
     fstream.writeUDT(oneVar)

     oneVar.name = "salario"
     oneVar.value = STR$(4700)
     oneVar.primitive = 1 'Numeric
     fstream.writeUDT(oneVar)

     SHOWMESSAGE "Escrito.."
     fstream.CLOSE


'Retrieve data
     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
'END


     FUNCTION getthevalue(clave AS STRING) AS VARIANT
'Uses vars(..)
      j& = 1
      getthevalue = ""

      WHILE LEN(RTRIM$(vars(j&).name)) > 0
       IF clave = RTRIM$(vars(j&).name) THEN
'Adjust needed
        getthevalue = LEFT$(vars(j&).value, LEN(vars(j&).value)-1)
        EXIT FUNCTION
       END IF

       INC(j&, 1)
      WEND
     END FUNCTION

'It can be created a funcion that get the type (.primitive)
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Fri 2023-1-27  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2003-02-17 07:28:01