Algorytmy i Programowanie Ćwiczenia: VBA (12)
Transkrypt
Algorytmy i Programowanie Ćwiczenia: VBA (12)
(C) 2005 RoG@j 2005-05-23 Algorytmy i Programowanie Ćwiczenia: VBA (12) Program zajęć (wg. TS…) ! Łańcuchy znakowe: ! © 2005 R. Robert Gajewski [email protected] http://rogaj.il.pw.edu.pl ! ! ! ! typ String, kodowanie ASCI, operacje na podciągach znakowych, operatory konkatenacji (łączenia) i porównania, funkcje tekstowe, konwersje danych tekstowych i liczbowych (jawne i niejawne) Wiosna 2005 Program zajęć (wg. TS…) ! ! ! ! ! ! praca z zewnętrznymi źródłami danych, podstawowe operacje I/O, otwieranie i zamykanie plików dyskowych, sekwencyjne przetwarzanie danych z/do plików tekstowych, formatowanie, systemowe operacje na plikach (kopiowanie, usuwanie, sprawdzanie istnienia pliku o podanej nazwie, itp.) Wiosna 2005 AiPOI 2004/2005 ! ! 3 ! ! ! ! ! Returns a Long containing the number of characters in a string or the number of bytes required to store a variable. ! ! Any valid string expression. varname ! ! Any valid variable name. One (and only one) of the two possible arguments must be specified. With user-defined types, Len returns the size as it will be written to the file. Wiosna 2005 AiPOI Cw 12 A valid named or user-defined format expression. AiPOI 2004/2005 4 Function Space() Len (string | varname) string ! Wiosna 2005 Any valid expression. format Optional. ! Len(): ! Returns a Variant (String) containing an expression formatted according to instructions contained in a format expression. Format (expression[, format]) expression Required. ! ! Function Len() ! 2 Format Function Pliki: ! AiPOI 2004/2005 AiPOI 2004/2005 5 Wiosna 2005 Space Function: Returns a Variant (String) consisting of the specified number of spaces. Space (number) The required number argument is the number of spaces you want in the string. The Space function is useful for formatting output and clearing data in fixed-length strings. AiPOI 2004/2005 6 1 (C) 2005 RoG@j 2005-05-23 FreeFile() ! ! ! ! Open Statement Returns an Integer representing the next file number available for use by the Open statement. FreeFile [(rangenumber)] The optional rangenumber argument is a Variant that specifies the range from which the next free file number is to be returned. Specify a 0 (default) to return a file number in the range 1 – 255, inclusive. Specify a 1 to return a file number in the range 256 – 511. Use FreeFile to supply a file number that is not already in use. Wiosna 2005 AiPOI 2004/2005 ! ! ! ! ! ! ! ! ! ! Any valid file number. AiPOI 2004/2005 ! 9 ! Wiosna 2005 ! ! ! Any valid file number. varlist Required. ! Comma-delimited list of variables that are assigned values read from the file — can't be an array or object variable. However, variables that describe an element of an array or user-defined type may be used. Wiosna 2005 AiPOI Cw 12 AiPOI 2004/2005 Any valid file number. outputlist Optional. Expression or list of expressions to print. AiPOI 2004/2005 10 Close statement Reads data from an open sequential file and assigns the data to variables. Input #filenumber, varlist filenumber Required. ! 8 Writes display-formatted data to a sequential file. Print #filenumber, [outputlist] filenumber Required. ! Input # Statement ! AiPOI 2004/2005 ! ! One or more comma-delimited numeric expressions or string expressions to write to a file. Wiosna 2005 ! Wiosna 2005 ! outputlist Optional. ! A valid file number in the range 1 to 511, inclusive. Use the FreeFile function to obtain the next available file number. Print # Statement Write # Statement - Writes data to a sequential file. Write #filenumber, [outputlist] filenumber Required. ! ! Keyword specifying the file mode: Append, Binary, Input, Output, or Random. If unspecified, the file is opened for Random access. filenumber Required. ! 7 String expression that specifies a file name — may include directory or folder, and drive. mode Required. ! Write Input statements ! Enables input/output (I/O) to a file. Open pathname For mode As [#]filenumber pathname Required. ! ! 11 Wiosna 2005 Concludes input/output (I/O) to a file opened using the Open statement. Close [filenumberlist] The optional filenumberlist argument can be one or more file numbers using the following syntax, where filenumber is any valid file number: If you omit filenumberlist, all active files opened by the Open statement are closed. When the Close statement is executed, the association of a file with its file number ends. AiPOI 2004/2005 12 2