8 Replies - 8694 Views - Last Post: 01 August 2011 - 12:08 PM Rate Topic: ***** 1 Votes

#1 deverauxxi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 19-July 11

Getting the caption of a label that will be used as a path. VB6

Posted 26 July 2011 - 03:05 AM

Hello World!

Im copying my file to another location using FileSystemObject. Im always writing a code just like this->
fso.CopyFile "C:\Documents and Settings\Me123\Desktop\transfer.txt", "B:\Requirements\", False
But now, I'm using Directory Listbox and Drive Listbox to trace my target location (B:\Requirements\) and indicate the path at Label (so the caption of my label will hold the selected path) but it isn't working. How am I able to get that path inside the Label in order for me to transfer my file?

Thx!

Is This A Good Question/Topic? 0
  • +

Replies To: Getting the caption of a label that will be used as a path. VB6

#2 chuckjessup  Icon User is offline

  • D.I.C Regular

Reputation: 33
  • View blog
  • Posts: 380
  • Joined: 26-October 09

Re: Getting the caption of a label that will be used as a path. VB6

Posted 26 July 2011 - 09:38 AM

View Postdeverauxxi, on 26 July 2011 - 03:05 AM, said:

Hello World!

Im copying my file to another location using FileSystemObject. Im always writing a code just like this->
fso.CopyFile "C:\Documents and Settings\Me123\Desktop\transfer.txt", "B:\Requirements\", False
But now, I'm using Directory Listbox and Drive Listbox to trace my target location (B:\Requirements\) and indicate the path at Label (so the caption of my label will hold the selected path) but it isn't working. How am I able to get that path inside the Label in order for me to transfer my file?

Thx!


You are displaying the path to a label? If so set the path that you want to copy to or from or both to be equil to the labels caption property.

I would have assumed that you knew how to do this as you seem to have used the label to display the path...

Here is the code to do what I think you would like done.

'==================='
'Set Path to caption'
'==================='
Labelx.Caption=Dir.Path
'========================================'
'tell FSO to use the labels caption prop.'
'========================================'
FSO.CopyFile "RootPath\DirPath\SomeOtherDirPath\",Labelx.Caption,False
'End Example'



This should help you... Please in the future post some of your code so that we can help more with your issues. Use Code tags for display.

Jesse Fender
Was This Post Helpful? 1
  • +
  • -

#3 deverauxxi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 19-July 11

Re: Getting the caption of a label that will be used as a path. VB6

Posted 26 July 2011 - 06:37 PM

'cmdbtn1
Dim fso As FileSystemObject
Set fso = New FileSystemObject
fso.CopyFile Label1.Caption, lbltarget.Caption, True



This code works =)
Thx for your reply, it helped me to explore more codes.

This post has been edited by deverauxxi: 26 July 2011 - 06:38 PM

Was This Post Helpful? 0
  • +
  • -

#4 chuckjessup  Icon User is offline

  • D.I.C Regular

Reputation: 33
  • View blog
  • Posts: 380
  • Joined: 26-October 09

Re: Getting the caption of a label that will be used as a path. VB6

Posted 26 July 2011 - 07:53 PM

View Postdeverauxxi, on 26 July 2011 - 06:37 PM, said:

'cmdbtn1
Dim fso As FileSystemObject
Set fso = New FileSystemObject
fso.CopyFile Label1.Caption, lbltarget.Caption, True



This code works =)
Thx for your reply, it helped me to explore more codes.


Umm for future reference you can declare items that have to be set as new items with one line of code, two lines becomes confusing and inefficient... e.g.:
dim FSO as new FileSystemObject
'OR'
dim FS as FileSystemObject : Set FS = New FileSystemObject


this will help make your programs more efficient.

Also if you declare them in the general declarations then you dont have to re-declare them each sub...

Hope that helps...

Jesse Fender
Was This Post Helpful? 1
  • +
  • -

#5 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 572
  • View blog
  • Posts: 2,986
  • Joined: 19-May 09

Re: Getting the caption of a label that will be used as a path. VB6

Posted 29 July 2011 - 04:57 PM

Actually, Jesse, that's a HUGE nono, highly inefficient. (Sorry! I know it looks cleaner.) For reasons why, and some cool ways to work with class instances, see my FAQ on the subject here: http://www.tek-tips....qs.cfm?fid=6008

