![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jan 2007
Posts: 3
Rep Power: 0
![]() |
Hi! Plz help anyone!!! I wrote this program from a visual basic .net book. It works fine but when i wanna write the same program using visual c++ .net code i get errors. Im using Visual studio.net 2003
Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click
Me.Close()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim intHours, intAllow As Integer, sngRate As Single
' display hours worked
For intHours = 1 To 50
Me.HoursList.Items.Add(intHours)
Next intHours
'display pay rates
For sngRate = 6 To 12 Step 0.5
Me.RateList.Items.Add(Format(sngRate, "standard"))
Next sngRate
'display witholding allowances
For intAllow = 0 To 10
Me.AllowList.Items.Add(intAllow)
Next intAllow
'select default item in each list box
Me.HoursList.SelectedItem = 40
Me.RateList.SelectedIndex = 0
Me.AllowList.SelectedIndex = 0
End Sub
Private Sub CalcButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CalcButton.Click
Dim intHours As Integer
Dim sngRate, sngGross, sngFWT, sngFICA, sngNet As Single
'assign selected items to variables
intHours = Me.HoursList.SelectedItem
sngRate = Me.RateList.SelectedItem
'calculate gross pay
If intHours <= 40 Then
sngGross = intHours * sngRate
Else
sngGross = 40 * sngRate + (intHours - 40) * sngRate * 1.5
End If
'calculate FWT
sngFWT = GetFwtTax(sngGross)
'calculate fica tax
sngFICA = sngGross * 0.0765
'round gross pay, fwt and fica tax
sngGross = Math.Round(sngGross, 2)
sngFWT = Math.Round(sngFWT, 2)
sngFICA = Math.Round(sngFICA, 2)
'calculate net pay
sngNet = sngGross - sngFWT - sngFICA
'display calculated amounts
Me.GrossLabel.Text = Format(sngGross, "currency")
Me.FWTLabel.Text = Format(sngFWT, "currency")
Me.FICALabel.Text = Format(sngFICA, "currency")
Me.NetLabel.Text = Format(sngNet, "currency")
End Sub
Private Function GetFwtTax(ByVal sngWeekPay As Single) As Single
Dim intAllow As Integer, sngTaxWages, sngTax As Single
'assign number of witholding allowances to a variable
intAllow = Me.AllowList.SelectedItem
'calculate taxable wages
sngTaxWages = sngWeekPay - intAllow * 55.77
'determine marital status then calculate FWT
If Me.SingleRadio.Checked = True Then
Select Case sngTaxWages
Case Is <= 51
sngTax = 0
Case Is <= 552
sngTax = 0.15 * (sngTaxWages - 51)
Case Is <= 1196
sngTax = 75.15 + 0.28 * (sngTaxWages - 552)
Case Is <= 2662
sngTax = 255.47 + 0.31 * (sngTaxWages - 1196)
Case Is <= 5750
sngTax = 709.93 + 0.36 * (sngTaxWages - 2662)
Case Else
sngTax = 1821.61 + 0.396 * (sngTaxWages - 5750)
End Select
Else 'marriedradio is selected
Select Case sngTaxWages
Case Is <= 124
sngTax = 0
Case Is <= 960
sngTax = 0.15 * (sngTaxWages - 124)
Case Is <= 2023
sngTax = 125.4 + 0.28 * (sngTaxWages - 960)
Case Is <= 3292
sngTax = 423.04 + 0.31 * (sngTaxWages - 2023)
Case Is <= 5809
sngTax = 816.43 + 0.36 * (sngTaxWages - 3292)
Case Else
sngTax = 1722.55 + 0.396 * (sngTaxWages - 5809)
End Select
End If
'return FWT
Return sngTax
End Function
Private Sub ClearLabels(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles NameTextBox.TextChanged, HoursList.SelectedValueChanged, _
RateList.SelectedValueChanged, AllowList.SelectedValueChanged, _
MarriedRadio.Click, SingleRadio.Click
Me.GrossLabel.Text = ""
Me.FWTLabel.Text = ""
Me.FICALabel.Text = ""
Me.NetLabel.Text = ""
End Sub
Private Sub NameTextBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles NameTextBox.Enter
Me.NameTextBox.SelectAll()
End Sub
End Class |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
It usually helps to mention (a) what the errors are, and (b) show people the code causing the errors. How on Earth is anyone meant to tell what's wrong with your program if you don't show the source code or what errors occurred?
|
|
|
|
|
|
#3 |
|
Hobbyist Programmer
|
I hope you know this but...
C++ .NET is not VB .NET big syntax difference there just a few examples (semicolons, no "dim", etc, etc) you're pretty much going to have to re-write the whole thing if you want to run it in C++.
__________________
I have never let my schooling interfere with my education. -Mark Twain- Xbox live gamertag: melbolt |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Jan 2007
Posts: 3
Rep Power: 0
![]() |
I do know but i wanted the code for c++ .net cause i get errors when coding the calcbutton event
|
|
|
|
|
|
#5 |
|
Sexy Programmer
|
Then post your code you wrote in C++ and we will do our best.
__________________
I would love to change the world, but they won't give me the source code! |
|
|
|
|
|
#6 |
|
Hobbyist Programmer
Join Date: Nov 2006
Location: 163H
Posts: 213
Rep Power: 2
![]() |
Have you imported the right libraries. Because if you did everything should work fine. It is not difficult to translate between .NET languages. But you must know something else, if you want to compile the code in visual studio you must compile it with /clr(in the console) or enable the clr in the project options.
__________________
You never test the depth of a river with both feet. The believer is happy. The doubter is wise. Free speech carries with it some freedom to listen. The next generation will always surpass the previous one. It`s one of the never ending cycles of life. |
|
|
|
|
|
#7 |
|
Newbie
Join Date: Jan 2007
Posts: 3
Rep Power: 0
![]() |
Well its not a console appliction, its a windows form app. And if u look at the VB code at the top, the calcButton event at the for loop, by trying to write the same thing with c++ code, it gives errors
int hours
for(hours=1; hours<=50; hours++)
{
this->HoursListBox->Items->Add(hours);
} |
|
|
|
|
|
#8 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
The error message is pretty clear. Check the prototype for Add and explicitly convert 'hours' to an object of that type. You might consider resorting to your help files, using the term, "C2664". Just a thought.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#9 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
I haven't done much work with the C++ .NET interface, but you probably have to do something like:
System::Int32 hours;
for(hours=1; hours<=50; hours++)
{
this->HoursListBox->Items->Add(hours);
} |
|
|
|
|
|
#10 |
|
Caffeinated Neural Net
![]() Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,007
Rep Power: 5
![]() |
You might need to explicitly 'box' the int. I'm not sure if VC++ boxes and unboxes stuff automagically, whereas C# does (which has good and bad sides). Try casting it to System::Object first, like so:
this->HoursListBox->Items->Add((System::Object)hours);
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot. - Vaarsuvius, Order of the Stick |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Compiling Maverik 6.2 (from C) | megamind5005 | C | 16 | May 3rd, 2006 5:41 PM |
| visual basic pixel image comparison | youngnoviceinneedofhelp | Visual Basic | 3 | Mar 19th, 2006 1:57 PM |
| C# is basically Visual Basic with C-style code | Josef_Stalin | C# | 25 | Nov 5th, 2005 8:36 AM |