S
Stuart
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
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