Solved

Converting Dir's to \..\..\

Posted on 1998-10-03
3
174 Views
Last Modified: 2010-04-30
If Name = "a111a111a111" Then Exit Sub

Hi,
I would like to do the following,
(real sorry for the points)

How do you convert a string with a file path from this C:\Canada\ONT\Ottawa
to this
..\..\
assuming I wanted to add a Link to Canada while the inital HTML file was saved in Ottawa.

Again, sorry for the points.
0
Comment
Question by:idcanada
[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
  • 2
3 Comments
 

Accepted Solution

by:
jfayling earned 30 total points
ID: 1437909
I use a function that I wrote that will split up a a string by a userdefined character.


I would do something like this

dim total as long
dim tmpArray as variant

  total=parsestring(tmpFilePath,"\",tmpArray)

 

  using the example you gave us:
      total = 3
      tmpArray(0)="C:"
      tmpArray(1)="Canada"
      tmpArray(2)="ONT"
      tmpArray(3)="Ottawa"

  notice that the 3 was the number of \ is found!

Good Luck!

Here is the function:

Function ParseString(LookIn As String, Search As String, ByRef ReturnArray As Variant) As Long
'
' Function Name:    ParseString
'
' Author:           JF Software (Jason R. Fayling)
'                   jfayling@glasscity.net
' Date:             1/10/97
'
' Inputs:           LookIn  (STRING)        String to use
'                   Search  (STRING)        What to look for in string
'                   ReturnARRAY (VARIANT)   Any found will be stored here
'
' Outputs:          ParseString (INTEGER)   Number of items in ReturnArray
'                                           starting with zero. If no item
'                                           was found, then returns -1
'
'                   ReturnArray (VARIANT)   Found items from string
'
' Purpose:          ParseString will take a string and seperate it into
'                   user-defined parts.
'                   Example:
'
'                       Dim i as Integer
'                       Dim j as integer
'                       dim Temp as variant
'
'                       i=ParseString("10/24/97","/",Temp)
'
'                       for j=0 to i
'                           msgbox Temp(j)
'                       next j
'
'                   This will display 10 then 24 then 97
'
'
' You are granted royalty free use of this code in your projects.   You may
' remove this comment block in your own projects.   If you intend to redistribute
' this function as part of a library or outside of your own VB project then you
' must leave this block in tact.


Dim X As Long
Dim start As Long
Dim pos As Long
Dim track As Long
ReDim TempHolder(Len(LookIn)) As String


    track = 0
    start = 1
   
    ' Start at the beginning of string and move down until it finds
    ' character it is looking for. Once it finds the character, it
    ' places everything before it and after the last found item into
    ' a new element in an array
   
    Do
        pos = InStr(start, LookIn, Search, vbBinaryCompare)
        If pos > 0 Then
            TempHolder(track) = Mid$(LookIn, start, (pos - start))
            track = track + 1
            start = pos + Len(Search)
        End If
    Loop Until pos = 0
   
    ' Make sure everything has been copied into Temp array
    TempHolder(track) = Mid$(LookIn, start, Len(LookIn))
       
    ReDim tempholder2(track)
   
    ' Move only elements with data in them
    For X = 0 To track
        tempholder2(X) = TempHolder(X)
    Next X
   
    Erase TempHolder
   
    ' Return Array is a variant so it can be passed an array
    ReturnArray = tempholder2
   
    If track = 0 Then
        ' Nothing was found
        ParseString = -1
    Else
        ParseString = track
    End If

End Function


0
 
LVL 4

Author Comment

by:idcanada
ID: 1437910
Thats a very good function,
although, would you mind helping me achieve the task asked in the Question?

I have a few problems,
How to read the last array?
(contains the filename)
and convert the rest to \..\..\ ???


0
 
LVL 4

Author Comment

by:idcanada
ID: 1437911
Okay,

I can read the last array.


0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…

690 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