Also, the use of the colon to put two lines together is considered archaic in terms of style, because while it looks efficient it is actually a bit harder to debug. If you string several lines onto one, and one of them has a bug in it, the other lines around it create confusion in the opinion of most.

So I respectfully disagree with your post, with apologies. Dev, the way that you have this is considered best practice by Microsoft.

This post has been edited by BobRodes: 29 July 2011 - 05:01 PM

Was This Post Helpful? 1
  • +
  • -

#6 chuckjessup  Icon User is offline

  • D.I.C Regular

Reputation: 33
  • View blog
  • Posts: 380
  • Joined: 26-October 09

Re: Getting the caption of a label that will be used as a path. VB6

Posted 30 July 2011 - 08:23 PM

View PostBobRodes, on 29 July 2011 - 04:57 PM, said:

Actually, Jesse, that's a HUGE nono, highly inefficient. (Sorry! I know it looks cleaner.) For reasons why, and some cool ways to work with class instances, see my FAQ on the subject here: http://www.tek-tips....qs.cfm?fid=6008

Also, the use of the colon to put two lines together is considered archaic in terms of style, because while it looks efficient it is actually a bit harder to debug. If you string several lines onto one, and one of them has a bug in it, the other lines around it create confusion in the opinion of most.

So I respectfully disagree with your post, with apologies. Dev, the way that you have this is considered best practice by Microsoft.


Sorry Bob I had to reply... And at least clarify where i was coming from...

Since i have classes that are some times called only a few times, and ones that are called all the time... would it be better to declare the object in the general dec, and then set it to the object when the form is loading... would that work... since i am learning this is a better way?


The only other reason was that i thought i was being helpful... but i guess i was not.

Sorry about that :(

Jesse Fender
Was This Post Helpful? 0
  • +
  • -

#7 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 572
  • View blog
  • Posts: 2,986
  • Joined: 19-May 09

Re: Getting the caption of a label that will be used as a path. VB6

Posted 01 August 2011 - 09:45 AM

It's fair to say that you should NEVER use the "As New" construct in VB6. Your question appears to be a different one here. The answer is, of course, "it depends." Where you declare and where you instantiate an object depends on where you need to use the object. It's just that it isn't efficient to use the "As New" for the reasons that I have clearly stated in that FAQ.
Was This Post Helpful? 1
  • +
  • -

#8 chuckjessup  Icon User is offline

  • D.I.C Regular

Reputation: 33
  • View blog
  • Posts: 380
  • Joined: 26-October 09

Re: Getting the caption of a label that will be used as a path. VB6

Posted 01 August 2011 - 11:20 AM

View PostBobRodes, on 01 August 2011 - 09:45 AM, said:

It's fair to say that you should NEVER use the "As New" construct in VB6. Your question appears to be a different one here. The answer is, of course, "it depends." Where you declare and where you instantiate an object depends on where you need to use the object. It's just that it isn't efficient to use the "As New" for the reasons that I have clearly stated in that FAQ.


Seems fair.. i just was wondering.

Jesse Fender
Was This Post Helpful? 0
  • +
  • -

#9 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 572
  • View blog
  • Posts: 2,986
  • Joined: 19-May 09

Re: Getting the caption of a label that will be used as a path. VB6

Posted 01 August 2011 - 12:08 PM

View Postchuckjessup, on 01 August 2011 - 07:20 PM, said:

View PostBobRodes, on 01 August 2011 - 09:45 AM, said:

It's fair to say that you should NEVER use the "As New" construct in VB6. Your question appears to be a different one here. The answer is, of course, "it depends." Where you declare and where you instantiate an object depends on where you need to use the object. It's just that it isn't efficient to use the "As New" for the reasons that I have clearly stated in that FAQ.


Seems fair.. i just was wondering.

Jesse Fender

If you read the FAQ I wrote, the reason is quite obvious. It does mention a circumstance in which it might be more efficient in terms of memory usage to use the As New construct, but I can't see it coming up much if at all. The "With New" construct is the best one for throwaway objects, by the way.

This post has been edited by BobRodes: 01 August 2011 - 12:15 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1