Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 11th, 2013, 08:16 PM
william7 william7 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Posts: 3 william7 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 25 m 29 sec
Reputation Power: 0
IF statement calculation ?

Can anybody give me an idea how to fashion an economical IF statement that will provide for single wins $2.00, double wins $10.00, Half the jackpot, and full jackpot wins for the lottery application below? I realize I could produce a very lengthy piece of code that will cover every conceivable combination of winning, but if there's a shorter way I would rather take it instead.

So far, my code is written for single wins (two matches) and the full jackpot (four matches). Double wins, any combination of two matches, and half the jackpot win which is any combination of three matches will take a lengthy IF statement.

I'm new to VB and programming and in bad need of help on this one.

Code:
Dim selectedItem1 = cboOne.SelectedItem.ToString  
        Dim selectedItem2 = cboTwo.SelectedItem.ToString  
        Dim selectedItem3 = cboThree.SelectedItem.ToString  
        Dim selectedItem4 = cboFour.SelectedItem.ToString  
        
  
        If selectedItem1 = lbl10.Text Then  
  
            lbl10.BackColor = Color.DarkGreen  
            MsgBox("Winner of " & FormatCurrency(SingleWin.ToString))  
  
        End If  
         
  
        If selectedItem2 = lbl20.Text Then  
            lbl20.BackColor = Color.DarkGreen  
            MsgBox("Winner of " & FormatCurrency(SingleWin.ToString))  
  
  
        End If  
  
        If selectedItem3 = lbl30.Text Then  
            lbl30.BackColor = Color.DarkGreen  
            MsgBox("Winner of " & FormatCurrency(SingleWin.ToString))  
  
  
        End If  
  
        If selectedItem4 = lbl40.Text Then  
            lbl40.BackColor = Color.DarkGreen  
            MsgBox("Winner of " & FormatCurrency(SingleWin.ToString)) 
  
        End If

 If selectedItem1 = lbl10.Text And selectedItem2 = lbl20.Text And  
 selectedItem3 = lbl30.Text And selectedItem4 = lbl40.Text Then  
        lbl10.BackColor = Color.DarkGreen  
        lbl20.BackColor = Color.DarkGreen  
lbl30.BackColor = Color.DarkGreen  
        lbl40.BackColor = Color.DarkGreen  
         MsgBox("JackPot!!")  
  
         End If


URL

Reply With Quote
  #2  
Old March 12th, 2013, 05:00 PM
couttsj couttsj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2011
Posts: 179 couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 22 h 13 m 30 sec
Reputation Power: 43
It is more stream lined if you use control arrays. The following is in VB6, but you get the idea. There are four labels and four combo boxes configured as control arrays. The combo box lists are preloaded with strings "One" to "Ten", and the lblWin box is made visible and flashes at different rates upon a win.
Code:
Private Sub cmdPlay_Click()
    Dim WinCount As Integer
    Dim N%
    Const SingleWin As String = "$100.00"
    Const DoubleWin As String = "$300.00"
    Const TripleWin As String = "$500.00"
    Const JackPot As String = "$1000.00"
    Randomize
    Timer1.Enabled = 0
    lblWin.Visible = False
    For N% = 0 To 3
        Label1(N%).BackColor = &H8000000F
        Label1(N%) = Combo1(N%).List(Int(10 * Rnd))
    Next N%
    For N% = 0 To 3
        If Combo1(N%).Text = Label1(N%).Caption Then
            Label1(N%).BackColor = &HFF00&     'Color.DarkGreen
            WinCount = WinCount + 1
        End If
    Next N%
    Select Case WinCount
        Case 0
            lblWin.Visible = False
        Case 1
            lblWin.Caption = SingleWin
            lblWin.Visible = True
            Timer1.Interval = 1000
            Timer1.Enabled = True
        Case 2
            lblWin.Caption = DoubleWin
            lblWin.Visible = True
            Timer1.Interval = 500
            Timer1.Enabled = True
        Case 3
            lblWin.Caption = TripleWin
            lblWin.Visible = True
            Timer1.Interval = 250
            Timer1.Enabled = True
        Case 4
            lblWin.Caption = JackPot
            lblWin.Visible = True
            Timer1.Interval = 100
            Timer1.Enabled = True
    End Select
End Sub

Private Sub Timer1_Timer()
    lblWin.Visible = Not lblWin.Visible
End Sub


J.A. Coutts

Reply With Quote
  #3  
Old March 16th, 2013, 08:47 AM
william7 william7 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Posts: 3 william7 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 25 m 29 sec
Reputation Power: 0
Thanks for this info! This is valuable information for me on using arrays which I'm currently unfamiliar with.

Reply With Quote
  #4  
Old March 29th, 2013, 06:44 PM
GGriggs GGriggs is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 18 GGriggs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 45 m 43 sec
Reputation Power: 0
test for wins

e.g

number_of_wins = 0

for xxx= 1 to number_0f_chances
'code which works out if this is a win
if this_is_ a_ win then
number_of_wins = number_of_wins + 1
end if
next xxx

if number_of_wins = 4 then
msgbox "You've hit the jackpot"
end if

(Can also use Case statement - but that is not always more elegant)

'etc etc

if number_of_wins = 0 then
msgbox "Hey man you suck!"
end if

Reply With Quote
  #5  
Old March 30th, 2013, 08:53 AM
william7 william7 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Posts: 3 william7 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 25 m 29 sec
Reputation Power: 0
Yes, this fits the pattern of what my instructor showed me the solution was the other day. I turned in this assignment awhile ago. Fortunately, it was only worth ten points towards my grade.

Reply With Quote
  #6  
Old April 1st, 2013, 02:56 AM
ismaelriley ismaelriley is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2013
Posts: 1 ismaelriley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 46 sec
Reputation Power: 0
Thanks for the info guys.... i was also looking for the same!!...thx!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > IF statement calculation ?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap