-
Jun 23rd, 2015, 01:53 PM
#1
Thread Starter
Lively Member
[RESOLVED] Please help vs 2012
Hi Guys,
I recently posted a thread trying to get help loading my combo box. I have already gotten that part figured out based on the tips I got yesterday. (Thanks if you left a comment on my previous thread) My issue now is trying to get my "calculate" button code to actually calculate what I need it to calculate.
This is my form. What I need my code to tell my form what to do is: When the user selects a specific rate class number (Combo-box is loaded from the Access Database I created) and hits its resident status I need for based on what the rate class is and the resident status is as well as what they enter for their rec. amounts I need it to calculate and put the output number in the Estimated fee text box. The calculation is [Estimate = (((NumofRec - 2000)/ 1000) * RateThous) + MinFee] This will be done in the background but the the numbers that are filled in for the RateThous and Min Fee are based upon which radio button is chosen and which number is selected from the combo-box. Also the numbers that correspond with the RateThous and MinFee are located in the Access database that I have created.......HELP!! PLEASE!!!...Thanks In Advance!!
BTW There are 17 different numbers to choose from in the combo box and the numbers change based on if the person is a resident or not. For example if I select 1 from the combo box, select Resident from the Radio buttons, and type 80,000 for the Receipt Amount then it should calculate like this:
((((80000-2000)/1000)*$1.35) + 65.00) = $170.30
If I select 1 from the combo box, select NonResident from the Radio buttons, and type 80,000 for the Receipt Amount then it should calculate like this:
((((80000-2000)/1000)*$2.70)+130.00) = $340.60
If someone thinks it is smarter to use two combo boxes instead of the radio buttons and the combo boxes then let me know I am open to changing things!
-
Jun 23rd, 2015, 06:28 PM
#2
Fanatic Member
Re: Please help vs 2012
something like this, bare in mind there is no error trapping for non numbers like blank or letters below, i also have no idea what data is in the combobox im assuming its the amount of that rate
Code:
dim numRec as integer = txtNumReciepts.Text
dim rateclass as integer = combobox1.selecteditem.tostring
dim total as decimal
if checkbox1.checked = true then
total = (((numRec - 2000)/1000) * rateclass) + 65
elseif checkbox2.checked = true then
total = (((numRec - 2000)/1000) * rateclass) + 130
end if
total = format(total,"0.00")
txtFee.text = total
My CodeBank Submissions
- Listbox with transparency and picture support - Click Here
- Check for a true internet connection - Click Here
- Open Cash drawer connected to receipt printer - Click Here
- Custom color and size border around form - Click Here
- Upload file to website without user logins, includes PHP - Click Here
- List All Removable USB Storage Devices - Click Here
- Custom On/Off Slide Control - Click Here
- Insert multiple rows of data into one database table using parameters - Click Here
- Trigger USB/Serial Cash Drawer - Click Here
-
Jun 24th, 2015, 07:08 AM
#3
Thread Starter
Lively Member
Re: Please help vs 2012
Originally Posted by bensonsearch
something like this, bare in mind there is no error trapping for non numbers like blank or letters below, i also have no idea what data is in the combobox im assuming its the amount of that rate
Code:
dim numRec as integer = txtNumReciepts.Text
dim rateclass as integer = combobox1.selecteditem.tostring
dim total as decimal
if checkbox1.checked = true then
total = (((numRec - 2000)/1000) * rateclass) + 65
elseif checkbox2.checked = true then
total = (((numRec - 2000)/1000) * rateclass) + 130
end if
total = format(total,"0.00")
txtFee.text = total
Thank You...and in the combo box there are numbers ranging from 1-17...The numbers represent what "rate class" a resident or nonresident is in. This will determine what values are to be used in the calculation to give the fee estimate to that person.
-
Jun 24th, 2015, 08:02 AM
#4
Thread Starter
Lively Member
Re: Please help vs 2012
Originally Posted by bensonsearch
something like this, bare in mind there is no error trapping for non numbers like blank or letters below, i also have no idea what data is in the combobox im assuming its the amount of that rate
Code:
dim numRec as integer = txtNumReciepts.Text
dim rateclass as integer = combobox1.selecteditem.tostring
dim total as decimal
if checkbox1.checked = true then
total = (((numRec - 2000)/1000) * rateclass) + 65
elseif checkbox2.checked = true then
total = (((numRec - 2000)/1000) * rateclass) + 130
end if
total = format(total,"0.00")
txtFee.text = total
This is my code under my calculate button and it is not calculating right and I am getting errors. I have a combo box and a set of radio buttons on my form. In the radio buttons I have 17 different options and the radio buttons are "Resident" and "NonResident" I need help getting my code to add the different values that need to be plugged into the equation when you click the calculate button. So For example,
If I select 1 from the combo box, select Resident from the Radio buttons, and type 80,000 for the Receipt Amount then it should calculate like this:
((((80000-2000)/1000)*$1.35) + 65.00) = $170.30
BUT
If I select 1 from the combo box, select NonResident from the Radio buttons, and type 80,000 for the Receipt Amount then it should calculate like this:
((((80000-2000)/1000)*$2.70)+130.00) = $340.60
OR IF I
Select 2 from the combo box, select Resident from the Radio buttons, and type 90,000 for the Receipt Amount then it should calculate like this:
((((90000-2000)/1000)*$1.45) + 70.00) = $197.60
If I select 2 from the combo box, select NonResident from the Radio buttons, and type 80,000 for the Receipt Amount then it should calculate like this:
((((90000-2000)/1000)*$2.90)+140.00) = $395.20
BTW I have an access database with the values in it. So essentially the person should be able to chose their rate class number from the combo-box and select if they are a resident or nonresident. Theses two options will determine what numbers to feel in for the equation and the only number they will manually enter in is their receipt amounts.
Code:
Option Strict On
Option Explicit On
Imports System.IO
Imports System.Data.OleDb
Public Class frmCalculateYourFee
Inherits System.Windows.Forms.Form
Dim gobjInputData As New ArrayList
'Database Global Variables
Dim gobjOleDbConnection As OleDbConnection
Dim gobjOleDbCommand As OleDbCommand
Dim gblnTrace As Boolean = False
Dim gWhichDBMS As String = "Access".ToUpper
Private Sub btnReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click
'This event handler is executed when the user clicks the Reset button. When clicked this button
'will clear all information entered into the form.
txtFeeEstimate.Text = ""
cboRateClass.Text = ""
txtReceiptAmt.Text = ""
txtReceiptAmt.Focus()
'Change the Id to readonly
cboRateClass.Enabled = True
cboRateClass.SelectedIndex = 0
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
'This event handler is executed when the user clicks the Exit button.
'When clicked this button will close the window and terminate the application.
Me.Close()
End Sub
Private Sub linklblFindYourRateClass_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles linklblFindYourRateClass.LinkClicked
Try
VisitLink()
Catch ex As Exception
' The error message
MessageBox.Show("Unable to open link that was clicked.")
End Try
End Sub
Sub VisitLink()
' Change the color of the link text by setting LinkVisited
' to True.
linklblFindYourRateClass.LinkVisited = True
' Call the Process.Start method to open the default browser
' with a URL:
System.Diagnostics.Process.Start("http://cityofgreer.org/departments/building_and_development_standards.php")
End Sub
Private Sub frmCalculateYourFee_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Building connection string for the database
Dim strConnectionString As String
If gWhichDBMS.ToUpper = "Oracle".ToUpper Then
strConnectionString = _
"Provider=MSDAORA;" & _
"Data Source=XE;User Id=system;Password=ims"
ElseIf gWhichDBMS.ToUpper = "Oracle64".ToUpper Then
strConnectionString = _
"Provider=OraOLEDB.Oracle.1;" & _
"Data Source=XE;User Id=system;Password=ims"
ElseIf gWhichDBMS.ToUpper = "Access".ToUpper Then
strConnectionString = _
"Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=LicenseFee.accdb"
ElseIf gWhichDBMS.ToUpper = "Sql server".ToUpper Then
strConnectionString = _
"PROVIDER=SQLOLEDB;" & _
"SERVER=LB-245-I;TRUSTED_CONNECTION=Yes"
ElseIf gWhichDBMS.ToUpper = "Sql Express".ToUpper Then
strConnectionString = _
"PROVIDER=SQLOLEDB;" & _
"SERVER=\SQLEXPRESS;TRUSTED_CONNECTION=Yes"
Else
MessageBox.Show("Invalid DBMS . . . " & ControlChars.NewLine & gWhichDBMS, _
"Error Window")
End
End If
'Connecting to database and load the combo box!!!!
'Will display message and end program if an error occurs
Dim objOleDbDataReader As OleDbDataReader
Dim strSQL As String
Dim intIdx As Integer = 0
strSQL = "SELECT RateClass" & _
" FROM RateClassSchedule"
Try
gobjOleDbConnection = New OleDbConnection(strConnectionString)
gobjOleDbCommand = New OleDbCommand
gobjOleDbCommand.Connection = gobjOleDbConnection
gobjOleDbCommand.Connection.Open()
MessageBox.Show("Successfully connected to " & gWhichDBMS & "!!!!!", "Connection Window")
gobjOleDbCommand.CommandText = strSQL
objOleDbDataReader = gobjOleDbCommand.ExecuteReader
'If the objOleDbDataReader is Nothing, then an error occurred.
If IsNothing(objOleDbDataReader) Then
MessageBox.Show("Ending the program . . . ", "Status Window")
End
End If
Do While (objOleDbDataReader.Read())
'Use the SCHEMA Attribute NAMES to retrieve the data from the returned object
cboRateClass.Items.Add(Convert.ToString(objOleDbDataReader.Item("RateClass")))
Loop
cboRateClass.SelectedIndex = 0
MessageBox.Show("Successfully loaded Rate Class Index!!!!", "Status Window")
'Must close the reader so a different query can be submitted
objOleDbDataReader.Close()
Catch objException As Exception
MessageBox.Show("Error connection to the database." & ControlChars.NewLine & _
objException.Message, "Error Window")
End
End Try
End Sub
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
'Declare Variables
Dim objOleDbDataReader As OleDbDataReader
Dim strSQL As String
Dim strRateClass As String
Dim strMissingSelection As String = "Missing Selection"
Dim strSelectResidentStatusError As String = "Select Your Resident Status"
Dim strSelectRateClassError As String = "Select Your Rate Class"
If cboRateClass.SelectedIndex = -1 Then
MessageBox.Show("Please Select a Rate Class!!")
Exit Sub
Else
strRateClass = Convert.ToString(cboRateClass.SelectedItem)
End If
strSQL = "SELECT RateClass, ResidentMinFee, NonResidentMinFee, ResidentRateThou, NonResidentRateThou" & _
" FROM RateClassSchedule" & _
"RateClass = '" & strRateClass.Trim & "'"
If gblnTrace Then
MessageBox.Show("Select Query" & ControlChars.NewLine & _
strSQL, "Submitted Query Window")
End If
Try
gobjOleDbCommand.CommandText = strSQL
objOleDbDataReader = gobjOleDbCommand.ExecuteReader
'If the objOleDbDataReader is Nothing, then an error occurred.
If IsNothing(objOleDbDataReader) Then
MessageBox.Show("Ending the program . . . ", "Status Window")
End
ElseIf objOleDbDataReader.HasRows = False Then
MessageBox.Show("Contact Business License Department For Your Fee!!!!", "Status Window")
Else
Do While (objOleDbDataReader.Read())
'Change the Id to readonly
cboRateClass.Enabled = False
Loop
MessageBox.Show("The information was successfully retrieved!!!!", "Status Window")
End If
'Must close the reader so a different query can be submitted
objOleDbDataReader.Close()
Catch objException As Exception
MessageBox.Show("Error loading the results of the query " & ControlChars.NewLine & _
objException.Message, "Error Window")
Exit Sub
Dim decReceiptAmt, decRate, decMinFee As Decimal
Dim dblFeeEstimate As Double
If cboRateClass.SelectedValue = 1 And RadResident.Checked = True Then
dblFeeEstimate = ((((decReceiptAmt - 2000) / 1000) * 1.35) + 65.0)
dblFeeEstimate = Convert.ToDouble(txtFeeEstimate)
End If
'Declare Variables
Dim decReceiptAmt As Decimal
Dim decFeeEstimate As Decimal
Dim decRate As Decimal
Dim decMinFee As Decimal
Dim strResidentMinFee, strNonResidentMinFee, strResidentRateThou, strNonResidentRateThou As String
strResidentMinFee = Convert.ToString(txtFeeEstimate.Text)
strNonResidentMinFee = Convert.ToString(txtFeeEstimate.Text)
strResidentRateThou = Convert.ToString(txtFeeEstimate.Text)
strNonResidentRateThou = Convert.ToString(txtFeeEstimate.Text)
'The formula for the Resident Business License Fees
decFeeEstimate = ((((decReceiptAmt - 2000) / 1000) * decRate) + decMinFee)
If cboRateClass.SelectedIndex = 1 Then
decFeeEstimate = ((((decReceiptAmt - 2000) / 1000) * decRate) + decMinFee)
End If
End Try
Dim intnumRec As Integer
Dim intrateclass As Integer
Dim dblFeeEstimate As Double
intnumRec = Convert.ToInt32(txtReceiptAmt.Text)
intrateclass = ConvertToInt32(cboRateClass.SelectedItem)
dblFeeEstimate = Convert.ToDouble(txtFeeEstimate.Text)
If RadResident.Checked = True Then
dblFeeEstimate = ((((intnumRec - 2000) / 1000) * intrateclass) + 65)
ElseIf RadNonResident.Checked = True Then
dblFeeEstimate = ((((intnumRec - 2000) / 1000) * intrateclass) + 130)
End If
End Sub
Private Sub txtReceiptAmt_TextChanged(sender As Object, e As EventArgs) Handles txtReceiptAmt.TextChanged
cboRateClass.Enabled = False
End Sub
Private Function ConvertToInt32(p1 As Object) As Integer
Throw New NotImplementedException
End Function
End Class
-
Jun 24th, 2015, 06:34 PM
#5
Fanatic Member
Re: Please help vs 2012
that looks awfully complex. do am i right in thinking you have this data in an access database?
rate class | resident min fee | non-resident min fee | resident rate | non-resident rate
if so then below should work fine
Code:
Dim sql As String = ""
Dim dbProvider As String
Dim dbSource As String
Dim da As New OleDb.OleDbDataAdapter
Dim con As New OleDb.OleDbConnection
Dim ds As New DataSet
dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
dbSource = "Data Source=LicenseFee.accdb;"
con.ConnectionString = dbProvider & dbSource
If RadResident.Checked = True Then
sql = "SELECT ResidentMinFee, ResidentRateThou FROM RateClassSchedule WHERE RateClass = '" & combobox1.selecteditem.tostring & "'"
Else
sql = "SELECT NonResidentMinFee, NonResidentRateThou FROM RateClassSchedule WHERE RateClass = '" & combobox1.selecteditem.tostring & "'"
End If
con.Open()
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "test")
con.Close()
Dim max As Integer = ds.Tables("test").Rows.Count
If max < 0 Then
'no possible rate returned
Exit Sub
Else
Dim numRec As Double
If IsNumeric(txtNumReciepts.Text) Then
numRec = txtNumReciepts.Text
Else
'not a number
End If
Dim rateclass As Integer
If IsNumeric(ds.Tables("test").Rows(0).Item(1).ToString) Then
rateclass = ds.Tables("test").Rows(0).Item(1).ToString
Else
'not a number
Exit Sub
End If
Dim minfee As Double
If IsNumeric(ds.Tables("test").Rows(0).Item(0).ToString) Then
minfee = ds.Tables("test").Rows(0).Item(0).ToString
Else
'not a number
Exit Sub
End If
Dim total As Decimal
total = (((numRec - 2000) / 1000) * rateclass) + minfee
total = Format(total, "0.00")
txtFee.text = total
End If
My CodeBank Submissions
- Listbox with transparency and picture support - Click Here
- Check for a true internet connection - Click Here
- Open Cash drawer connected to receipt printer - Click Here
- Custom color and size border around form - Click Here
- Upload file to website without user logins, includes PHP - Click Here
- List All Removable USB Storage Devices - Click Here
- Custom On/Off Slide Control - Click Here
- Insert multiple rows of data into one database table using parameters - Click Here
- Trigger USB/Serial Cash Drawer - Click Here
-
Jun 24th, 2015, 06:37 PM
#6
Re: Please help vs 2012
Originally Posted by bensonsearch
that looks awfully complex. do am i right in thinking you have this data in an access database?
rate class | resident min fee | non-resident min fee | resident rate | non-resident rate
if so then below should work fine
Code:
Dim sql As String = ""
Dim dbProvider As String
Dim dbSource As String
Dim da As New OleDb.OleDbDataAdapter
Dim con As New OleDb.OleDbConnection
Dim ds As New DataSet
dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
dbSource = "Data Source=LicenseFee.accdb;"
con.ConnectionString = dbProvider & dbSource
If RadResident.Checked = True Then
sql = "SELECT ResidentMinFee, ResidentRateThou FROM RateClassSchedule WHERE RateClass = '" & combobox1.selecteditem.tostring & "'"
Else
sql = "SELECT NonResidentMinFee, NonResidentRateThou FROM RateClassSchedule WHERE RateClass = '" & combobox1.selecteditem.tostring & "'"
End If
con.Open()
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "test")
con.Close()
Dim max As Integer = ds.Tables("test").Rows.Count
If max < 0 Then
'no possible rate returned
Exit Sub
Else
Dim numRec As Double
If IsNumeric(txtNumReciepts.Text) Then
numRec = txtNumReciepts.Text
Else
'not a number
End If
Dim rateclass As Integer
If IsNumeric(ds.Tables("test").Rows(0).Item(1).ToString) Then
rateclass = ds.Tables("test").Rows(0).Item(1).ToString
Else
'not a number
Exit Sub
End If
Dim minfee As Double
If IsNumeric(ds.Tables("test").Rows(0).Item(0).ToString) Then
minfee = ds.Tables("test").Rows(0).Item(0).ToString
Else
'not a number
Exit Sub
End If
Dim total As Decimal
total = (((numRec - 2000) / 1000) * rateclass) + minfee
total = Format(total, "0.00")
txtFee.text = total
End If
isnumeric?
-
Jun 24th, 2015, 07:17 PM
#7
Fanatic Member
Re: Please help vs 2012
Originally Posted by ident
isnumeric?
yeah..... tests if it has a number.....
My CodeBank Submissions
- Listbox with transparency and picture support - Click Here
- Check for a true internet connection - Click Here
- Open Cash drawer connected to receipt printer - Click Here
- Custom color and size border around form - Click Here
- Upload file to website without user logins, includes PHP - Click Here
- List All Removable USB Storage Devices - Click Here
- Custom On/Off Slide Control - Click Here
- Insert multiple rows of data into one database table using parameters - Click Here
- Trigger USB/Serial Cash Drawer - Click Here
-
Jun 24th, 2015, 07:45 PM
#8
Re: Please help vs 2012
which has no place in vb.net. its vb6 code that calls Double.Parse.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|