Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > VB6 > Строка от CommonDialog(как разделить на части...)


Автор: Farhod 31.8.2002, 01:05
Я сделал свойство CommonDialog таким что бы при вызове окна "Oткрытия файлов" ShowOpen" он открывал (выделял) несколько файлов.И в результате у меня в строке "Имя файла" получается несколько имен файлов разделённые с кавычками. Я хочу сделать так что бы при открытии этих файлов каждый файл добавлялся в ListBox. У меня в свойсве FileName
получается  несколько файлов. Подскажите ...

Автор: Win MK 32 31.8.2002, 05:57
Отлавливай с помощью функции mid() то что между кавычками и добавляй в список.

Автор: Win MK 32 31.8.2002, 05:57
mid(переменная_с_открытыми_файлами, начальный_символ, количество_символов_после_начального)
smile=168

Автор: Farhod 1.9.2002, 00:31
Да но как программно определить кавычки ?

Автор: Win MK 32 1.9.2002, 05:25
text2.text :
Код
"

Перебирай с помощью mid() по одному символу и если он не равен text2.text то переменная1 = переменная1 + этот_символ иначе добавляй "переменная1" в список и переменная1 = ""

Автор: Sniper 21.1.2003, 06:55
FarhodFarhodFarhod

Автор: cardinal 21.1.2003, 07:09
Split Function

Description

Returns a zero-based, one-dimensionalarray containing a specified number of substrings.

Syntax

Split(expression[, delimiter[, count[, compare]]])

The Split function syntax has these parts:

Part Description
expression Required.String expression containing substrings and delimiters. If expression is a zero-length string(""), Split returns an empty array, that is, an array with no elements and no data.
delimiter Optional. String character used to identify substring limits. If omitted, the space character (" ") is assumed to be the delimiter. If delimiter is a zero-length string, a single-element array containing the entire expression string is returned.
count Optional. Number of substrings to be returned; –1 indicates that all substrings are returned.
compare Optional. Numeric value indicating the kind of comparison to use when evaluating substrings. See Settings section for values.


Settings

The compare argument can have the following values:

Constant Value Description
vbUseCompareOption –1 Performs a comparison using the setting of the Option Compare statement.
vbBinaryCompare 0 Performs a binary comparison.
vbTextCompare 1 Performs a textual comparison.
vbDatabaseCompare 2 Microsoft Access only. Performs a comparison based on information in your database.

Автор: Роман 1.7.2005, 13:29
'Быть может "тупорыльно", но работает!!!

inull = False
spath = CommonDialog1.FileName

n = 0
m = Len(spath) - 1
Dim mf() As String ' массив файлов

If Mid(spath, Len(spath), 1) = Chr(0) Then spath = Mid(spath, 1, Len(spath) - 1)
Do While inull = False

i = InStrRev(spath, vbNullChar)
If i = 0 Then inull = True Else tmp = Mid(spath, i + 1, Len(spath) - i)
If i = Len(spath) Then ReDim Preserve mf(0): mf(0) = tmp
temp = Mid(spath, i + 1, Len(spath) - i)
If i <> 0 Then spath = Mid(spath, 1, i - 1)
If temp <> "" Then ReDim Preserve mf(n + 1): mf(n) = temp: n = n + 1
Loop

If n = 1 Then n = 2 ' типа если был 1 файл, то 2, т.к. первое значение - путь
For i = 0 To n - 2
MsgBox mf(i)
Next i

' получили как вы поняли массив mf () от 0 до n-2

Автор: ~FoX~ 1.7.2005, 13:51
split возвращает массив стрингов.

Автор: Vach 1.7.2005, 14:41
Роман используй теги кода.
Пример с использованием Split Function
Код
Private Const cdlOFNAllowMultiselect = &H200
Private Const cdlOFNCreatePrompt = &H2000
Private Const cdlOFNExplorer = &H80000
Private Const cdlOFNExtensionDifferent = &H400
Private Const cdlOFNFileMustExist = &H1000
Private Const cdlOFNHelpButton = &H10
Private Const cdlOFNHideReadOnly = &H4
Private Const cdlOFNLongNames = &H200000
Private Const cdlOFNNoChangeDir = &H8
Private Const cdlOFNNoDereferenceLinks = &H100000
Private Const cdlOFNNoLongNames = &H40000
Private Const cdlOFNNoReadOnlyReturn = &H8000
Private Const cdlOFNNoValidate = &H100
Private Const cdlOFNOverwritePrompt = &H2
Private Const cdlOFNPathMustExist = &H800
Private Const cdlOFNReadOnly = &H1
Private Const cdlOFNShareAware = &H4000
Private Const CD_FLAGS = cdlOFNAllowMultiselect + cdlOFNExplorer + cdlOFNLongNames

Private Sub Form_Load()
With CommonDialog1
        .CancelError = True
        .MaxFileSize = 32000
        .Filter = "All Files *.*/*.*"
        .Flags = CD_FLAGS
        .ShowOpen
        
        myFiles = Split(.FileName, vbNullChar) 'собственно замена твоего кода
         
        Select Case UBound(myFiles)
            Case 0
                List1.AddItem myFiles(0)
            Case Is > 0
                For i = 1 To UBound(myFiles)
                    myPath = myFiles(0) & IIf(Right(myFiles(0), 1) <> "\", "\", "") & myFiles(i)
                    List1.AddItem myPath
                Next i
        End Select
End With
End Sub

Автор: Naghual 1.7.2005, 17:52
А по моему проще будет разобратся с кавычками через Replace?

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)