Results 1 to 6 of 6

Thread: [RESOLVED] Custom Functions...

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Posts
    98

    Resolved [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:
    1. Private Function getGeneralFontData(intSectionIndex As Integer, intSizePosition As Integer) as StdFont
    2.  
    3. Dim sFnt As New StdFont
    4. sFnt.Size = garrChequePrinterCfg(intSectionIndex, intSizePosition) * 2
    5. sFnt.Name = garrChequePrinterCfg(intSectionIndex, intSizePosition + 1)
    6. If garrChequePrinterCfg(intSectionIndex, intSizePosition + 2) = "Yes" Then
    7.     sFnt.Bold = True
    8. Else
    9.     sFnt.Bold = False
    10. End If
    11. 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?

  2. #2
    New Member
    Join Date
    Feb 2007
    Location
    Greenville, SC
    Posts
    13

    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.

  3. #3
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: Custom Functions...

    getGeneralFontData returns n object. It should be:
    VB Code:
    1. Set getGeneralFontData = sFnt
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Posts
    98

    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?

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Posts
    98

    Re: Custom Functions...

    Please note that every time *other than* the first time, the function seems to be behave properly.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Posts
    98

    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
  •  



Click Here to Expand Forum to Full Width