View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson[_3_] Dave Peterson[_3_] is offline
external usenet poster
 
Posts: 2,824
Default Proper Programming

There are technical reasons for dimming your variables as the correct type.
Your code will execute faster and you'll be reserving less space for them.

In xl2002, there's a "Using Data Types Efficiently" in VBA's help.

But the overwhelming reason I declare variables as the correct type is to get
VBA's intellisense to pop up.

if you use
Dim Wks as Worksheet
then as soon as you type the dot in:
Wks.
You'll see VBA start to help with a list of all the things that come next.

You don't get that with
dim Wks
'cause VBA has no idea what you're working with.


Stuart wrote:

Is the following the corect way to use functions? The following works fine,
however When I look at what the experts do they seem to embellish there code
with remarks like "as Double" "as Integer" "as Variant" and wonder if i
should embellish mine in this way, but, I don't really know what it all
means nor do I see the point in it as code seems to run quite happily
without it?

Anyway, here is some code that I have wrote, it works fine and does the job,
but how should it of been done.

PS. I do really appreciate the help that is freely given by others on this
group, it is invaluable, and take this opportunity to wish you all a very
happy xmas!

Sub KeepImage()
Dim lB1, lB2
lB1 = GetList1Info()
lB2 = GetList2Info()
If lB1 = "" Or lB2 = "" Then Exit Sub
ActiveSheet.Unprotect
With ActiveCell
.Offset(0, 2) = "Yes"
.Offset(0, 3) = lB1
.Offset(0, 4) = lB2
End With
end sub

Private Function GetList1Info()
Dim lBox1 As ListBox
Dim temp, i
Set lBox1 = Sheets("jpegs").ListBoxes("List Box 1")
With lBox1
For i = 1 To .ListCount
If .Selected(i) Then
temp = .List(i)
Exit For
End If
Next i
End With
GetList1Info = temp
End Function

Private Function GetList2Info()
Dim lBox2 As ListBox
Dim temp, i
Set lBox2 = Sheets("jpegs").ListBoxes("List Box 2")
temp = ""
With lBox2
For i = 1 To .ListCount
If .Selected(i) Then
temp = temp & .List(i) & ";"
End If
Next i
End With
GetList2Info = temp
End Function


--

Dave Peterson