|
-
Feb 16th, 2007, 10:06 AM
#1
Thread Starter
Lively Member
[RESOLVED] Custom Functions...
Hey all,
So, I've got this function that is supposed to just set pass a StdFont variable, after setting it's arguments from data in some arrays.
VB Code:
Private Function getGeneralFontData(intSectionIndex As Integer, intSizePosition As Integer) as StdFont
Dim sFnt As New StdFont
sFnt.Size = garrChequePrinterCfg(intSectionIndex, intSizePosition) * 2
sFnt.Name = garrChequePrinterCfg(intSectionIndex, intSizePosition + 1)
If garrChequePrinterCfg(intSectionIndex, intSizePosition + 2) = "Yes" Then
sFnt.Bold = True
Else
sFnt.Bold = False
End If
getGeneralFontData = sFnt
However, when I attempt to execute this funtion, I get the following error:
Run-time error '91':
Object variable or With block not set
(this is making a reference to the line getGeneralFontData = sFnt)
I thought that I set getGeneralFontData when I declared the function? When I remover the "as StdFont" part, the function actually seems to work, except for some reason the first time the function executes the values are passed incorrectly.
Thoughts?
-
Feb 16th, 2007, 10:17 AM
#2
New Member
Re: Custom Functions...
You need to do the following on the last line of the Function:
Set getGeneralFontData = sFnt
I think that the reason why when you remove the StdFont decalaration that the function works is that the object is being coerced to a Variant and a Variant assignment does not require the use of the Set Keyword.
-
Feb 16th, 2007, 10:20 AM
#3
Re: Custom Functions...
getGeneralFontData returns n object. It should be:
VB Code:
Set getGeneralFontData = sFnt
-
Feb 16th, 2007, 10:30 AM
#4
Thread Starter
Lively Member
Re: Custom Functions...
Alright, that's fixed my error issue. However, the first time the function is called, it doesn't preform properly. I put some stops into the code, and the arguments are passed properly, and the first font values are pulled properly from the arrays. When I check the values of sFnt.Name, sFnt.Size, and sFnt.Bold just before the Set getGeneralFontData = sFnt line is run they are:
sFnt.Name = Arial
sFnt.Size = 24
sFnt.Bold = True
Now, the Set getGeneralFontData = sFnt line is run, and I go back to where the function was originally called using the line:
sFnt = getGeneralFontData(j, 3)
Now I checked the values of sFnt.Name, sFnt.Size, and sFnt.Bold again and they are:
sFnt.Name = Arial
sFnt.Size = 8.5
sFnt.Bold = False
How is this possible?
-
Feb 16th, 2007, 10:33 AM
#5
Thread Starter
Lively Member
Re: Custom Functions...
Please note that every time *other than* the first time, the function seems to be behave properly.
-
Feb 16th, 2007, 10:34 AM
#6
Thread Starter
Lively Member
Re: Custom Functions...
Oh, I think I've fixed it.
I changed:
sFnt = getGeneralFontData(j, 3)
to: Set sFnt = getGeneralFontData(j, 3)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|