Results 1 to 4 of 4

Thread: [RESOLVED] How to call the function correctly ?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2005
    Posts
    570

    Resolved [RESOLVED] How to call the function correctly ?

    Hi,

    How to call the function properly? The below is the code:

    VB Code:
    1. Public Sub Clear_Text()
    2. txtCustomerName = ""
    3. txtSalesPerson = ""
    4. txtPoBox = ""
    5. End Sub

    1) Clear_Text
    2) Call Clear_Text

    Both are working fine. But need to know which is the proper way to call?

    Seema.

  2. #2
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,713

    Re: How to call the function correctly ?

    Both are fine to use. Call is the legacy syntax from BASIC language.
    You procedure is a sub and not a function since it doesnt return a value or object.
    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

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,501

    Re: How to call the function correctly ?

    The only issue is when you have parameters, silly example:
    VB Code:
    1. Public Sub Set_Text(CustomerText as String, SalesText as String)
    2. txtCustomerName.Text = CustomerText
    3. txtSalesPerson.Text = SalesText
    4. End Sub
    You can call the sub like this:
    VB Code:
    1. Set_Text "a customer", "a salesperson"
    2. Call Set_Text ("a customer", "a salesperson")
    but not like this:
    VB Code:
    1. Set_Text ("a customer", "a salesperson")

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2005
    Posts
    570

    Re: How to call the function correctly ?

    Quote Originally Posted by si_the_geek
    The only issue is when you have parameters, silly example:
    VB Code:
    1. Public Sub Set_Text(CustomerText as String, SalesText as String)
    2. txtCustomerName.Text = CustomerText
    3. txtSalesPerson.Text = SalesText
    4. End Sub
    You can call the sub like this:
    VB Code:
    1. Set_Text "a customer", "a salesperson"
    2. Call Set_Text ("a customer", "a salesperson")
    but not like this:
    VB Code:
    1. Set_Text ("a customer", "a salesperson")
    Thanks a lot for the help.

    Seema.

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