Results 1 to 8 of 8

Thread: [RESOLVED] Forms and functions

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2005
    Posts
    20

    Resolved [RESOLVED] Forms and functions

    Hi all

    I'm afraid I know the answer to this already, but...

    I have a user form that asks for a file to open. When the user clicks the browse button, a function creates a browse window and allows the user to select a file. The function returns the file name and path to the form (i.e. C:\DooDoo\stinky.dog). When the user clicks the "Open" button this file path is passed along so the program can do all sorts of inappropriate things.

    What I was wondering, is it possible to get a function to return multiple values? Ideally, I would have two variables, one for the path (C:\DooDoo) and one for the file name (stinky.dog).
    When you tell me that this isn't possible, how then do I split the two? I can't foresee using some string manipulations as the length of the path and file name will vary. Unless I did some sort of backwards string counting that split the string at the backslash before the file name.
    Oh bother.

    Is it possible to make a function hold an array?

    Oh yeah, I'm using a function because it was the only way I saw to get the values back to the form, other than public variables.
    !! I just has an epiphany... Perhaps I can set the two string values to the forms variables inside the function.. something like
    VB Code:
    1. frmPickaFile.strFilePath = strPathfromFunction
    I'll go try it out. While I'm doing that, anyone else have a suggestion??

    Super thanks

    Mike
    Last edited by GIS_Mike; Jul 27th, 2005 at 07:36 AM. Reason: I can't spell

  2. #2
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: Forms and functions

    Is this Excel or Access?? And What version?

    VB Code:
    1. 'Code after the return from the dialog
    2.   Dim arrFile(1 To 2) As String
    3.   arrFile(1) = Mid(FileName,1,InStrRev(FileName,"\")
    4.   arrFile(2) = Mid(FileName,InStrRev(FileName,"\")
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2005
    Posts
    20

    Re: Forms and functions

    It's neither Excel nor Access.. It's ArcGIS, which I have a feeling no one else around here uses. Preventing me from bothering too deep into specifics.

    The question is more of a general VBA/VB6 syntax type question. Is it possible to return multiple values from a single function call?

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

    Re: Forms and functions

    Sure it is! (I also have ArcView GIS and MapObjects but I havent used it in years. So its not currently on my system )

    Here is an example I just wrote a minute ago that returns a semicolon delimited string. Then I parse the string into an array. You could probably do the same. The example is in Excel VBA.

    VB Code:
    1. Public Function ListSheets() As String
    2.     Dim sSheets As String
    3.     Dim i As Integer
    4.     For i = 1 To ActiveWorkbook.Sheets.Count
    5.         sSheets = sSheets & ActiveWorkbook.Sheets(i).Name & ";"
    6.     Next
    7.     ListSheets = Left$(sSheets, Len(sSheets) - 1)
    8. End Function
    9.  
    10. Private Sub UserForm_Initialize()
    11.     Dim ar() As String
    12.     Dim i As Integer
    13.    
    14.     ar = Split(ThisWorkbook.ListSheets, ";")
    15.     For i = 0 To UBound(ar)
    16.         ComboBox1.AddItem ar(i)
    17.     Next
    18.     Erase ar
    19. 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

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jul 2005
    Posts
    20

    Re: Forms and functions

    Oh man I'm telling you, ArcGIS is where it's at!

    Ok, now I may be reading your code incorrectly but it seems to me that you made a nifty little work around that almost embeds a function call into an array.
    That's sexy. Kind of Python-esque. I like.

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

    Re: Forms and functions

    Really, Thanks! I havent see Python code before. There is a way to go direct and pass an array argument but I usually use this type of method. If you want to do it direct I can search for some code thats on the forums that I know of that will also work.
    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

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Jul 2005
    Posts
    20

    Re: Forms and functions

    If you have a free moment, I'd appreciate it. I think what you've shown me would suffice but I'm always interested to learn more.

    Mike

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

    Re: Forms and functions

    Ok, here is a good example. Note the limitations in doing it this way.

    http://www.vbforums.com/showpost.php...51&postcount=4
    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

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