Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


WHS scripting with functions

 
Logged in as: Guest
arrSession:exec spGetSession 2,16,58143
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> Post a VBScript >> WHS scripting with functions
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 WHS scripting with functions - 3/18/2008 7:51:38 AM   
  drawls

 

Posts: 4
Score: 0
Joined: 2/11/2008
Status: offline
option explicit
dim input1
dim msg
input1 = inputbox("Enter a number.")
msg = whatnum(input1)
msgbox msg, vbokonly, "t2r1"
function whatnum(in1)
dim out
if isnumeric(in1) then
if in1 > 0 then
 out = "The number is positive."
elseif in1 < 0 then
 out = "The number is negitive."
else
 out = "The number is zero."
end if
else
out = "You did not enter a number."
end if
whatnum = out
end function
--------------------------------------------------------------------------------------------------------------
option explicit
dim word1
dim word2
dim body
dim title
word1 = inputbox("Enter a word.")
word2 = inputbox("Enter another word.")
body = upperlower(word1, word2, title)
msgbox body, vbokonly, title
function upperlower(w1, w2, title)
dim b1
title = lcase(w2)
b1 = ucase(w1)
upperlower = b1
end function
--------------------------------------------------------------------------------------------------------------
option explicit
dim num
dim sum
dim count
dim hi
dim lo
dim avg
num = inputbox("Enter a number.")
hi = num
lo = num
count = 1
do until num < 0
sum = cdbl(sum) + cdbl(num)
if num > hi then
 hi = num
end if
if num < lo then
 lo = num
end if
avg = doavg(sum, count)
count = cdbl(count) + 1
num = inputbox("Enter a positive number or a negitive to end.")
loop
msgbox "The sum is: " & sum & vbcrlf & "The average is: " & avg & vbcrlf & "The hi is: " &
hi & vbcrlf & "The lo is: " & lo, vbokonly, "t2r3"
function doavg(s1, c1)
dim average
average = cdbl(s1) / cdbl(c1)
doavg = average
end function

--------------------------------------------------------------------------------------------------------------

option explicit
dim num1
dim num2
dim output
num1 = inputbox("Enter the first number.")
num2 = inputbox("Enter the second number.")
output = dostring(num1, num2)
msgbox output, vbokonly, "t2r4"
function dostring(n1, n2)
dim count
dim out
if n1 < n2 then
for count = n1 to n2
 out = out & count & " "
next
else
for count = n2 to n1
 out = out & count & " "
next
end if
dostring = out
end function
--------------------------------------------------------------------------------------------------------------
option explicit
dim st1
dim st2
dim comp
st1 = inputbox("Enter a number.")
st2 = inputbox("Enter another number.")
comp = stringcomp(st1, st2)
msgbox comp, vbokonly, "t2r5"
function stringcomp(s1, s2)
dim output
dim test
test = strcomp(s1, s2)
if test = 0 then
output = "They are the same."
else
output = "The are differant."
end if
stringcomp = output
end function
-------------------------------------------------------------------------------------------------------------
option explicit
dim num
dim myArray()
dim output
dim count
num = inputbox("Enter a number.")
redim myArray(num)
for count = 0 to num - 1
myArray(count) = cdbl(count) + 1
next
output = doout(myArray)
msgbox output, vbokonly, "t2r6"
function doout(myArray)
dim x
dim out
for x = 0 to num - 1
out = out & myArray(x) & " "
next
doout = out
end function
--------------------------------------------------------------------------------------------------------------
option explicit
dim filename
dim strinput
dim stroutput
dim x
dim z
filename = inputbox("Enter the file name and location.")
strinput = inputbox("Enter the phrase.")
set x = wscript.createobject("scripting.filesystemobject")
createfile()
writefile()
closefile()
openfile()
readfile()
closefile()
msgbox stroutput
function createfile()
if (x.fileexists(filename)) then
set z = x.opentextfile(filename, 8)
else
set z = x.opentextfile(filename, 2, "true")
end if
end function
function writefile()
z.writeline strinput
end function
function closefile()
z.close()
end function
function openfile()
set z = x.opentextfile(filename, 1)
end function
function readfile()
stroutput = z.readall()
end function
--------------------------------------------------------------------------------------------------------------
option explicit
dim filename
dim inputfolder
dim x
dim z
dim strinput
dim fileFolder
dim folder
filename = inputbox("Enter the name of the file.")
inputfolder = inputbox("Enter the name of the folder.")
strinput = inputbox("Enter the string to type in the file.")
folder = "c:\" & inputfolder
fileFolder = folder & "\" & filename
set x = wscript.createobject("scripting.filesystemobject")
msgbox fileFolder
x.createfolder folder
openfile()
function openfile()
if x.fileexists(fileFolder) then
set z = x.opentextfile(fileFolder, 2)
else
set z = x.opentextfile(fileFolder, 8, "true")
end if
end function
z.writeline strinput
z.close
x.copyfile fileFolder, folder & "\fileCopy.txt"
x.deletefile fileFolder
-------------------------------------------------------------------------------------------------------------
option explicit
dim msgoutput
dim x
on error resume next
msgoutput = "Hello"
msbox msgoutput
if Err > 0 then
Err.description = "The msgbox command is mispelled."
set x = wscript.createobject("wscript.shell")
x.logevent 1, "t2r9.vbs Error: " & Err.number & " Description: " & Err.Description
& " Source: " & Err.source
msgbox "Error: " & Err.number & " - " & Err.description
Err.clear
end if
 
 
Post #: 1
 
 RE: WHS scripting with functions - 3/18/2008 8:07:05 AM   
  ebgreen


Posts: 4408
Score: 29
Joined: 7/12/2005
Status: offline
Thanks for posting this code for others to look at. Could you please explain what the purpose is and use code tags and format the code to make it more legible?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to drawls)
 
 
Post #: 2
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> Post a VBScript >> WHS scripting with functions Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts