473,378 Members | 1,372 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

For Each loop question

I'm having trouble understanding exactly where something comes from. Consider the bit of script below. Who decided to use oFile in the loop and why choose oFile?
Expand|Select|Wrap|Line Numbers
  1. Set oFSO = WScript.CreateObject("Scripting.FileSystemObject")
  2.  
  3. sPath = InputBox("Provide starting folder path")
  4. Set oFolder = oFSO.GetFolder(sPath)
  5.  
  6. If oFSO.FolderExists(sPath) Then
  7.  
  8. For Each oFile in oFolder.Files
  9.     Msgbox "File " & oFile.Name & " last changed on on " & _
  10.     oFile.DateLastModified & " and of type " & _
  11.     oFile.Type & ". It is contained in folder " & _
  12.     oFile.ParentFolder.Path & " and uses the short " & _
  13.     " filename " & oFile.Shortname & "."
  14. Next
  15. End If
  16.  
Feb 10 '08 #1
4 1276
debasisdas
8,127 Expert 4TB
I dont think the code is yours

oFile is declared some where else which is not part of this code and that must be a file object.
Feb 11 '08 #2
I'm having trouble understanding exactly where something comes from. Consider the bit of script below. Who decided to use oFile in the loop and why choose oFile?
Expand|Select|Wrap|Line Numbers
  1. Set oFSO = WScript.CreateObject("Scripting.FileSystemObject")
  2.  
  3. sPath = InputBox("Provide starting folder path")
  4. Set oFolder = oFSO.GetFolder(sPath)
  5.  
  6. If oFSO.FolderExists(sPath) Then
  7.  
  8. For Each oFile in oFolder.Files
  9.     Msgbox "File " & oFile.Name & " last changed on on " & _
  10.     oFile.DateLastModified & " and of type " & _
  11.     oFile.Type & ". It is contained in folder " & _
  12.     oFile.ParentFolder.Path & " and uses the short " & _
  13.     " filename " & oFile.Shortname & "."
  14. Next
  15. End If
  16.  

Here


Dim oFSO As FileSystemObject
Dim sPath As String
Private Sub Command1_Click()
Set oFSO = New FileSystemObject

sPath = InputBox("Provide starting folder path")
Set oFolder = oFSO.GetFolder(sPath)

If oFSO.FolderExists(sPath) Then

For Each oFile In oFolder.Files
MsgBox "File " & oFile.Name & " last changed on on " & _
oFile.DateLastModified & " and of type " & _
oFile.Type & ". It is contained in folder " & _
oFile.ParentFolder.Path & " and uses the short " & _
" filename " & oFile.ShortName & "."
Next
End If

End Sub
Feb 11 '08 #3
The code is NOT mine. I was reading it and trying to figure out the thing I was asking about. The code also works as is so it is not declared anywhere else.

Thanks anyway
Feb 13 '08 #4
Killer42
8,435 Expert 8TB
... The code also works as is so it is not declared anywhere else.
Then VB must be set to allow you to use variables without explicitly declaring them - a very bad practice.
Feb 13 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

33
by: Arthur | last post by:
>>>a= >>> for p in a: print p 1 2 3 >>> p 3 My naive expectation was that p would be 'not defined' from outside
0
by: John Wilson | last post by:
Hello, I have the following code which populates as table data from a SQL Server 2000 stored proc (RSByDemoID2). Below that is the view and stored procedure which takes @DemoID as input to match...
3
by: zeroDoNotYeSpamtype | last post by:
(I tried to post this earlier, but it seems without success) A similar question to this has been answered many times, to whit the question applying when the index variable of a for loop is...
3
by: Gustavo Randich | last post by:
The following seems to be a bug. The execution returns rows 1,2. It should return 1,1. In fact, if I run the code within a stored procedure alone (not in a trigger), the loop doesn't overwrite the...
22
by: Jan Richter | last post by:
Hi there, the Code below shows DJBs own implementation of strlen (str_len): unsigned int str_len(char *s) { register char *t; t = s; for (;;) { if (!*t) return t - s; ++t;
8
by: Shamrokk | last post by:
My application has a loop that needs to run every 2 seconds or so. To acomplish this I used... "Thread.Sleep(2000);" When I run the program it runs fine. Once I press the button that starts the...
29
by: garyusenet | last post by:
I'm trying to investigate the maximum size of different variable types. I'm using INT as my starting variable for exploration. I know that the maximum number that the int variable can take is:...
3
by: nina297 | last post by:
Good morning, How do I set up a For each loop to loop through my records in the database? My fields are topics, question and answers. I want the one topic displayed that goes with each...
44
by: James Watt | last post by:
can anyone tell me how to do an infinite loop in C/C++, please ? this is not a homework question .
2
by: perkykoala | last post by:
I apologize in advance for being REALLY detailed/verbose. It's the result of staring/tweaking code for too long. Using VB 2005: I need to design a multiple choice test (unfortunately, I can't...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.