Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 17th, 2007, 9:31 AM   #1
VBuser
Newbie
 
Join Date: Jan 2007
Posts: 3
Rep Power: 0 VBuser is on a distinguished road
Question Plz Help - Visual Basic .net/visual C++ .net Code

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
VBuser is offline   Reply With Quote
Old Jan 17th, 2007, 10:23 AM   #2
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Quote:
Originally Posted by VBuser View Post
It works fine but when i wanna write the same program using visual c++ .net code i get errors.
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?
Arevos is offline   Reply With Quote
Old Jan 17th, 2007, 10:57 AM   #3
melbolt
Professional Programmer
 
melbolt's Avatar
 
Join Date: Feb 2005
Location: PA, USA
Posts: 253
Rep Power: 4 melbolt is on a distinguished road
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
melbolt is offline   Reply With Quote
Old Jan 17th, 2007, 11:11 AM   #4
VBuser
Newbie
 
Join Date: Jan 2007
Posts: 3
Rep Power: 0 VBuser is on a distinguished road
Quote:
Originally Posted by melbolt View Post
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 do know but i wanted the code for c++ .net cause i get errors when coding the calcbutton event
VBuser is offline   Reply With Quote
Old Jan 17th, 2007, 11:50 AM   #5
ReggaetonKing
Sexy Programmer
 
ReggaetonKing's Avatar
 
Join Date: Nov 2005
Location: New Jersey
Posts: 891
Rep Power: 4 ReggaetonKing is on a distinguished road
Send a message via AIM to ReggaetonKing
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!
ReggaetonKing is offline   Reply With Quote
Old Jan 17th, 2007, 11:53 AM   #6
pegasus001
Hobbyist Programmer
 
pegasus001's Avatar
 
Join Date: Nov 2006
Location: 163H
Posts: 215
Rep Power: 3 pegasus001 is on a distinguished road
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.
pegasus001 is offline   Reply With Quote
Old Jan 18th, 2007, 12:42 PM   #7
VBuser
Newbie
 
Join Date: Jan 2007
Posts: 3
Rep Power: 0 VBuser is on a distinguished road
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);
}
it gives error C2664: c:\Documents and Settings\fe\My Documents\Visual Studio Projects\Payroll\Form1.h(366): error C2664: 'System::Windows::Forms::ListBox::ObjectCollection::Add' : cannot convert parameter 1 from 'int' to 'System::Object __gc *'
VBuser is offline   Reply With Quote
Old Jan 18th, 2007, 1:14 PM   #8
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Jan 18th, 2007, 1:23 PM   #9
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
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);
}
Arevos is offline   Reply With Quote
Old Jan 19th, 2007, 1:19 AM   #10
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 1,126
Rep Power: 5 lectricpharaoh will become famous soon enough
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);
@Arevos: If managed C++ is like C#, the int type is probably an alias for System.Int32, so the changed definition would be unnecessary in that case (and fail to resolve the problem). Still, I suppose it's worth a shot, as I don't know if managed C++ behaves this way (never used it; if I'm gonna write managed code, I'll stick to C#, using C++ for native code).
__________________
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
lectricpharaoh is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Compiling Maverik 6.2 (from C) megamind5005 C 16 May 3rd, 2006 6:41 PM
visual basic pixel image comparison youngnoviceinneedofhelp Visual Basic 3 Mar 19th, 2006 2:57 PM
C# is basically Visual Basic with C-style code Josef_Stalin C# 25 Nov 5th, 2005 9:36 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:13 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC