Its been a while since I have thought about posting anything. For the summer semester I am taking CPT-114 which is basically Visual Basic, but thus far its mostly been VBScript, a Microsoft proprietary javascript wannabe. I finally got to a script which was complex enough to post. Basically, its a program that generates a list of gifts for a wedding registry sorted by side of the wedding party, the original assignment also said to make an additional list of gifts that were repeated, but the instructor said we could omit the last part due to the complexity. Well that sounded like a challenge to me, so this is what I spaghetti-coded. (I hope it fits)
<script language="vbScript" type="text/vbscript">
option explicit
dim name, faction, gift, bride_text_out, groom_text_out, groom_counter, bride_counter, flag, flag1, flag2
dim gift_counter, gift_index_list, current_gift, length_check, one_cut, gift_pointer2, single_flag, record_count
dim gift_list, name_list, eof_flag, gift_index_flag, gift_pointer, gift_name, gift_precount
set gift_index_list = createobject("scripting.dictionary")
set gift_list = createobject("scripting.dictionary")
flag = "yes"
Do while flag="yes"
name = inputbox("Enter name:")
faction = inputbox("Enter faction: (bride/groom)")
gift = inputbox("Enter gift name:")
record_count = record_count + 1
if faction = "bride" then
bride_counter = bride_counter + 1
bride_text_out = bride_text_out & bride_counter & ". " & name & ": " & gift & "<br>"
else
groom_counter = groom_counter + 1
groom_text_out = groom_text_out & groom_counter & ". " &name & ": " &gift & "<br>"
end if
gift_counter = gift_counter + 1
gift_index_list.add gift_counter, gift
if gift_list.exists(gift) then
if left(gift_list.item(gift),1) = "1" then
one_cut = len(gift_list.item(gift)) - 1
name_list = "1" &name &"<br>"
name_list = name_list + right(gift_list.item(gift), one_cut)
else
name_list = "1" &name &"<br>"
name_list = name_list + gift_list.item(gift)
end if
gift_list.remove(gift)
gift_list.add gift, name_list
else
name_list = name &"<br>"
gift_list.add gift, name_list
end if
flag = inputbox ("Would you like to add another gift? (yes/no)")
Loop
document.write "Gifts on the bride side:" &"<br>"
document.write bride_text_out
document.write "<br>"
document.write "Gifts on the groom side:" &"<br>"
document.write groom_text_out
document.write "<br>"
gift_pointer = 0
gift_pointer2 = 0
gift_name = 0
do while flag1 = 0
gift_pointer2 = gift_pointer2 + 1
gift_pointer = gift_pointer2
gift_name = gift_index_list.item(gift_pointer)
do while record_count > gift_pointer
gift_pointer = gift_pointer + 1
if gift_index_list.item(gift_pointer) = gift_name then
gift_index_list.remove(gift_pointer)
end if
loop
if gift_pointer2 >= record_count then
flag1 = 1
end if
loop
gift_pointer = 1
do while record_count >= gift_pointer
if gift_index_list.item(gift_pointer) <> "" and Left(gift_list.item(gift_index_list.item(gift_pointer)),1) = "1" then
document.write "Multiple " &gift_index_list.item(gift_pointer) &" by:<br>"
length_check = len(gift_list.item(gift_index_list.item(gift_pointer))) - 1
document.write right(gift_list.item(gift_index_list.item(gift_pointer)),length_check)
document.write "<br>"
end if
gift_pointer = gift_pointer + 1
loop
document.write ("<br>Spaghetti-coded by <a href='http://bradlavario.info'>Brad LaVario</a>")
</script>
Okay it didn’t quite fit, but here is a link to it.
note: it will ONLY run in IE (Internet Explorer).

