Hardware Reference
In-Depth Information
INPUT #1, a(n%)
NEXT N%
CLOSE #l
END SUB
It is important to note that in both the Loaddata and Savedata subprograms,
the data array, a() , has been declared as SHARED between the procedure and
the main code. The subprograms therefore have access to the data held in the
array without the need for values to be passed in the form of a parameter list.
As a further example of simple file handling, the following routines written
in Visual Basic show how it is possible to read and write parameters required
to configure a serial communications port (note that this application requires
the MSComm control from the Visual Basic Toolbox). In order to write the five
string data values required to configure a serial port we could use:
Public Sub WriteDataParamFile()
Dim FILENUM As Byte
FILENUM = FreeFile ' get ID for the first available free file
Open "SetCom.txt" For Output As #FILENUM
Print #FILENUM, sComPort
Print #FILENUM, sBaudRate
Print #FILENUM, sParity
Print #FILENUM, sDataBits
Print #FILENUM, sStopBits
Close #FILENUM
End Sub
Typical default values for the string data might be:
sComPort = "1"
sBaudRate = "9600"
sParity = "N"
sDataBits = "8"
sStopBits = "1"
The stored data file will thus comprise the following data:
1,9600,N,8,1
In order to read the data file we will need a routine like the following:
Public Sub ReadDataParamFile()
Dim FILENUM As Byte
FILENUM = FreeFile ' get ID for the first available free file
Open "SetCom.txt" For Input As #FILENUM
Input #FILENUM, sComPort
Input #FILENUM, sBaudRate
Input #FILENUM, sParity
Input #FILENUM, sDataBits
Input #FILENUM, sStopBits
Close #FILENUM
End Sub
Note that, in practice the foregoing routine would require a simple error
handler (using, for example, On Error GoTo ) to cope with the eventuality that
the file was not found.
Search WWH ::




Custom Search