Solved

get directory name from a path using split

Posted on 2014-09-25
6
97 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 48

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 48

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 48

Accepted Solution

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

 If strParts(UBound(strParts)) = cboName Then
0
Independent Software Vendors: 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!

 

Author Closing Comment

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

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Suggested Courses
Course of the Month7 days, 6 hours left to enroll

623 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