Polls and Notepad

Posted by Stratus on Thu 13 Mar 2003 03:26 AM — 9 posts, 32,771 views.

#0
sub Poll (thename, theoutput, thewildcards)
dim Name
Name = world.gettriggerinfo (thename, 101)
world.send """Well hello there, " + Name + ". Todays poll is: Who's cooler, Intro or Naveah?"
world.enabletrigger "Vote", TRUE
end sub


sub Vote (thename, theoutput, thewildcards)
dim Name
dim Vote
dim Vote2
dim fVote
dim Intro
dim Naveah
Name = world.gettriggerinfo (thename, 101)
Vote = world.gettriggerinfo (thename, 110)
Vote2 = LCASE(Vote)
fVote = RIGHT(Vote2, 6)
SELECT CASE fVote

Case "intro."
world.send """Your vote has been registered as Intro. #SA"
world.activatenotepad "Poll"
world.appendtonotepad "Poll", "1 | " + Name
world.appendtonotepad "Poll", vbcrlf
world.SaveNotepad "Poll", "c:\Program Files\Mushclient\Poll", 0

Case " intro"
world.send """Your vote has been registered as Intro. #SA"
world.activatenotepad "Poll"
world.appendtonotepad "Poll", "1 | " + Name
world.appendtonotepad "Poll", vbcrlf
world.SaveNotepad "Poll", "c:\Program Files\Mushclient\Poll", 0



Case "aveah."
world.send """Your vote has been registered as Naveah. #SA"
world.activatenotepad "Poll"
world.appendtonotepad "Poll", "2 | " + Name
world.appendtonotepad "Poll", vbcrlf
world.SaveNotepad "Poll", "c:\Program Files\Mushclient\Poll", 0

Case "naveah"
world.send """Your vote has been registered as Naveah. #SA"
world.activatenotepad "Poll"
world.appendtonotepad "Poll", "2 | " + Name
world.appendtonotepad "Poll", vbcrlf
world.SaveNotepad "Poll", "c:\Program Files\Mushclient\Poll", 0

end SELECT
world.enabletrigger "Vote", FALSE
end sub

Now this whole thing works like magic *but* when I exit out of Mushclient or the notepad it refuses to save. So I can't save over sessions. Any solutions?
Australia Forum Administrator #1
What do you mean "it refuses to save"? In what way?

Judging by your code the problem is more that you would need to load it for the next session, otherwise each session would start with a blank notepad window.
#2
Whenever I load the saved file and use the script again it either activates a seperate notepad or it clears the one I had already opened. I was wrong about it not saving, I thought it would save as a .txt file so when I looked for it in the folder I didn't see it.
Australia Forum Administrator #3
The title has to be identical for it to use the same window.

What you might do on a world open (or world connect) which you can add a script for, is to use scripting to read the file into memory (there are examples on the forum), and then use world.appendtonotepad to put that data into the notepad window, ready for new events.
#4
I changed the script to open "c:\program files\mushclient\poll" and now it actually brings up the same file which is an improvement but when I try to append to it it created a new notepad file

sub Connect (thename, theoutput, thewildcars)
open "C:\Program Files\Mushclient\Poll"
world.appendtonotepad "Poll", "Poll: Intro VS. Naveah!"
world.appendtonotepad "Poll", vbcrlf
end sub
Australia Forum Administrator #5
I mean, you have to read the file into memory, and append it to your notepad. See this post:


http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=1297


There is an example sub there "GetFileContents" - use that to get the file into memory, and then append it to the notepad (with world.AppendToNotepad) - then the earlier file will definitely be in the same notepad.
#6
If I did that wouldn't I have to save everything in the notepad back into the file so the next time I opened Mushclient and the file it would read and copy everything back into the notepad again?
#7
Isn't there any way I could just directly append it to the file instead of even using a seperate notepad?
Australia Forum Administrator #8
For storing ad-hoc results like this you might be better off using a database anyway. Look in the plugins section of this forum, there is an example database I did. A little modification of this, and you could store each vote into an Access database. That would be better in the long run than getting a file that is longer and longer. Also, you wouldn't lose votes in the event of a program or Windows crash.