|
-
Jul 27th, 2005, 07:35 AM
#1
Thread Starter
Junior Member
[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:
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
-
Jul 27th, 2005, 07:42 AM
#2
Re: Forms and functions
Is this Excel or Access?? And What version?
VB Code:
'Code after the return from the dialog
Dim arrFile(1 To 2) As String
arrFile(1) = Mid(FileName,1,InStrRev(FileName,"\")
arrFile(2) = Mid(FileName,InStrRev(FileName,"\")
Danny
Never Think Impossible
If you find my answer helpful then please add to my reputation
-
Jul 27th, 2005, 11:53 AM
#3
Thread Starter
Junior Member
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?
-
Jul 27th, 2005, 12:04 PM
#4
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:
Public Function ListSheets() As String
Dim sSheets As String
Dim i As Integer
For i = 1 To ActiveWorkbook.Sheets.Count
sSheets = sSheets & ActiveWorkbook.Sheets(i).Name & ";"
Next
ListSheets = Left$(sSheets, Len(sSheets) - 1)
End Function
Private Sub UserForm_Initialize()
Dim ar() As String
Dim i As Integer
ar = Split(ThisWorkbook.ListSheets, ";")
For i = 0 To UBound(ar)
ComboBox1.AddItem ar(i)
Next
Erase ar
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jul 27th, 2005, 01:25 PM
#5
Thread Starter
Junior Member
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.
-
Jul 27th, 2005, 01:34 PM
#6
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jul 27th, 2005, 02:06 PM
#7
Thread Starter
Junior Member
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
-
Jul 27th, 2005, 02:10 PM
#8
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|