Can't understand use of variable in this code

F

Fred Boer

Hello:

I've been working with AppTitle and AppIcon and RefreshTitleBar. I've
cribbed the code below from the Access Help files. Could someone please
explain to me the purpose of the "intX" variable in the procedure? It isn't
clear to me why the variable is needed...

Thanks!
Fred Boer

Sub cmdAddProp_Click()
Dim intX As Integer
Const DB_Text As Long = 10
intX = AddAppProperty("AppTitle", DB_Text, "My Custom Application")
intX = AddAppProperty("AppIcon", DB_Text, "C:\Windows\Cars.bmp")
CurrentDb.Properties("UseAppIconForFrmRpt") = 1
Application.RefreshTitleBar
End Sub

Function AddAppProperty(strName As String, _
varType As Variant, varValue As Variant) As Integer
Dim dbs As Object, prp As Variant
Const conPropNotFoundError = 3270

Set dbs = CurrentDb
On Error GoTo AddProp_Err
dbs.Properties(strName) = varValue
AddAppProperty = True

AddProp_Bye:
Exit Function

AddProp_Err:
If Err = conPropNotFoundError Then
Set prp = dbs.CreateProperty(strName, varType, varValue)
dbs.Properties.Append prp
Resume
Else
AddAppProperty = False
Resume AddProp_Bye
End If
End Function
 
G

Graham R Seach

Fred,

I'd have thought you could work that one out.

IntX is the Bolean return value from AddAppProperty(). In
cmdAddProp_Click(), it's not used, but you could take some action based on
whether AddAppProperty() succeeded or failed.

Regards,
Graham R Seach
Microsoft Access MVP
Canberra, Australia
 
F

Fred Boer

Dear Graham:
I'd have thought you could work that one out.

Thanks for the vote of confidence, Graham! ;) *
IntX is the Bolean return value from AddAppProperty(). In
cmdAddProp_Click(), it's not used, but you could take some action based on
whether AddAppProperty() succeeded or failed.

Actually, I *did* realize that the function would return a value (I saw that
when I ran the function in the immediate window...), and that this value
would be stored in the variable. What I didn't see was that the variable was
necessary (as you say, it isn't), and I hadn't thought of a use for such a
variable (which you've now shown me). Thanks very much!

Fred

* Or did you think I was being a bit lazy? <g>
 
D

Douglas J. Steele

Fred Boer said:
Dear Graham:


Thanks for the vote of confidence, Graham! ;) *


Actually, I *did* realize that the function would return a value (I saw
that when I ran the function in the immediate window...), and that this
value would be stored in the variable. What I didn't see was that the
variable was necessary (as you say, it isn't), and I hadn't thought of a
use for such a variable (which you've now shown me). Thanks very much!

Note that even if it's a function, if you're absolutely not going to look at
the return value, you can always use the Call syntax:

Call AddAppProperty("AppTitle", DB_Text, "My Custom Application")
Call AddAppProperty("AppIcon", DB_Text, "C:\Windows\Cars.bmp")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top