
November 14th, 2007, 03:10 PM
|
|
Registered User
|
|
Join Date: Nov 2007
Posts: 2
Time spent in forums: 16 m 38 sec
Reputation Power: 0
|
|
|
Basic VBScript Class Loop determine biggest and smallest!
I am in a very basic VBScript class in college where we need to write a program using a loop, reading from a program. I have reading from the file and writing to a new one and all the calculations I have, but how can I work in an if statement to compare the number to the previous one. I know this is a lot of code, but I figure it will help, thanks in advance!
Code:
Option Explicit
Dim rts,rfso,wts,wfso,Nums,x,b,c,ct,totx,e,f,q
Call OpenFiletoRead(rts,rfso)
Call OpenFiletoWrite(wts,wfso)
Call Heading(wts)
Call GetNums(nums,rts)
Do until csng(nums) >= 9999
Call count(ct)
totx=csng(totx) + csng(nums)
If csng(nums) > csng(tot
b=fir(nums)
c=sec(nums)
Call Table(nums,wts)
Call GetNums(nums,rts)
Loop
wts.write "--------------------------------------------------------"
wts.writeblanklines 2
wts.write "Average " & average(nums)
wts.writeblanklines 1
wts.write "Largest " & e
wts.writeblanklines 1
wts.write "Smallest " & f
Call closefile(rts,rfso,wts,wfso)
'-------------------SUBS------------------
Sub GetNums(nums, rts)
nums = rts.read(7)
End Sub
Sub count(ct)
If nums < 9999 Then
ct = csng(ct) + 1
End If
End Sub
Sub Table(nums, wts)
Call leftjustify(nums, 15)
wts.write nums
Call rightjustify(b,15)
wts.write b
Call rightjustify(c,25)
wts.write c
wts.writeblanklines 2
End Sub
Sub Heading(wts)
wts.write "x Int(x) Int(10x + .5)/10 "
wts.writeblanklines 1
wts.write "------------------------------------------------"
wts.writeblanklines 2
End Sub
'------------------------------------------------
Sub OpenFiletoWrite(wts,wfso)
Dim filename
Set wfso=createobject("Scripting.Filesystemobject")
Filename="ProjectNums.txt"
Set wts=wfso.createtextfile(filename,True)
End Sub
Sub rightjustify(myNumber,n)
Dim colwidth
Do until cint(colwidth) > cint(n)
myNumber=" " & cstr(myNumber)
colwidth= len(cstr(myNumber))
Loop
colwidth=0
n=0
End Sub
Sub Openfiletoread(rts,rfso)
Dim filename
Set rfso=createobject("Scripting.filesystemobject")
filename="TheNumbers.txt"
Set rts=rfso.opentextfile(filename,1,False)
End Sub
Sub closefile(rts,rfso,wts,wfso)
rts.close
wts.close
Set wts=Nothing
Set wfso=Nothing
Set rts=Nothing
Set rfso=Nothing
End Sub
Function fir(a)
fir=int(a)
End Function
Function sec(a)
Dim y
y= (10*csng(a)) + .05
sec=int(y)/10
End Function
Sub LeftJustify(myWord, n)
Dim colwidth
Do until cint(colWidth) > cint(n)
myWord = cstr(myWord) & " "
colwidth = cint(len(cstr(myword)))
Loop
colwidth = 0
n = 0
End Sub
Function average(a)
average= csng(totx)/csng(ct)
End Function
Last edited by Shadow Wizard : November 20th, 2007 at 01:46 AM.
Reason: added [Code] and [/Code] tags around code please do that yourself next.
|