8 Replies - 5582 Views - Last Post: 01 August 2011 - 12:08 PM
#1
Getting the caption of a label that will be used as a path. VB6
Posted 26 July 2011 - 03:05 AM
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!
Replies To: Getting the caption of a label that will be used as a path. VB6
#2
Re: Getting the caption of a label that will be used as a path. VB6
Posted 26 July 2011 - 09:38 AM
deverauxxi, on 26 July 2011 - 03:05 AM, said:
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
#3
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
#4
Re: Getting the caption of a label that will be used as a path. VB6
Posted 26 July 2011 - 07:53 PM
deverauxxi, 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
#5
Re: Getting the caption of a label that will be used as a path. VB6
Posted 29 July 2011 - 04:57 PM
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
#6
Re: Getting the caption of a label that will be used as a path. VB6
Posted 30 July 2011 - 08:23 PM
BobRodes, on 29 July 2011 - 04:57 PM, said:
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
#7
Re: Getting the caption of a label that will be used as a path. VB6
Posted 01 August 2011 - 09:45 AM
#8
Re: Getting the caption of a label that will be used as a path. VB6
Posted 01 August 2011 - 11:20 AM
BobRodes, on 01 August 2011 - 09:45 AM, said:
Seems fair.. i just was wondering.
Jesse Fender
#9
Re: Getting the caption of a label that will be used as a path. VB6
Posted 01 August 2011 - 12:08 PM
chuckjessup, on 01 August 2011 - 07:20 PM, said:
BobRodes, on 01 August 2011 - 09:45 AM, said:
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
|
|

New Topic/Question
Reply



MultiQuote



|