Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 27th, 2012, 08:50 AM
Juz Juz is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 1 Juz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 50 sec
Reputation Power: 0
Issues with If statement not comparing Variables

Hello all,
I'm fairly new to VBscript so bare with me, I'm trying to create a script to get a line of test from one text document and then create a variable with it and then store that in one file. Once that Source text file entry has been updated then get it again and compare the two variables.

Heres what I have so far:
Code:
Set obj = CreateObject("Scripting.FileSystemObject") 
Set objTextFile = obj.OpenTextFile("listdrives.txt",1) 
For i = 1 to 84    
objTextFile.ReadLine 
Next 
strLine = objTextFile.ReadLine 
objTextFile.Close 

If (obj.FileExists("disk1.txt")) Then 
Set objWriteFile = obj.OpenTextFile("disk2.txt",2,true) 
 objWriteFile.WriteLine strLine 
 objWriteFile.WriteLine Date 
 objWriteFile.Close

Else
Set objWriteFile = obj.OpenTextFile("disk1.txt",2,true) 
 objWriteFile.WriteLine strLine 
 objWriteFile.WriteLine Date 
 objWriteFile.Close
End If 

If (obj.FileExists("disk2.txt")) Then 

Set objTextFile = obj.OpenTextFile("disk1.txt",1) 
 strLine1 = objTextFile.ReadAll 
 objTextFile.Close

Set objTextFile = obj.OpenTextFile("disk2.txt",1) 
 strLine2 = objTextFile.ReadAll 
 objTextFile.Close

If strLine1 = strLine2 Then 

Set objWriteFile = obj.OpenTextFile("NotChanged.txt",2,true) 
 objWriteFile.WriteLine strLine1 
 objWriteFile.WriteLine strLine2 
 objWriteFile.Close

Else
Set objWriteFile = obj.OpenTextFile("Changed.txt",2,true) 
 objWriteFile.WriteLine strLine1
 objWriteFile.WriteLine strLine2 
objWriteFile.Close
Set objWriteFile = obj.OpenTextFile("disk1.txt",2,true) 
 objWriteFile.WriteLine strLine2 
 objWriteFile.Close

End If 
End If 

The result I get is first run -
Creates disk1.txt with correct content
Second run - Creates disk2.txt with correct content then compares the two and creates NotChanged.txt with correct content
Third run (When I change the 85th line in listdrives.txt) - Creates Changed.txt with correct content and modify's disk1.txt correctly
Fourth run (With 85th line in listdrives.txt unchanged) -
Modify's Changed.txt with correct content and modify's disk1.txt with correct content?
So even though both variables are the same its going to the Else clause for some reason?
Thanks in advance
Juz

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Issues with If statement not comparing Variables

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap