Solved

get directory name from a path using split

Posted on 2014-09-25
6
95 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 47

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 47

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 47

Accepted Solution

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

 If strParts(UBound(strParts)) = cboName Then
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

Author Closing Comment

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

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

734 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