Results 1 to 14 of 14

Thread: [RESOLVED] Invalid use of property

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Resolved [RESOLVED] Invalid use of property

    I am wanting to set some text in a label at run-time for:

    bold italic
    bold
    underline
    non bold (regular)
    strike through
    italic

    and i have the following so i can test it and i am getting the error
    Invalid use of property
    this is what i have:
    VB Code:
    1. Private Sub mnuLabelFontStyleBold_Click()
    2.     lblText(m_intControlIndex).Font.[hl]Bold[/hl]
    3. End Sub

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: Invalid use of property

    OK, i found that its a boolean flag of some sort so added = True

    However, when I want to set the text to regular text with the following, its not doing it...
    VB Code:
    1. Private Sub mnuLabelFontStyleRegular_Click()
    2.     lblText(m_intControlIndex).Font.Bold = False
    3. End Sub

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Invalid use of property

    You need to either set the .Bold = False and then enter in text or highlight the text if it already exists and then tggle the .Bold = False.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Invalid use of property

    No, if your wanting to enter in new text then set the .Bold before entering the text. If your just reformatting some existing text then highlight and apply the .Bold = False

    It works exactly like it does in the Word GUI.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: Invalid use of property

    when the label has received a end user caption, they can go into a menu to specify the whole label as a particular format. one of those formats, i am trying to accomplish is Bold + Italic; however, its toggling between either/or, instead of setting it bold + italic or neither. i cannot seem to find anywhere, where you can set both and then toggle between the two. this is what i have so far?
    VB Code:
    1. Private Sub mnuLabelFontStyleBoldItalic_Click()
    2.     With lblText(m_intControlIndex)
    3.         .Font.Bold = Not .Font.Bold
    4.         .Font.Italic = Not .Font.Italic
    5.     End With
    6. End Sub

  7. #7
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Invalid use of property

    The code you showed should work perfectly. Set a breakpoint in the procedure and check that m_intControlIndex actually have the correct value (so it's not 0 which if I understood your previous posts correctly is an invisible control).

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: Invalid use of property

    Quote Originally Posted by Joacim Andersson
    The code you showed should work perfectly. Set a breakpoint in the procedure and check that m_intControlIndex actually have the correct value (so it's not 0 which if I understood your previous posts correctly is an invisible control).
    its showing the right index value. but what it is doing is not turning off bold and italic or turning it on. what its doing is toggling between the top, and then the bottom.

    what i need to do is turn both off at the same time or turn both on at the same time. i dont see anywhere in my msdn where there is a .font.bolditalic so cant set it that way. typical ms though.

  9. #9
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Invalid use of property

    VB Code:
    1. Private Sub mnuLabelFontStyleBoldItalic_Click()
    2.     With lblText(m_intControlIndex)
    3.         .Font.Bold = Not .Font.Bold
    4.         .Font.Italic = [b].Font.Bold [/b]
    5.     End With
    6. End Sub

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: Invalid use of property

    Quote Originally Posted by Joacim Andersson
    VB Code:
    1. Private Sub mnuLabelFontStyleBoldItalic_Click()
    2.     With lblText(m_intControlIndex)
    3.         .Font.Bold = Not .Font.Bold
    4.         .Font.Italic = [b].Font.Bold [/b]
    5.     End With
    6. End Sub
    .font.bold would be referencing the top line?

  11. #11
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Invalid use of property

    Font.Bold is simply a property value of boolean type so it's either True or False. The first line set it to one of these values (toggle) while the second makes sure that Font.Italic is set to the same value. So it either turns both properties to True or to both False.

    But maybe I'm missing something and completly misunderstood what you are trying to do.

  12. #12

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: Invalid use of property

    Quote Originally Posted by Joacim Andersson
    Font.Bold is simply a property value of boolean type so it's either True or False. The first line set it to one of these values (toggle) while the second makes sure that Font.Italic is set to the same value. So it either turns both properties to True or to both False.

    But maybe I'm missing something and completly misunderstood what you are trying to do.
    no, you understood me because when i tried your alteration, it worked like a charm. was just trying to understand what you were doing. its not so good to take someones code/alterations and not understand them, so was just making sure i understood. i like to understand the logic so if i had to do it again or in another project in the future, i would know what i was doing and could understand what was going on. thanks for the help JA.

  13. #13
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: [RESOLVED] Invalid use of property

    You're welcome. It's great that you're always striving to understand the code you're using. To explain it in another way, the code basically does the same thing as this code does:
    VB Code:
    1. Dim str As String, txt As String
    2. str = "Hello World"
    3. txt = str
    The second variable is simply assigned the same value as the first contains. The only difference is that in your case it's not variables but properties you assign values to.

  14. #14

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: [RESOLVED] Invalid use of property

    Quote Originally Posted by Joacim Andersson
    You're welcome. It's great that you're always striving to understand the code you're using. To explain it in another way, the code basically does the same thing as this code does:
    VB Code:
    1. Dim str As String, txt As String
    2. str = "Hello World"
    3. txt = str
    The second variable is simply assigned the same value as the first contains. The only difference is that in your case it's not variables but properties you assign values to.
    always better to understand the code than use code you dont understand.

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