Reputation: 0 Apprentice
- New Members
- Active Posts:
- 5 (0.01 per day)
- 22-February 13
- Profile Views:
- Last Active:
- Feb 24 2013 10:38 PM
- Dream Kudos:
Posts I've Made
Posted 24 Feb 2013Thanks for the replies. At first glance it appears you understood what I was trying to do and also appears to be something that will work. This module is doing the heavy lifting and so it was easier to describe what I was trying than to confuse this with the actual code but after obscuring a few items for proprietary reasons here it is before I make mods per your suggestions. Its part of an automation server application so it has some cryptic elements but you should be able to see the gist of it. I am self taught in VB.net and started about 6 months ago so I have some gaping holes in my knowledge but learning fast so please be nice as I break easily
I have multiple pages to display and therefore have page controls. I am adding the ability to shuffle position of the pics based upon user preference so I have to track the position and order they load into the pictureBox controls. I am still carving out some of the functionality but needed to clear this hurdle of looping controls before I continue. I had previously written this in LISP years ago but needed to completely re-write in VB.net which is my first oop language (that is code for "start learning another language!").
Private Sub IlocPageLoader() ' create the page array ' get all the picture reg keys - newly added plus the existing Dim strPreviousCategory As String = CStr((Registry.GetValue("HKEY_CURRENT_USER\Software\MySoftware\LibMgr\Common\Library", "PreviousCategory", ""))) Dim strPreviousLibrary As String = CStr((Registry.GetValue("HKEY_CURRENT_USER\Software\MySoftware\LibMgr\Common\Library", "PreviousLibrary", ""))) Dim keyLibrary As RegistryKey = _ Registry.CurrentUser.OpenSubKey _ ("Software\MySoftwareLLC\LibMgr\Category\" & strPreviousCategory & "\" & strPreviousLibrary) ' create a list of sysmbols Dim astrSymbols As Array = keyLibrary.GetSubKeyNames() Dim intSymbolCount As Integer = astrSymbols.Length Dim intPageSize As Integer ' get the display configuration Select Case CStr(Registry.GetValue("HKEY_CURRENT_USER\Software\MySoftware\LibMgr\Common\Library", "DefaultDisplay", "")) Case "4x6" intPageSize = 24 Case "2x3" intPageSize = 6 Case "1x1" intPageSize = 1 End Select ' calculate qty of pages needed Dim intPageQty As Integer = CInt(Fix(Math.Ceiling(intSymbolCount / intPageSize))) Dim decPreviousPage = (CDec(Registry.GetValue("HKEY_CURRENT_USER\Software\MySoftware\LibMgr\Common\Library", "PreviousPage", ""))) ' set the spin page control spnPages.Maximum = CDec(intPageQty) spnPages.Value = decPreviousPage ' display the page of previews ' create a counter for the image tile positions Dim intTilePosition As Integer = intPageSize For intCounter As Integer = CInt((intPageSize * decPreviousPage)) To CInt(((intPageSize * decPreviousPage) - intPageSize) + 1) Step -1 ' establish the pic control name starting at intPageSize and counting down to 1 'Dim TileName As New Control = Me.Controls.Item(intTilePosition) ' paint background of pic control to erase any previous image displayed ' step thru each symbol and display the preview if the position matches For Each StrSymbol As String In astrSymbols Dim strSymbolKey As String = _ ("HKEY_CURRENT_USER\Software\MySoftware\LibMgr\Category\" & strPreviousCategory & "\" & strPreviousLibrary & "\" & StrSymbol) If CInt(Registry.GetValue(strSymbolKey, "Position", "")) = intCounter Then Dim strFileName As String = CStr(Registry.GetValue(strSymbolKey, "Location", "")) Try Dim doc As Appserv.Document = Appserv.Application.DocumentManager.MdiActiveDocument Using docLock As Appserv.DocumentLock = doc.LockDocument ' load the picture into the picture box ' extract the thumbnail to display in the picturebox Dim db As New DatabaseServices.Database(False, False) db.ReadDwgFile(strFileName, DatabaseServices.FileOpenMode.OpenForReadAndReadShare, True, Nothing) Dim bm As Drawing.Bitmap = db.ThumbnailBitmap 'bm now contains a valid thumbnail bitmap. ' load the picture into the picture box 'Me.Controls.Item(intTilePosition).image = bm picFilePreviewX.Image = bm End Using Catch objException As System.OutOfMemoryException MessageBox.Show("The file attempting to be displayed is not an image file.", "Invalid File", MessageBoxButtons.OK) End Try End If Next StrSymbol ' advance to the previous image tile position working backwards intTilePosition = intTilePosition - 1 Next intCounter ' housekeeping keyLibrary.Close() End Sub
Posted 22 Feb 2013ps - I agree about always declaring the data type but was not accepting anything other than object... I added the string type at the end of all this and now it likes it. I think if I were to try to use the string it would then throw the cast exception.. another mystery dealing with the "collection" type that will need to wait until I am allot more accomplished to resolve... thanks again.
' if anything was selected from first list then add each selection to the other list If lstBrowseFolders.SelectedItems.Count > 0 Then For Each strJobFolder As String In lstBrowseFolders.SelectedItems lstArchiveFolders.Items.Add(strJobFolder) Next ' compare modified list back to first list and remove the duplicates from first list For Each strJobFolder As String In lstArchiveFolders.Items lstBrowseFolders.Items.Remove(strJobFolder) Next
Posted 22 Feb 2013You nailed it... thanks. I tried many variations of your solution to no avail and felt it was more important to understand the "why" than the actual "how" after seeing your solution. Any use of the list (such as "for each" ) will force a change in the controls at time of removal resulting in a fail. Any use of each item (as opposed to its index) forces a mismatch in casting resulting in a fail. Your approach compares "whatever" at index "x" with "whatever" at index "y" so casting and using the list to loop thru never come into play. "Strict" forced me to use "is" instead of "=" but that was fine. After I thought about my two lists I realized "I never want an item to appear on both lists..... therefore..." I can use the target list receiving the items to compare back and remove any duplicates I had just created. Lots of wasted resources on a long list (for example adding 2 new items to an existing list of 200) but no more than index stepping thru a long list.
Here is what I ended up with - let me know if you see any landmines:
If lstBrowseFolders.SelectedItems.Count > 0 Then For Each strJobFolder In lstBrowseFolders.SelectedItems lstArchiveFolders.Items.Add(strJobFolder) Next For Each strJobFolder In lstArchiveFolders.Items lstBrowseFolders.Items.Remove(strJobFolder) Next 'For a As Int32 = lstBrowseFolders.SelectedItems.Count - 1 To 0 Step -1 ' For i As Int32 = lstBrowseFolders.Items.Count - 1 To 0 Step -1 ' '-- compare the value of the select item to any given item in the list. ' If lstBrowseFolders.SelectedItems(a) Is lstBrowseFolders.Items(i) Then ' '-- remove the item by the index we found ' lstBrowseFolders.Items.RemoveAt(i) ' '-- exit the inner for loop ' Exit For ' End If ' Next 'Next End If
- Member Title:
- New D.I.C Head
- Age Unknown
- Birthday Unknown
spigniff hasn't added any friends yet.