Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,222 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,219 people online right now. Registration is fast and FREE... Join Now!




Nested Rep Structure-additonal questions

 
Reply to this topicStart new topic

Nested Rep Structure-additonal questions

liquid198
4 Nov, 2007 - 09:04 PM
Post #1

New D.I.C Head
*

Joined: 22 Oct, 2007
Posts: 29


My Contributions
wonderous me again.. and im at it again and i need help.. so maybe i can sleep..
i want a application that will allow the sales mgr to enter the compansy income and expense amounts..It may vary each time the app is started. For example the user may enter five income accounts and 3 expense accounts. or 20 and 30. the app should display the total income.. expense.. and profit or loss.use the input function to get the individual income and expense amounts. use rep structure to determine to help accumlate the total income and toal expense. also use a counter to determine how many times the loop was processed/ use messageboxes to display message.

diplays amounts with decimals.. dollar signs..heres my code.. i so fudged up.. help




CODE


Private Sub calcButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

        Dim salescount As Integer
        Dim total As Decimal



        'repeat as long as user enters in a numeric value



        Do While salescount <> ""
            If IsNumeric(salescount) Then
                salescount = salescount + 1
                total = total + Convert.ToDecimal(total)
            Else
                MessageBox.Show("The amount must be numeric. ", " Premium Paper", _
            MessageBoxButtons.OK, MessageBoxIcon.Information)




            End If
            'get sales amount from user


            salesamount = InputBox(" Please enter a amount.Click Cancel to end.", _
                "Sales Amount", "0")

        Loop

        'if greater than zero go thur loop


        If salescount > 0 Then
            total = salescount + salescount
            Me.xMessageLabel.Text = salescount.ToString("C2")
        Else
            Me.xMessageLabel.Text = 0
            MessageBox.Show("No sales amount were entered. ", "Premium Paper Company", _
            MessageBoxButtons.OK, MessageBoxIcon.Information)




This post has been edited by liquid198: 5 Nov, 2007 - 05:38 AM
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Nested Rep Structure-additonal Questions
4 Nov, 2007 - 10:29 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,660



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Hi liquid,

The solution is pretty simple if you think about it. You setup a loop where you first ask the user for an amount up front. If they entered a value, check if it is numeric. If it is, add to our counter and add the amount entered to the total.

Then prompt for the next value and start all over again until they either enter a blank or hit cancel. Then you just see if they entered any amounts via the counter and spit out the results.

Below I have put the basics which will get you started collecting your income accounts. All you have to do is repeat the process for your expense accounts. At the end when it is time to show the profit or loss, you can take the variable total from this example and subtract the expense total from it to get the profit/loss. Then throw on a dollar sign and you are good to go.

CODE

Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
        Dim salescount As Integer = 0
        Dim total As Decimal = 0D
        Dim salesamount As String

        ' Ask the user for a sales amount
        salesamount = InputBox(" Please enter an amount. Click Cancel to end.", "Sales Amount", "0")

        ' Loop until they enter a blank or hit cancel
        Do While salesamount <> ""
                ' If value is numeric, add to counter and add sales amount to total
                If IsNumeric(salesamount) Then
                        salescount = salescount + 1
                        total = total + Convert.ToDecimal(salesamount)
                Else
                        MessageBox.Show("The amount must be numeric. ", " Premium Paper", MessageBoxButtons.OK, MessageBoxIcon.Information)
                End If

                ' Get next sales amount from user
                salesamount = InputBox(" Please enter a amount. Click Cancel to end.", "Sales Amount", "0")
        Loop


        ' If sales were entered, display the number of accounts and the total.
        ' Otherwise show that no accounts were entered.

        If salescount > 0 Then
                Me.xMessageLabel.Text = salescount.ToString()
                MessageBox.Show("Number of accounts: " & salescount.ToString() & " and amount total is: " & total.ToString())
        Else
                Me.xMessageLabel.Text = 0
                MessageBox.Show("No sales amount were entered. ", "Premium Paper Company", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
End Sub


The only other note I have for you is that you need to keep track of your data types. You were attempting to dump a string into an integer value. Remember InputBox returns a string, not an integer.

Enjoy the code!

"At DIC we be account collecting coding ninjas!" decap.gif
User is offlineProfile CardPM
+Quote Post

liquid198
RE: Nested Rep Structure-additonal Questions
5 Nov, 2007 - 04:41 AM
Post #3

New D.I.C Head
*

Joined: 22 Oct, 2007
Posts: 29


My Contributions
any ideas on a interface.. im stuck.. and not sure.. if all i have is a label.. income: and a textbox.. cal,clear, exit.. and a message label.. and little picture box up top and a label to say "name of company sales form"
User is offlineProfile CardPM
+Quote Post

liquid198
RE: Nested Rep Structure-additonal Questions
5 Nov, 2007 - 04:48 AM
Post #4

New D.I.C Head
*

Joined: 22 Oct, 2007
Posts: 29


My Contributions
[code] wouldnt i put this in the forms load procedure.. because its not popping up..

' Ask the user for a sales amount
salesamount = InputBox(" Please enter an amount. Click Cancel to end.", "Sales Amount", "0")
User is offlineProfile CardPM
+Quote Post

liquid198
RE: Nested Rep Structure-additonal Questions
5 Nov, 2007 - 06:19 PM
Post #5

New D.I.C Head
*

Joined: 22 Oct, 2007
Posts: 29


My Contributions
anyone?
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Nested Rep Structure-additonal Questions
5 Nov, 2007 - 06:54 PM
Post #6

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Moved to VB.Net Forum smile.gif
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Nested Rep Structure-additonal Questions
5 Nov, 2007 - 09:07 PM
Post #7

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,319



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
The problem here is the conditional statement in your while loop.
CODE

Do While salescount <> ""


salescount is an Integer data type, so your while loop will never execute because you are trying to compare an integer to a empty string. This will always evaluate to false.

Also, InputBox is going to return a string, not an Integer type.

Check out the code that Martyr2 already supplied to you. It holds all your answers and will provide a lot of guidance.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 05:47AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month