Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

get directory name from a path using split

Posted on 2014-09-25
6
Medium Priority
?
99 Views
Last Modified: 2014-09-25
I am trying to get the full path to a directory based on a combo box selection
typical file path in array:
C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Williams 1247 RiverBend rd\Fencing Bids

Private Sub Command3_Click()
Dim FileName As String
If cboBids.ListIndex <> -1 Then
FileName = GetPathToCboItem(cboBids.Text)
End If
I keep getting a type mismatch
Function GetPathToCboItem(cboName As String) As String
Dim i As Integer
Dim strParts() As String
For i = LBound(mArrProjects) To UBound(mArrProjects)
    strParts = Split(mArrProjects(i), "\")
    If UBound(strParts) = cboName Then ' [b]type mismatch here[/b]
      GetPathToCboItem = mArrProjects(i)
      Exit Function
    End If
 Next
End Function

Open in new window

what is wrong ?
0
Comment
Question by:isnoend2001
  • 4
  • 2
6 Comments
 
LVL 49

Expert Comment

by:Martin Liss
ID: 40344468
Ubound returns the number of items in the array -1. You want to do something like
If strParts(i) = cboName then
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 40344471
Is C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Williams 1247 RiverBend rd what you want to get?
0
 
LVL 49

Accepted Solution

by:
Martin Liss earned 2000 total points
ID: 40344480
Wait... do this.

 If strParts(UBound(strParts)) = cboName Then
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Closing Comment

by:isnoend2001
ID: 40344502
Thanks Martin Lliss that fixes the problem
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 40344630
You're welcome. Do you understand why it works?
0
 

Author Comment

by:isnoend2001
ID: 40345335
Thanks not sure you changed
 If UBound(strParts) = cboName Then ' type mismatch here
to
   If strParts(UBound(strParts)) = cboName Then
and that fixed the issue
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

782 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question