You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
> There is always another way to skin your Felis domesticus.
Sure is. Put 10 programmers to write 3 identical lines of code
and you'll end with 10 different solutions. Not possible? For
programmers, everything is possible..
BTW, I often use arrays for this purpose myself. In some cases,
using the listbox and LB_FINDSTRINGEXACT calls before adding can
be sufficiant though.
I take the approach that potential problems should be corrected
as close to their generation as possible. This prevents potential
errors from creeping in on me.
In the Listboxes which I am using in my programs for File and
Field selections, I check for duplicates immediately an entry occurs,
or as soon as the information becomes available to my program.
I don't permit errors to occur that the user can see if it is
possible to prevent it. I use one array to hold my data items. I use
another array of indexes which corresponds to which data I want to
show in my Listboxes. That permits me to more easily allow the user
to select and re-order listbox items. I never allow the sorting of
strings by the list box itself.
I just saw Borje's posting. Different techniques for different
programmers. There is always another way to skin your Felis domesticus.
I suggest using Sendmessage with LB_FINDSTRINGEXACT to see if the
file already has been added. Fast enough for most operations.
Remember to set indexStart to -1 for checking all items in the list.
(I created a nice bug for a client via this once, by setting it to
zero, so first item never was checked..
This way, you shouldn't even need any arrays - just check if the file
is in the list and add it if not. Use the listbox as "visual array",
so to speak..
Lets try another approach....
(It's ListBox not ListView by the way)
My files are opened and put into the ListBox, and I don't really care what's in the ARRAY of files until the COMPILE button is pressed on the application.
That being said, would it be easier to just put the files into the Listbox, then if MORE are added do a scan of the Listbox for a duplicate file?
I don't want duplicate files being displayed, and I can read the data into the array when COMPILE is pressed, from the ListBox..
Hmmmmm just style at this point, what are your thoughts on this?
Is it easier to maintain the array and not worry about the Listbox or better to maintain the ListBox for viewability purposes (So dupes aren't shown in the box)??
The multiple file select "Open file dialog" works great now! (Thanks!)
BUt now i have another issue.
I'm putting all of the files into a ListView and that works great but I want to determine if a file has already been added.
That piece of the code broke when I made it open multiple files:
It basically states that if you only open one file, it now determines that file is added whether it is or is not.
And multiple files? It doesn't even check, or does not return anythign if the multiple file is there.
Would there be a better way to do an Array Scan with the Listview? Since it is disaplying the actual files that were opened?
Code:
g_Result = MyOpenFileDialog(ByVal hDLg,_
ByVal Caption,_
FileSpec,_
g_CurrWorkingDir,_
ByVal Filter,_
ByVal DefExtension,_
lStyle)
lResult = Tally(FileSpec,Chr$(0))
If lResult <> 0 Then 'Parse out the multiple files
CurrentDir = Parse$(FileSpec,Chr$(0),1)
FileSpec = Right$(FileSpec,Len(FileSpec) - Instr(FileSpec,Chr$(0))) 'REMOVE the directory
If IsFalse g_FileIndex Then g_FileIndex = 1 'Prevent GPF if at zero
For lLoop = g_FileIndex To lResult
g_Files(lLoop) = CurrentDir & "\" & Parse$(FileSpec,Chr$(0),lLoop)
ListBox Add hDlg, %IDLISTBOX1, g_Files(lLoop)
g_FileIndex = lLoop 'Keep index up to date
Next
Else 'Add the single file but First make sure it's not in the list already
Incr g_FileIndex
g_Files(g_FileIndex) = FileSpec
ListBox Add hDlg, %IDLISTBOX1, g_Files(g_FileIndex)
End If
Array Scan g_Files(), Collate Ucase, = FileSpec, To DuplicateCheck
If DuplicateCheck Then
MsgBox "The file " & g_Files(DuplicateCheck) & " is already added", %MB_ICONINFORMATION,g_szCCS
Exit Function
End If
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Leave a comment: