Results 1 to 5 of 5

Thread: Filenames, Pathnames, Filenames.....

  1. #1
    Guest

    Question

    Whenever I am working with FileBoxes, I always have to use this bit of code. It makes sense but surely there is a quicker way or less code is required.

    Code:
    Private Sub cmdOpen_Click()
    Dim Slash As String
    
    Slash = "\"
    If Right(fil.Path, 1) = "\" Then Slash = ""
    
    ShellExecute Me.hwnd, "open", fil.Path & Slash & fil.FileName, "", fil.Path & Slash, 0
    End Sub
    The reason why I need to put this in (for those who are still wondering) is because fil.Path always gives the path without a '\' on the end, UNLESS it is the root directory (i.e. 'C:\'). So is there anyway to put a slash or dash or whatever on the end of a path and not put one there if there is already on there?

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Code:
    Sub SetSlash(Text as string)
      if right$(Text,1)<>"\" then text = text & "\"
    End sub
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Guest
    Oh, I didn't think of that (obviously).

    Another thing, looking at your code I saw right$(). What does this do? And the following things...

    Code:
    Text1.Text = Right("asdfasdf", 1)
    Text1.Text = Right$("asdfasdf", 1)
    
    'And these ones:
    
    Text1.Text = Chr(65)
    Text1.Text = Chr$(65)
    
    'And a lot of people are doing this:
    
    Dim r As Long
    r& = 20 * 2
    I'm not that good at VB so I don't know what this does.

  4. #4
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Right returns a variant.
    Right$ returns a string.

    Same goes for Chr and Chr$.

    I think you can write:

    Dim r&

    and it will declare r& as Long. I think it's called postfix notation or something like that. Variables ending in $ are strings, and ending in % are integers I think. I don't use it myself because it looks messy.
    Harry.

    "From one thing, know ten thousand things."

  5. #5
    Guest
    The Right function takes in a variant, whereas the Right$ takes in a string.

    This means that Right$ is slightly faster as it doesn't have to cast the variant "String" parameter to a string data type before the requested string is returned.

    This holds true for all functions where there is a $ and non-$ version (Left, Trim, Chr, Right etc.)

    - gaffa

    [Edited by gaffa on 11-08-2000 at 02:20 AM]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width