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 December 17th, 2012, 09:16 PM
hemihead_dave hemihead_dave is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 8 hemihead_dave User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 17 m 34 sec
Reputation Power: 0
Need Help Changing From a Select Case

I could use some help in changing this code from a select case to a For...Next statement or a If...Then statement, which ever seems easier? I am using VB 2010 Express. I can get the 16.50 processing fee to show in total, but none of the rest. Here is what I need help changing. This code does work, need to consolidate it. PLEASE HELP, I AM SO LOST.

Public Class MainForm

Private Function CalcBusiness(ByVal process1 As Double, ByVal service1 As Double, ByVal price1 As Double) As Double
' add basic charges for business customers to calculate the total of a cable bill

' declare variables
Dim total1 As Double
Dim processingFee As Double = 16.5
Dim serviceFee As Double
Dim premiumChannels As Double
Dim connections As Double
Dim price As Double

' determine the service fee for number of connections
' customers must have at least 1 connection
serviceFee = connectionsListBox.SelectedIndex

Select Case serviceFee
Case 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
connections = 80
Case 10
connections = 84
Case 11
connections = 88
Case 12
connections = 92
Case 13
connections = 96
Case Else
connections = 100
End Select

total1 = processingFee + connections + price
totalDueLabel.Text = total1.ToString("C2")

Return total1

Reply With Quote
  #2  
Old December 17th, 2012, 11:24 PM
hemihead_dave hemihead_dave is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 8 hemihead_dave User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 17 m 34 sec
Reputation Power: 0
Coded using If..Then Statement

I finally figured it out, so I am showing my results. It does work and there may be another way to do it, I am just not sure.


'Cable Direct:


Option Explicit On
Option Strict On
Option Infer On

Public Class MainForm

Private Function CalcBusiness(ByVal process1 As Double, ByVal service1 As Double, ByVal price1 As Double) As Double

Dim total1 As Double
Dim processingFee As Double = 16.5
Dim serviceFee As Double
Dim premiumChannels As Double
Dim connections As Double
Dim price As Double

connections = connectionsListBox.SelectedIndex

If connections >= 10 Then
serviceFee = 80 + 4 * connections - 36
Else
serviceFee = 80
End If

premiumChannels = premiumListBox.SelectedIndex


If premiumChannels = 0 Then
price = 0
Else
price = premiumChannels * 50
End If

total1 = processingFee + serviceFee + price
totalDueLabel.Text = total1.ToString("C2")

Return total1

End Function

Private Function CalcResidential(ByVal process2 As Double, ByVal service2 As Double, ByVal price2 As Double) As Double

Dim total2 As Double
Dim processingFee As Double = 4.5
Dim serviceFee As Double = 30
Dim premiumChannels As Double
Dim price As Double

premiumChannels = premiumListBox.SelectedIndex

If premiumChannels = 0 Then
price = 0
Else
price = premiumChannels * 5.0
End If

total2 = processingFee + serviceFee + price
totalDueLabel.Text = total2.ToString("C2")

Return total2

End Function

Private Sub calcButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles calculateButton.Click
If business.Checked = True Then
Dim processingFee As Double
Dim connections As Double
Dim price As Double

' call a function procedure to perform calculations

Call CalcBusiness(processingFee, connections, price)
Else
Dim processingFee As Double
Dim serviceFee As Double
Dim price As Double

' call a function procedure to perform calculations

Call CalcResidential(processingFee, serviceFee, price)
End If

End Sub

Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
Me.Close()
End Sub

Private Sub clearButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles clearButton.Click
totalDueLabel.Text = String.Empty
End Sub
End Class

Reply With Quote
  #3  
Old January 1st, 2013, 04:25 AM
Incidentals Incidentals is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2010
Posts: 89 Incidentals User rank is First Lieutenant (10000 - 20000 Reputation Level)Incidentals User rank is First Lieutenant (10000 - 20000 Reputation Level)Incidentals User rank is First Lieutenant (10000 - 20000 Reputation Level)Incidentals User rank is First Lieutenant (10000 - 20000 Reputation Level)Incidentals User rank is First Lieutenant (10000 - 20000 Reputation Level)Incidentals User rank is First Lieutenant (10000 - 20000 Reputation Level)Incidentals User rank is First Lieutenant (10000 - 20000 Reputation Level)Incidentals User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Day 4 h 23 m 19 sec
Reputation Power: 156
Quote:
Originally Posted by hemihead_dave
I finally figured it out, so I am showing my results. It does work and there may be another way to do it, I am just not sure.


'Cable Direct:


Option Explicit On
Option Strict On
Option Infer On

Public Class MainForm

Private Function CalcBusiness(ByVal process1 As Double, ByVal service1 As Double, ByVal price1 As Double) As Double

Dim total1 As Double
Dim processingFee As Double = 16.5
Dim serviceFee As Double
Dim premiumChannels As Double
Dim connections As Double
Dim price As Double

connections = connectionsListBox.SelectedIndex

If connections >= 10 Then
serviceFee = 80 + 4 * connections - 36
Else
serviceFee = 80
End If

premiumChannels = premiumListBox.SelectedIndex


If premiumChannels = 0 Then
price = 0
Else
price = premiumChannels * 50
End If

total1 = processingFee + serviceFee + price
totalDueLabel.Text = total1.ToString("C2")

Return total1

End Function

Private Function CalcResidential(ByVal process2 As Double, ByVal service2 As Double, ByVal price2 As Double) As Double

Dim total2 As Double
Dim processingFee As Double = 4.5
Dim serviceFee As Double = 30
Dim premiumChannels As Double
Dim price As Double

premiumChannels = premiumListBox.SelectedIndex

If premiumChannels = 0 Then
price = 0
Else
price = premiumChannels * 5.0
End If

total2 = processingFee + serviceFee + price
totalDueLabel.Text = total2.ToString("C2")

Return total2

End Function

Private Sub calcButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles calculateButton.Click
If business.Checked = True Then
Dim processingFee As Double
Dim connections As Double
Dim price As Double

' call a function procedure to perform calculations

Call CalcBusiness(processingFee, connections, price)
Else
Dim processingFee As Double
Dim serviceFee As Double
Dim price As Double

' call a function procedure to perform calculations

Call CalcResidential(processingFee, serviceFee, price)
End If

End Sub

Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
Me.Close()
End Sub

Private Sub clearButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles clearButton.Click
totalDueLabel.Text = String.Empty
End Sub
End Class


you have fixated on the conditional stuff

look at

Code:
If premiumChannels = 0 Then
            price = 0
        Else
            price = premiumChannels * 5.0
        End If



the expression price=premiumChannels *5.0 is true for all values including zero so why bother with the if at all?

the first if does not need the else you could simply front load the structure and just use an inline if

Code:
If connections >= 10 Then
            serviceFee = 80 + 4 * connections - 36
        Else
            serviceFee = 80
        End If


becomes

Code:
serviceFee=80
if connections >=10 then serviceFee=serviceFee+4*connections-36


although I am not sure of the arithmatic

80+4*connections -36 is the same as 44+4*connections

you could look at the maths a bit more and use boolean logic to control these expressions.

Thats a way of using the truth to add delete or multiply things by 0 or -1 false or true

more info if needed

Hope this helps

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Need Help Changing From a Select Case

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