• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 253
  • Last Modified:

Program codes meaning.

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
elyn_09
Asked:
elyn_09
  • 4
1 Solution
 
sazhagianambiCommented:
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
 
elyn_09Author Commented:
Thank you. Can you be more specific? Because I need to explain line by line in my project report. Thank You.
0
 
elyn_09Author Commented:
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!

 
elyn_09Author Commented:
Thank you. Can you be more specific? Because I need to explain line by line in my project report. Thank You.
0
 
elyn_09Author Commented:
Thank you. Can you be more specific? Because I need to explain line by line in my project report. Thank You.
0
 
Da_WeaselCommented:
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now