Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function Value

Status
Not open for further replies.

ajtsystems

IS-IT--Management
Jan 15, 2009
80
GB
I wonder if anyone can help? I have this function

Set objFile3 = objFSO.GetFile(results)
Set objFile4 = objFSO.GetFile(resultsCopy)


if objFile4.Size = objFile3.Size then
osame = false
else
osame = true
end if

retvalue = ShowFileSum(FileSize1, FileSize2)

MsgBox "The function returned: " & retValue


'call function, if file has changed then same is 0
showFileSum 0, osame

Function ShowFileSum(FileSize1, FileSize2)
Dim sum

' Determine and display the sum.
sum = FileSize1 + FileSize2

' Set the function's return value.
ShowFileSum = sum

End Function


No matter what size the files which I compare are the function always seems to return 0. When I echo same it does show a value of 1. Something in the function maybe?
 
@op: If you do not understand certain aspect of certain problem, you ask (nicely) for further clarification and help. It is not the way to do thing professionally by proliferating threads of essence the same problem you've asked. (Count your time. It can go: time's up.)
 
You forgot to assign values to the function arguments:
Code:
[COLOR=#804040][b]set[/b][/color] objFSO  [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]CreateObject[/color][COLOR=#804040][b]([/b][/color][COLOR=#ff00ff]"Scripting.FileSystemObject"[/color][COLOR=#804040][b])[/b][/color]
[COLOR=#804040][b]Set[/b][/color] objFile3 [COLOR=#804040][b]=[/b][/color] objFSO[COLOR=#804040][b].[/b][/color][COLOR=#a020f0]GetFile[/color][COLOR=#804040][b]([/b][/color][COLOR=#ff00ff]"results.txt"[/color][COLOR=#804040][b])[/b][/color]
[COLOR=#804040][b]Set[/b][/color] objFile4 [COLOR=#804040][b]=[/b][/color] objFSO[COLOR=#804040][b].[/b][/color][COLOR=#a020f0]GetFile[/color][COLOR=#804040][b]([/b][/color][COLOR=#ff00ff]"resultsCopy.txt"[/color][COLOR=#804040][b])[/b][/color]

FileSize1 [COLOR=#804040][b]=[/b][/color] objFile3[COLOR=#804040][b].[/b][/color][COLOR=#a020f0]Size[/color]
FileSize2 [COLOR=#804040][b]=[/b][/color] objFile4[COLOR=#804040][b].[/b][/color][COLOR=#a020f0]Size[/color]

Wscript[COLOR=#804040][b].[/b][/color]Echo [COLOR=#ff00ff]"FileSize1 = "[/color] [COLOR=#804040][b]&[/b][/color] FileSize1 [COLOR=#804040][b]& _[/b][/color]
             [COLOR=#ff00ff]", FileSize2 = "[/color] [COLOR=#804040][b]&[/b][/color] FileSize2

[COLOR=#804040][b]if[/b][/color] FileSize1 [COLOR=#804040][b]=[/b][/color] FileSize2 [COLOR=#804040][b]then[/b][/color]
  osame [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]false[/color] 
[COLOR=#804040][b]else[/b][/color] 
  osame [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]true[/color]
[COLOR=#804040][b]end[/b][/color] [COLOR=#804040][b]if[/b][/color] 

retvalue [COLOR=#804040][b]=[/b][/color] ShowFileSum[COLOR=#804040][b]([/b][/color]FileSize1[COLOR=#804040][b],[/b][/color] FileSize2[COLOR=#804040][b])[/b][/color]

Wscript[COLOR=#804040][b].[/b][/color]Echo [COLOR=#ff00ff]"The function returned:  "[/color] [COLOR=#804040][b]&[/b][/color] retValue


[COLOR=#0000ff]'call function, if file has changed then same is 0[/color]
showFileSum [COLOR=#ff00ff]0[/color][COLOR=#804040][b],[/b][/color] osame

[COLOR=#804040][b]Function[/b][/color] ShowFileSum[COLOR=#804040][b]([/b][/color]FileSize1[COLOR=#804040][b],[/b][/color] FileSize2[COLOR=#804040][b])[/b][/color]
    [COLOR=#804040][b]Dim[/b][/color] [COLOR=#008080]sum[/color]
   [COLOR=#0000ff] ' Determine and display the sum.[/color]
    [COLOR=#008080]sum[/color] [COLOR=#804040][b]=[/b][/color] FileSize1 [COLOR=#804040][b]+[/b][/color] FileSize2
   [COLOR=#0000ff] ' Set the function's return value.[/color]
    ShowFileSum [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]sum[/color]
[COLOR=#804040][b]End[/b][/color] [COLOR=#804040][b]Function[/b][/color]
Output:
Code:
cscript /Nologo pokus.vbs
FileSize1 = 5, FileSize2 = 4
The function returned:  9
 
showFileSum 0, osame???
0 + False or 0 + True....doesnt make that much sense to me
 
I agree with mrmovie.

Also, comparing file sizes is not a definitive test whether the files are the same or not. Even so, I think you would want to reverse the logic of this test:
Code:
if objFile4.Size = objFile3.Size then
osame = false 
   else 
osame = true
end if

As is - it says "if the file sizes are equal, set osame = true
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top