Перейти из форума на сайт.

НовостиФайловые архивы
ПоискАктивные темыТоп лист
ПравилаКто в on-line?
Вход Забыли пароль? Первый раз на этом сайте? Регистрация
Компьютерный форум Ru.Board » Компьютеры » Прикладное программирование » Excel VBA (часть 3)

Модерирует : ShIvADeSt

 Версия для печати • ПодписатьсяДобавить в закладки
На первую страницук этому сообщениюк последнему сообщению

Открыть новую тему     Написать ответ в эту тему

nick7inc



Advanced Member
Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору

Код:
Private text_file_map() As Long
Private file_number As Long
 
 
 
Private Sub Class_Initialize()
file_number = 0
ReDim text_file_map(1 To 100)
End Sub
 
Private Sub Class_Terminate()
Erase text_file_map()
Close_file
End Sub
 
Public Sub Close_file()
If file_number > 0 Then Close #file_number: file_number = 0
End Sub
 
Public Function file_num() As Long
file_num = file_number
End Function
 
Public Sub Open_file(filename As String)
Close_file
file_number = FreeFile(0)
Open filename For Input As #file_number
End Sub
 
Public Sub get_text_line(ByVal line_number As Long, ByRef text As String)
If file_number <= 0 Then Exit Sub
 
Dim size As Long
size = UBound(text_file_map)
If size > line_number Then '!!! size >= line_number+1
    If text_file_map(line_number) > 0 Then
        Seek #file_number, text_file_map(line_number)
        Line Input #file_number, text
        Exit Sub
    End If
Else
    If line_number < size * 2 Then size = size * 2 Else size = line_number * 2
    ReDim Preserve text_file_map(1 To size)
End If
Dim cur_line As Long
cur_line = 1
   
Do While (text_file_map(cur_line) > 0)
    cur_line = cur_line + 1
Loop
   
If cur_line = 1 Then text_file_map(1) = 1: cur_line = cur_line + 1
   
Seek #file_number, text_file_map(cur_line - 1)
Line Input #file_number, text
If EOF(file_number) Then Exit Sub
text_file_map(cur_line) = Seek(file_number)
   
  ' cur_line указывает на пустой адрес text_file_map(), который надо заполнить
Dim i As Long
For i = cur_line To line_number
    Line Input #file_number, text
    If EOF(file_number) Then Exit Sub
    text_file_map(i + 1) = Seek(file_number)
Next i
   
End Sub
 

Всего записей: 1138 | Зарегистр. 04-05-2007 | Отправлено: 13:03 18-06-2013 | Исправлено: nick7inc, 13:09 18-06-2013
Открыть новую тему     Написать ответ в эту тему

На первую страницук этому сообщениюк последнему сообщению

Компьютерный форум Ru.Board » Компьютеры » Прикладное программирование » Excel VBA (часть 3)


Реклама на форуме Ru.Board.

Powered by Ikonboard "v2.1.7b" © 2000 Ikonboard.com
Modified by Ru.B0ard
© Ru.B0ard 2000-2024

BitCoin: 1NGG1chHtUvrtEqjeerQCKDMUi6S6CG4iC

Рейтинг.ru