PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Declaring the path-VBForums
Results 1 to 10 of 10

Thread: Declaring the path

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2005
    Posts
    5

    Declaring the path

    I have the following situation:

    Private Sub img1_Click()
    frmPicture.Show
    frmPicture.imgPicture.Picture = LoadPicture(Path+"1.jpg")
    End Sub

    Private Sub img2_Click()
    frmPicture.Show
    frmPicture.imgPicture.Picture = LoadPicture(Path+"2.jpg")
    End Sub
    ......
    Private Sub img125_Click()
    frmPicture.Show
    frmPicture.imgPicture.Picture = LoadPicture(Path+"125.jpg")
    End Sub

    Private Sub img126_Click()
    frmPicture.Show
    frmPicture.imgPicture.Picture = LoadPicture(Path+"126.jpg")
    End Sub

    My question is - where do I declare the Path? I don't want to do it after each Private Sub, cos it would take me a long time. So, I'm wondering if there's another place, where I could do it just once?

    Thank You
    Newbie

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

    Re: Declaring the path

    If you declare it at the top of the form in the declarations section above any procedures it will be
    modular or common to the entire form and all its procedures.

    VB Code:
    1. Option Explicit
    2.  
    3. Private msPath As String = "C:\MyPathtoMyPictures\"
    4.  
    5. Private Sub img1_Click()
    6.     frmPicture.Show
    7.     frmPicture.imgPicture.Picture = LoadPicture(msPath +"1.jpg")
    8. End Sub
    9.  
    10. Private Sub img2_Click()
    11.     frmPicture.Show
    12.     frmPicture.imgPicture.Picture = LoadPicture(msPath +"2.jpg")
    13. End Sub
    14. ......
    15. Private Sub img125_Click()
    16.     frmPicture.Show
    17.     frmPicture.imgPicture.Picture = LoadPicture(msPath +"125.jpg")
    18. End Sub
    19.  
    20. Private Sub img126_Click()
    21.     frmPicture.Show
    22.     frmPicture.imgPicture.Picture = LoadPicture(msPath +"126.jpg")
    23. End Sub
    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
    Addicted Member
    Join Date
    Aug 2004
    Posts
    176

    Re: Declaring the path

    How about the Form_load?
    Declare path in general, initiate in load.

  4. #4
    Addicted Member
    Join Date
    Aug 2004
    Posts
    176

    Re: Declaring the path

    Sorry Rob, din't see ur reply.

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

    Re: Declaring the path

    You could initialize the variable in the Form_Load event also. It just depends on
    personal preference and if there is code acting on it before the Form_Load event. The
    Form_Initialize event fires first, fyi.

    Edit: I just read your post. If you dim it in the Form_Load event it will only be
    local to that event, not to all procedures in the form.
    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
    New Member
    Join Date
    Feb 2005
    Posts
    5

    Re: Declaring the path

    When I do it like this:

    Option Explicit

    Private msPath As String = "C:\........\"

    I receive the error message "Expected: end of statement", but when I change it to this:

    Option Explicit

    Private msPath As String
    msPath = "C:\........\"

    I receive the following error message: "Invalid outside procedure"

    What's the problem?
    Thanks for your replies

  7. #7
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Declaring the path

    set the value inside of a subroutine. that is a requirement.
    not the declaration. just the assignment.

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

    Re: Declaring the path

    Sorry, I was still in VS.NET mode.

    In VB6 this would be the correct way.

    VB Code:
    1. Option Explicit
    2.  
    3. Private msPath As String
    4.  
    5. Private Sub Form_Load()
    6.     msPath = "C:\MyPathtoMyPictures\"
    7. End Sub
    8.  
    9. Private Sub img1_Click()
    10.     frmPicture.Show
    11.     frmPicture.imgPicture.Picture = LoadPicture(msPath +"1.jpg")
    12. End Sub
    13.  
    14. Private Sub img2_Click()
    15.     frmPicture.Show
    16.     frmPicture.imgPicture.Picture = LoadPicture(msPath +"2.jpg")
    17. End Sub
    18. ......
    19. Private Sub img125_Click()
    20.     frmPicture.Show
    21.     frmPicture.imgPicture.Picture = LoadPicture(msPath +"125.jpg")
    22. End Sub
    23.  
    24. Private Sub img126_Click()
    25.     frmPicture.Show
    26.     frmPicture.imgPicture.Picture = LoadPicture(msPath +"126.jpg")
    27. End Sub
    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

  9. #9

    Thread Starter
    New Member
    Join Date
    Feb 2005
    Posts
    5

    Re: Declaring the path

    I got it. Thank you guys

  10. #10
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,135

    Re: Declaring the path

    As an alternative you may want to define some CONSTs:
    VB Code:
    1. 'in Form's general declaration or in the module
    2. Option Explicit
    3.  
    4. Public CONST JPG_PATH "C:\IMAGES\JPG\"
    5. Public CONST BMP_PATH "C:\IMAGES\BMP\"
    6. Public CONST GIF_PATH "C:\IMAGES\GIF\"
    7.  
    8. 'and so on

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width