AfraLisp Blog

The AutoLisp/Visual Lisp/VBA Resource Website

AfraLisp Blog

Home Newsletter Utter Rubbish Coding Tips AutoCAD Tips Contact Downloads WAUN

From ACAD Newsletter Dated October 27th 1999. (http://www.vbdesign.net)
(And believe it or not, it was "me" that asked Randall the question!!!)

Q. How's about project that would display a set of AutoCad slides, similar to the image dialogue that AutoCAD uses. The difference being, that the application would allow the user to select a library directory (where the slides and blocks are kept) and would create the image dialogue "on the fly". This way, the image dialogue would not have to be hardcoded as it is in the AutoCAD menu. Thinking about it, maybe we should use WMF files instead of slides

A. Of course we could use the slide ocx to display a complete library of slides, but it is a shareware tool. So Kenny went with using Window Metafiles for the images. The problem is, VBA does not allow for a dynamic array of controls (in VB 5 and up this can be done), so we could create the image controls one at a time (see my dynamic control code from this month), but this becomes very complex if you have more than say, 10 images in a directory. You need to expand the form to fit all of the images, or provide a button to switch to the next set of images...too much trouble when we can just use StdPictures. What is an stdPicture? A picture held in memory! We can even make these a dynamic array! Well, that solves half of our problem, but how do we get enough image controls onto the form to display all of the pictures in any given directory? the answer is, we don't! Time to use a Tab Strip! This is the first part of this project, the second half will depend on what Kenny (and the YOU) want to do with it, should we set it so that the user can click an image and have the block inserted? Perhaps allow multiple selections so that many blocks can be inserted as many times as needed? INPUT please!!!

One last note, Take a look at what Ralph worked up prior to building the project!!

For the form:
1 tab strip named tabImages
9 image controls (all with default names) placed in the client area of the tab strip
1 command button (default name)
1 text box (default name)

'Begin code Block
Option Explicit
Option Base 1
Private stdImages() As StdPicture
Private colFiles As Collection

Private Sub CommandButton1_Click()
If TextBox1.Text > "" Then
If Dir(TextBox1.Text) > "" Then
tabImages.Enabled = True
LoadImages TextBox1.Text
CommandButton1.Enabled = False
Else
MsgBox "The path provided was not valid", vbOKCancel, "Llama Central"
End If
Else
MsgBox "You must provide a valid path", vbOKCancel, "Llama Central"
End If
End Sub

Private Sub tabImages_Change()
Dim ctlcontrol As Control
For Each ctlcontrol In UserForm1.Controls
If TypeOf ctlcontrol Is Image Then
ctlcontrol.Picture = Nothing
End If
Next
SetImages
End Sub

Private Sub TextBox1_Change()
CommandButton1.Enabled = True
End Sub

Private Sub UserForm_Click()

End Sub

Private Sub LoadImages(strPath As String)
Dim strFile As String
Dim intCnt As Integer
Static intTab As Integer
Set colFiles = New Collection
If Right(strPath, 1) <> "\" Then strPath = strPath & "\"
strFile = Dir(strPath & "\*.wmf")
Do While strFile > ""
colFiles.Add strFile
strFile = Dir
Loop
intCnt = colFiles.Count
ReDim stdImages(intCnt)
For intCnt = LBound(stdImages) To UBound(stdImages)
Set stdImages(intCnt) = LoadPicture(strPath & colFiles(intCnt))
If intCnt > 8 Then
If intCnt Mod 9 = 1 Then
tabImages.Tabs.Add "Tab" & intTab, intCnt & " - " & intCnt + 9
intTab = intTab + 1
End If
End If
Next
SetImages
End Sub

Private Sub SetImages()
Dim intIcnt As Integer
Dim intTabNum As Integer
intTabNum = tabImages.SelectedItem.Index * 9
intIcnt = 1 + intTabNum
Image1.Picture = stdImages(intIcnt)
If intIcnt = UBound(stdImages) Then Exit Sub
intIcnt = intIcnt + 1
Image2.Picture = stdImages(intIcnt)
If intIcnt = UBound(stdImages) Then Exit Sub
intIcnt = intIcnt + 1
Image3.Picture = stdImages(intIcnt)
If intIcnt = UBound(stdImages) Then Exit Sub
intIcnt = intIcnt + 1
Image4.Picture = stdImages(intIcnt)
If intIcnt = UBound(stdImages) Then Exit Sub
intIcnt = intIcnt + 1
Image5.Picture = stdImages(intIcnt)
If intIcnt = UBound(stdImages) Then Exit Sub
intIcnt = intIcnt + 1
Image6.Picture = stdImages(intIcnt)
If intIcnt = UBound(stdImages) Then Exit Sub
intIcnt = intIcnt + 1
Image7.Picture = stdImages(intIcnt)
If intIcnt = UBound(stdImages) Then Exit Sub
intIcnt = intIcnt + 1
Image8.Picture = stdImages(intIcnt)
If intIcnt = UBound(stdImages) Then Exit Sub
intIcnt = intIcnt + 1
Image9.Picture = stdImages(intIcnt)
intIcnt = intIcnt + 1
End Sub

Private Sub UserForm_Initialize()
tabImages.Tabs.Item(0).Caption = "1 - 9"
tabImages.Tabs.Remove (1)
tabImages.Enabled = False
CommandButton1.Caption = "Load Images"
End Sub
'End Code Block

The AutoLisp/Visual Lisp/VBA Resource Website

Copyright 1999-Perpetuity by AfraLisp

All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage

The AutoLisp/Visual Lisp/VBA Resource Website