hi folks,
I put together a little nifty vbscript during a time where I was bored.
what it does is the following:
1)it starts by determining if variable object is an object indeed and it gives its test result in a msgbox using the IsObject intrinsic function
2) it then prompts you for the name of any of your ex-girlfriends(assuming you are a male)
3) after a name is entered, a mesgbox asks whether you want to continue entering names or not,
4) if yes, the array used to store girlfriends' name is re dimensioned to its by adding one more element to it
5) all this execution takes places in a "do loop while" loop that continues to iterating asking whether its ok to continue entering more name, the loop gets only exited when you choose no
6) after the loop is finished, the script instantiates the CreateTextfile method of the filesystem object to :
a. create a blank new text file in my desktop directory(you may have to change this directory path to that of yours in order to make it work)
b. the script writes to the file the date and time in which the file was last modified
according to your system time settings
c. the scripts enters a "for next" loop in which it writes the element values of the array in chronological order(the order in which they were originally entered) one in its own separate line
d. the script then rearranges the names entered in the array in alphabetical order using the bubble sort technique
here is the entire script code, so guys have fun and please send me any thoughts or suggestions to improve it, thanks
' first stage : variables declaration zone
Option Explicit
Dim gf_array(), x, message, name, gname, element, temp, i, j
Dim FSO, txtFile : Set FSO = WScript.CreateObject("Scripting.FileSystemObject")
ReDim gf_array(1)
'------------------------------------------------------------------------------------------------
' second stage : fist array data item entry
MsgBox("FS0 variable is an object: " & IsObject(FSO)) 'function that returns a boolean value indicating whether expression is an object
name = InputBox("enter the name of a girlfriend", "Girl Friend name") 'first prompt
gf_array(UBound(gf_array) -1) = name 'adds element to the first index position of Array
'---------------------------------------------------------------------------------------------
' second stage : looping
Do
message = MsgBox("would you like to enter another girlfriend's name?", vbYesNo, "Name")
If message = vbYes Then
ReDim Preserve gf_array(UBound(gf_array) + 1)
name = InputBox("enter the name of a girlfriend", "Girl Friend name")
gf_array(UBound(gf_array) -1) = name
End If
Loop While message <> vbNo
gname = "your girlfriends' names are: " & vbNewLine
'-----------------------------------------------------------------------------------------------------------
' third stage : working the file system object
Set txtFile = FSO.CreateTextFile("c:\users\bryan\desktop\girlfriends.txt" , True)
txtFile.WriteLine("Last Modified on " & DateValue(Now()) & " at: " & TimeValue(Now()) & VbCrLf & vbcrlf)
txtFile.WriteLine("the chronological order in which you entered the names are:" & vbcrlf)
For x = 0 To UBound(gf_array)
gname = gname & gf_array(x) & vbNewLine
txtFile.WriteLine(gf_array(x) & vbcrlf)
Next
MsgBox gname,,"Total GirlFriends's names"
'--------------------------------------------------------------------------------------------------------------------
'fourth stage : alphabetical sorting of Array
For i = UBound(gf_array) - 1 To 0 Step -1
For j = 0 To i
If gf_array(j) > gf_array(j+1) Then
temp=gf_array(j+1)
gf_array(j+1) = gf_array(j)
gf_array(j) = temp
End If
Next
Next
'--------------------------------------------------------------------------------------------------------------------
'fifth stage : writing the names to the text file in alphabetical order
gname = "alphabetical order of your past girlfriends: "
txtFile.WriteLine(VbCrLf & "the names of all of your past girlfriends in alphabetical order is:")
For x = 0 To UBound(gf_array)
gname = gname & gf_array(x) & vbNewLine
txtFile.WriteLine(gf_array(x) & vbcrlf)
Next
MsgBox gname,,"Total GirlFriends's names"
txtFile.Close