• Welcome to Valhalla Legends Archive.
 

Creating a Vote Feature

Started by OuTLawZGoSu, January 17, 2004, 12:20 PM

Previous topic - Next topic

OuTLawZGoSu

I got this:

I need to add theusername to the list when "Yes" or "No" is typed.
Exept, when the user types yes or no, nothing happens.


'Vote
'
If username = LoadMaster Then
If Left((LCase(message)), 5) = (LoadTrigger & "vote") Then
Form1.chkVote = vbChecked
AddQueue "Vote: " & (Mid(message, 6, Len(message) - 1))
End If
End If

If username = username And LCase(message) = "yes" Then
   If username = Form1.voteuserchk.FindItem(x) Then
   If Form1.chkVote = vbChecked Then Form1.LbYes.AddItem "Yes"
   End If
   Form1.voteuserchk.ListItems.add 1, , username
End If

If username = username And LCase(message) = "no" Then
   If username = Form1.voteuserchk.FindItem(x) Then
   If Form1.chkVote = vbChecked Then Form1.LbNo.AddItem "No"
   End If
   Form1.voteuserchk.ListItems.add 1, , username
End If

If username = LoadMaster And LCase(message) = "voff" Then
   If Form1.chkVote = vbChecked Then
   Form1.chkVote = vbUnchecked
   Form1.txtYes = Form1.LbYes.ListCount
   Form1.txtNo = Form1.LbNo.ListCount
   AddQueue "Results: " & Form1.txtYes.text & " voted for Yes, " & Form1.txtNo.text & " voted for No."
   Form1.LbYes.Clear
   Form1.LbNo.Clear
   Form1.txtYes.text = ""
   Form1.txtNo.text = ""
   Form1.voteuserchk.ListItems.Clear
End If
End If


Help?

UserLoser.

#1
I don't understand the purpose of "If username = username", it's the same as If 1 = 1

OuTLawZGoSu

#2
Quote from: UserLoser. on January 17, 2004, 02:59 PM
I don't understand the purpose of "If username = username", it's the same as If 1 = 1

That just means If any user type in Yes or No then.

DarkMinion

If you're going to let anybody use it why have an if at all?

ChR0NiC

Just a suggestion.......try using ElseIf ?

OuTLawZGoSu

#5
Quote from: DarkMinion on January 17, 2004, 03:50 PM
If you're going to let anybody use it why have an if at all?

Wow..... aight, its a vote command. Therefore, anyone in the channel must have access to Yes and No ( If username = username Then.... ). Voteoff command is only for the Master ( If username = LoadMaster Then... )

I will try elseif but i doubt it will solve my problem.

Lord-Vegito

elseif wasnt suggested to solve ur problem it was suggested to clean up ur code  :o

Tuberload

