Solved

get directory name from a path using split

Posted on 2014-09-25
6
89 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 46

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 46

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 46

Accepted Solution

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

 If strParts(UBound(strParts)) = cboName Then
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Closing Comment

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

895 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now