?
Solved

Program codes meaning.

Posted on 2003-02-26
6
Medium Priority
?
237 Views
Last Modified: 2010-05-01
This is a send file program.

With Me.CommonDialog1
       .DialogTitle = "Choose File:"
       .InitDir = App.Path
       .ShowOpen
   End With
   
   If Me.CommonDialog1.FileName <> "" Then
       Me.List1.AddItem Me.CommonDialog1.FileName
   End If

In the second buttons click event:

In the second buttons click event:
'there is a better way to do this with the API, but
'this is easier.

   With Me.CommonDialog1
       .DialogTitle = "Choose Send To Path:"
       .InitDir = App.Path
       .FileName = "x"
       .ShowOpen
   End With
   
   If Me.CommonDialog1.FileName <> "" Then
       Me.Label1.Caption = Mid(Me.CommonDialog1.FileName, 1, InStrRev(Me.CommonDialog1.FileName, "\"))
   End If

In the third buttons click event do either:
Dim iItem as integer
Dim strFile as string

For iItem = Me.List1.ListCount - 1 To 0 Step -1
    strFile = Dir(Me.List1.List(iItem))
    FileCopy Me.List1.List(iItem), Me.Label1.Caption & strFile
    Kill Me.List1.List(iItem)
    Me.List1.RemoveItem (iItem)
Next iItem

or

Dim iItem as integer
Dim strFile as string

For iItem = Me.List1.ListCount - 1 To 0 Step -1
    strFile = Dir(Me.List1.List(iItem))
    Name Me.List1.List(iItem) As Me.Label1.Caption & strFile
    Me.List1.RemoveItem (iItem)
Next iItem

Can someone be kind enough to explain what each sentence does? Maybe just put a bracket beside the code and say what each sentence does.
0
Comment
Question by:elyn_09
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 1

Expert Comment

by:sazhagianambi
ID: 8024969
Hi,


With Me.CommonDialog1[CommonDialog used to show the FilePath dialogs]
      .DialogTitle = "Choose File:"
      .InitDir = App.Path [Set Present Path]
      .ShowOpen 'Show
  End With
 
  If Me.CommonDialog1.FileName <> "" Then 'If Any File Name Selected
      Me.List1.AddItem Me.CommonDialog1.FileName 'Add FileName int List1
  End If

In the second buttons click event:

In the second buttons click event:
'there is a better way to do this with the API, but
'this is easier.

  With Me.CommonDialog1  [Show CommonDialog Box With Present Working Dir and a File Name as 'x']
      .DialogTitle = "Choose Send To Path:"
      .InitDir = App.Path
      .FileName = "x"
      .ShowOpen
  End With
 
  If Me.CommonDialog1.FileName <> "" Then 'If any FileName Selected (ie Dir Path)
      Me.Label1.Caption = Mid(Me.CommonDialog1.FileName, 1, InStrRev(Me.CommonDialog1.FileName, "\")) ' Set Label caption as FileName With /
  End If

In the third buttons click event do either:
Dim iItem as integer
Dim strFile as string


['Here Select Each FileName From ListBox Copy them Into the Directory Which is in Label Caption]
[Both Loop Doing Same Thing]

For iItem = Me.List1.ListCount - 1 To 0 Step -1
   strFile = Dir(Me.List1.List(iItem))
   FileCopy Me.List1.List(iItem), Me.Label1.Caption & strFile
   Kill Me.List1.List(iItem)
   Me.List1.RemoveItem (iItem)
Next iItem

or

Dim iItem as integer
Dim strFile as string

For iItem = Me.List1.ListCount - 1 To 0 Step -1
   strFile = Dir(Me.List1.List(iItem))
   Name Me.List1.List(iItem) As Me.Label1.Caption & strFile
   Me.List1.RemoveItem (iItem)
Next iItem


Friend i Give Mu Comments With in[] . Hope this will be Helpful.

Regards,
Nambi
0
 

Author Comment

by:elyn_09
ID: 8025090
Thank you. Can you be more specific? Because I need to explain line by line in my project report. Thank You.
0
 

Author Comment

by:elyn_09
ID: 8025102
Thank you. Can you be more specific? Because I need to explain line by line in my project report. Thank You.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:elyn_09
ID: 8025103
Thank you. Can you be more specific? Because I need to explain line by line in my project report. Thank You.
0
 

Author Comment

by:elyn_09
ID: 8025200
Thank you. Can you be more specific? Because I need to explain line by line in my project report. Thank You.
0
 
LVL 3

Accepted Solution

by:
Da_Weasel earned 240 total points
ID: 8027289
With Me.CommonDialog1
  'set the dialoge title
  .DialogTitle = "Choose File:"
  'set the initial directory to the same one that the
  'program is running from
  .InitDir = App.Path
  'show the Open File dialog window
  .ShowOpen
End With

'if the file name is blank then no file was
'selected, do nothing
If Me.CommonDialog1.FileName <> "" Then
  'a file was selected to get the Filename property of the
  'CommonDialog control and add it to the List control via
  'the AddNew method
  Me.List1.AddItem Me.CommonDialog1.FileName
End If

In the second buttons click event:
With Me.CommonDialog1
  'set the Dialog box title
  .DialogTitle = "Choose Send To Path:"
  'set the initial directory to the same one that the
  'program is running from
  .InitDir = App.Path
  'set the initial value for the file name to "x"
  .FileName = "x"
  'show the Open File dialog window
  .ShowOpen
End With
 
'if the file name is blank then no file was
'selected, do nothing
If Me.CommonDialog1.FileName <> "" Then
  'a file was selected to get the Filename property of the
  'CommonDialog control and add it to the List control via
  'the AddNew method
  Me.Label1.Caption = Mid(Me.CommonDialog1.FileName, 1, InStrRev(Me.CommonDialog1.FileName, "\"))
  'InStrRev returns the position in a string of the first
  'occurance of a character starting from the end of the
  'string
  'eg if FileName = C:\some\path\filename.exe then it
  'returns 13 which is the this ^ characters position
  'that is inturn used as a parameter to the Mid Fucntion
  'that will end up looking something like this with our
  'example Mid("C:\some\path\filename.exe",1,13)
  'that statement tells it to return 13 characters of the
  'string starting with character number 1 ("C")
  'then assign it too the lable control, so using our
  'example data the lables caption would
  'be "C:\some\path\"
End If

In the third buttons click event do either:
Dim iItem as integer
Dim strFile as string
'here we are setting up a loop that ranges from the
'[total number of list box items] - 0 and subtracts one
'each time through the loop
For iItem = Me.List1.ListCount - 1 To 0 Step -1
   'Dir returns the filename of the full path if it finds a
   'mathcing one
   'e.g. if the list item = c:\some\path\test.txt
   'then it will return test.txt
   strFile = Dir(Me.List1.List(iItem))
   'FileCopy then copies the currently selected item
   'in the list to the path and file name contructed
   'from the path in the label caption and the filename
   'gotten above with the Dir function
   FileCopy Me.List1.List(iItem), Me.Label1.Caption & strFile
   'delete the currently selected file in the listbox
   Kill Me.List1.List(iItem)
   'remove the item from the listbox
   Me.List1.RemoveItem (iItem)
Next iItem

or

Dim iItem as integer
Dim strFile as string

'same as above
For iItem = Me.List1.ListCount - 1 To 0 Step -1
   'same as above
   strFile = Dir(Me.List1.List(iItem))
   'the Name Function renames a file
   'if the new path is different from the old path
   'then the file is moved to the new location
   Name Me.List1.List(iItem) As Me.Label1.Caption & strFile
   'same as above
   Me.List1.RemoveItem (iItem)
Next iItem
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question