Results 1 to 4 of 4

Thread: [RESOLVED] [02/03] Class variables for pathway

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Location
    NZ
    Posts
    178

    Resolved [RESOLVED] [02/03] Class variables for pathway

    I am trying understand why my "path" variable will not work for File/OpenText etc yet my "f" & ''fn" variables work together. I have the following code in above the FormLoad window.

    VB Code:
    1. Dim fn As String 'Filename that is being manipulated
    2.   Dim f As String = ("C:\71151A2\")
    3.   Dim path As String = f & fn

    If i use
    VB Code:
    1. fn = "PHONELISTS.TXT" 'File with phone directories
    2.     sr = File.OpenText(f & fn)
    The code finds the file but if I use "path" in place of "f" & ''fn" it won't find it! Any clues as to why. I have declared the variable again in the sub procedure.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [02/03] Class variables for pathway

    Please do not create duplicate threads. They are a hindrance to the smooth running of the forum and they don't help you in any way.

    After executing this code:
    VB Code:
    1. Dim fn As String 'Filename that is being manipulated
    2.   Dim f As String = ("C:\71151A2\")
    3.   Dim path As String = f & fn
    the 'path' variable contains the string "C:\71151A2\". After that, setting 'fn' to something has no effect whatsoever on 'path', so after this code:
    VB Code:
    1. fn = "PHONELISTS.TXT" 'File with phone directories
    'fn' contains the string "PHONELISTS.TXT" but 'path' still contains "C:\71151A2\". Had you used the debugger to check the value of path when you were using it you would have seen that.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [02/03] Class variables for pathway

    I am going to delete the dup

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Location
    NZ
    Posts
    178

    Re: [02/03] Class variables for pathway

    Quote Originally Posted by jmcilhinney
    Please do not create duplicate threads. They are a hindrance to the smooth running of the forum and they don't help you in any way.
    Apologies for this I do not know how this happened. As for the debugger sometimes it works & sometimes it doesn't. I appear to have some minor gremlins that are inconsistent & intermitten with my system & produces unexpected & unusual results.

    As to "path" explanation, I did see that but what I do not know is why!!!! ,because I Dim path = f & fn (which work by themselves).

    Now I see!!!!! Thankyou

    Rest assured I have appreciated your help very much to a newbie who knows enuff to be dangerous!

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