#7
Quote from: LoRd]VeGiTo[ on January 19, 2004, 02:55 PM
elseif wasnt suggested to solve ur problem it was suggested to clean up ur code  :o

If you are going suggest ways to clean up his code, my first suggestion would be to use a language that promotes it. My opinion is that VB6 and below doesn't. ;D Upgrade to VB.NET and then decouple the UI from the system. Keep in mind my suggestion is object oriented.
Quote"Pray not for lighter burdens, but for stronger backs." -- Teddy Roosevelt
"Your forefathers have given you freedom, so good luck, see you around, hope you make it" -- Unknown

R.a.B.B.i.T

Quote from: UserLoser. on January 17, 2004, 02:59 PM
I don't understand the purpose of "If username = username", it's the same as If 1 = 1

Reflexive property.

You can make your voting at least 2ms faster by using arrays rather than listviews (or listboxes).

Tuberload

Quote from: R.a.B.B.i.T on January 19, 2004, 06:18 PM
Quote from: UserLoser. on January 17, 2004, 02:59 PM
I don't understand the purpose of "If username = username", it's the same as If 1 = 1

Reflexive property.

You can make your voting at least 2ms faster by using arrays rather than listviews (or listboxes).

That is basically what I was telling him to do... I think the benefits are that it would keep the system and UI separate, allowing for easier maintenance.
Quote"Pray not for lighter burdens, but for stronger backs." -- Teddy Roosevelt
"Your forefathers have given you freedom, so good luck, see you around, hope you make it" -- Unknown

ChR0NiC

Quote from: OuTLawZGoSu on January 17, 2004, 12:20 PM
I got this:

I need to add theusername to the list when "Yes" or "No" is typed.
Exept, when the user types yes or no, nothing happens.


'Vote
'
If username = LoadMaster Then
If Left((LCase(message)), 5) = (LoadTrigger & "vote") Then
Form1.chkVote = vbChecked
AddQueue "Vote: " & (Mid(message, 6, Len(message) - 1))
End If
End If

If username = username And LCase(message) = "yes" Then
   If username = Form1.voteuserchk.FindItem(x) Then
   If Form1.chkVote = vbChecked Then Form1.LbYes.AddItem "Yes"
   End If
   Form1.voteuserchk.ListItems.add 1, , username
End If

If username = username And LCase(message) = "no" Then
   If username = Form1.voteuserchk.FindItem(x) Then
   If Form1.chkVote = vbChecked Then Form1.LbNo.AddItem "No"
   End If
   Form1.voteuserchk.ListItems.add 1, , username
End If

If username = LoadMaster And LCase(message) = "voff" Then
   If Form1.chkVote = vbChecked Then
   Form1.chkVote = vbUnchecked
   Form1.txtYes = Form1.LbYes.ListCount
   Form1.txtNo = Form1.LbNo.ListCount
   AddQueue "Results: " & Form1.txtYes.text & " voted for Yes, " & Form1.txtNo.text & " voted for No."
   Form1.LbYes.Clear
   Form1.LbNo.Clear
   Form1.txtYes.text = ""
   Form1.txtNo.text = ""
   Form1.voteuserchk.ListItems.Clear
End If
End If


Help?

I dunno if this would help but try

If username = username And LCase(message) = LCase("yes") Then


And


If username = username And LCase(message) = LCase("no") Then


Seems like a long shot, but I have had stranger things happen......

Also.....did that ElseIf help at all???

R.a.B.B.i.T

#11
Quote from: ChR0NiC on January 19, 2004, 06:55 PM
I dunno if this would help but try

If username = username And LCase(message) = LCase("yes") Then


And


If username = username And LCase(message) = LCase("no") Then




That is quite pointless, seeing as how when you do LCase("yes") the result, is of course, "yes" (the same is true with "no").  As said previously, username = username is not needed.  All you need is the following:

'// Sub Stuff..this is at the end..
If LCase(Message) = "yes" Then
   If Not Voted(UserName) Then
       Form1.lvVoted.ListItems.Add , , UserName
       Form1.lvVotes.ListItems.Add , , "yes"
   Else
       'Send "/m  " & UserName & " You have already voted."
       ' This is commented because if too many people vote _
         and your queue sucks, it could flood the bot.
   End If
ElseIf LCase(Message) = "no" Then
   If Not Voted(UserName) Then
       Form1.lvVoted.ListItems.Add , , UserName
       Form1.lvVotes.ListItems.Add , , "no"
   Else
       'Send "/m  " & UserName & " You have already voted."
       ' This is commented because if too many people vote _
         and your queue sucks, it could flood the bot.
   End If
End If
End Sub

Public Function Voted(CheckName As String) As Boolean
   Voted = False
   On Error Goto ErrorVote
   Dim c As Integer
   For c = 1 to Form1.lvVoted.ListItems.Count
       If LCase(CheckName) = LCase(Form1.lvVoted.ListItems(c).Text) Then
           Voted = True
           Exit Function
       End If
   Next c
ErrorVote:
End Function


This works a lot better, and a lot quicker, albeit it requires 3 ListViews.

Then, once the vote is over, you can call this:

Public  Function Results() As String
   On Error GoTo ErrReport
   Dim v As Integer, cYes As Integer, cNo As Integer
   For v = 1 To Form1.lvVotes.ListItems.Count
       If Form1.lvVotes.ListItems(v).Text = "yes" Then
           cYes = cYes + 1
       Else
           cNo = cNo + 1
       End If
   Next v
   Results = CStr(cYes) & "ß" & CStr(cNo)
   Exit Function
ErrReport:
   Results = "Error reporting results."
End Function.


I'm prettyr sure you can figure it out from there..

ChR0NiC

I agree, using this would be more efficient and I think he will discover it works.....

hismajesty

Quote from: R.a.B.B.i.T on January 19, 2004, 06:18 PM
Quote from: UserLoser. on January 17, 2004, 02:59 PM
I don't understand the purpose of "If username = username", it's the same as If 1 = 1

Reflexive property.

You can make your voting at least 2ms faster by using arrays rather than listviews (or listboxes).

What would be so wrong with an integer?

R.a.B.B.i.T

Quote from: hismajesty on January 21, 2004, 02:24 PM
Quote from: R.a.B.B.i.T on January 19, 2004, 06:18 PM
Quote from: UserLoser. on January 17, 2004, 02:59 PM
I don't understand the purpose of "If username = username", it's the same as If 1 = 1

Reflexive property.

You can make your voting at least 2ms faster by using arrays rather than listviews (or listboxes).

What would be so wrong with an integer?
"If username = username" doesn't do anything, theres no way the username won't equal the username unless it's changed at the exact moment when the If is in the middle of checking.  That part is 100% useless.