ByRef & ByVal Code - Program To Execute Properly - Can't Get Them To Add Up And Display The Quantity And Price

Apr 7, 2010

I started this tutorial on sub procedures and am having trouble trying to get this program to execute properly. The problem lies with the total. I am trying to figure out the math part of it. When I hit F5 I can see this

Item Quantity Price.

Pizza Slices
Fries
Soft Drinks

Total

But I can't get them to add up and display the quantity and price. I tried the ByVal and ByRef code but am not sure if I did it right

Here is the code that I have so far:

Public Class Form1

Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCompute.Click

Dim pizza, fries, drinks, total As Double

[CODE]...

View 6 Replies


ADVERTISEMENT

Class -program Where Enter The Description, Price, And Quantity Of An Item, Then Click On The Add Button

Aug 13, 2009

I have to create a program where you enter the description, price, and quantity of an item, then click on the Add button. It will then put the description, price, quantity, and total for that line (including tax) in a listbox. The tax is determined by what you put in a text box labeled tax:. When you press Submit Order, it should show a grand total in a text box called Grand Total. It should have a class that is called Items that has a function called GetTotalAmount() that figures out the total including tax. I have started it, but am having a tough time with how to get the subtotals into the text box, then also show the amount including the tax PLUS then do the grand total.

Heres what I have so far:

CODE:

View 3 Replies

Calculations Using Quantity And Price - Not Getting Right Value

Jun 3, 2011

I got a program I am working on. It does some calculations using quantity and price in such. Heres the calculation module.
Private Sub calculations()
If AdultsizeRadioButton1.Checked = True Then
adulttotaldecimal = quantityinteger * adultpricedecimal * hoursinteger
ElseIf ChildsizeRadioButton2.Checked = True Then
childtotaldecimal = quantityinteger * childpricedecimal * hoursinteger
[Code] .....

Ok, everything has worked when I display the information.... up until the accumprofitdecimal variable. When i display that value its NOT what it should be. For instance i'm putting in a quanity of 1 and an hour of 1 for an adult then for a child, the extended price comes out properly as $2.15 now the code accumprofitdecimal += extendedpricedecimal SHOULD add the extended price (2.15) to the accumulative total. but when i display the accum profit total it shows a number that makes zero sense... is accumprofitdecimal += extendedpricedecimal not correct code?

View 3 Replies

Reciept Printing - Form Which Consist - Item Code , Item Name , Item Price , Quantity Of Item

May 25, 2012

Regarding my college project. i'm working on a sales system . i have a form which consist of all the following information( item code , item name , item price , quantity of item ) which is display using a data grid . data input by user using text box and all this information will be stored in a database(sales database) i'm using ms access 2007. the grand total will be displayed in a text box . and amount paid will be input in a text box too , my major problem now is how to i create a reciept that will have all this information of the purcase. i have a reciept button . what the next step ? i dont have any idea how to get the reciept done.

Imports System.Data.OleDb

Public Class Form5
Dim con As New OleDbConnection

[CODE].......................

View 9 Replies

VB - Calculation - Multiply The Quantity Of An Item By The Price

Mar 12, 2012

I am struggling to write the code for a calculation. The calculation I wish to do is to multiply the quantity of an item by the price. The problem is that the "form" i am creating uses a letter (i.e A, B, C etc) which corresponds to a set value. I do not know how to link the Letter to the corresponding value.

For Example, A= 25, B= 20, C=25

I want to calculate the total of 6 lots of A. I am also using a Combo Box to list the Letters.

View 2 Replies

VS 2008 Calculate Price * Quantity = Cost?

Mar 3, 2010

I certainly hope I don't aggravate you with what is certainly a very simple code problem. I have never programmed before, but I do have a background in tech support, etc. I have an assignment to do and it's frustrating to wade through the information out there to find exactly what I need and nothing more.The assignment has 3 parts, one of which i've done. We are to do the same function in both javascript and VB. I was able to take a sample we did in class that caluclates a 10% discount and modify it so it calculates the total. Now, I have to modify that into a VB sln file. then write about the differences but that part will be cake.

I am working in Visual Studio 2008 - that program is new to me as well. When I created my login and it asked what VB I'm using, I did not know but under theu of VS, it says VB 2008.hat I attempted to do was to take the instructor's sample discount code and modify it for the new purpose, but an error was generated. This is the sample code I started with:

'Programmer: Dan Dougherty
'Date: Feb 2010
'

[code].....

View 14 Replies

Combine And Add The Quantity,Price,Total Of Same Index In Listview?

Oct 9, 2011

Combine and Add the Quantity of same index in listview here's my Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If NumericUpDown1.Text = "" Then
MessageBox.Show("Please Input the Quantity!", "Sale", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
NumericUpDown1.Text = 1
End If

[Code]...

View 7 Replies

When To Use ByVal And ByRef

Nov 17, 2011

I am a student and i get confused when i see a lot of ByRef and ByVal arguments in a sub procedure. Can someone make it simple for me to understand when it should be used?

View 9 Replies

.net - ByRef Vs ByVal Clarification?

Dec 8, 2010

I've read a lot on this, but am having a hard time thinking through this tonight. (Maybe it's the hydrocodone... just had a root canal. i'm just starting on a class to handle client connections to a TCP server. Here is the code I've written thus far:

[Code]...

Now, on my Socket property, when setting the value, it is required to be ByVal. It is my understanding that the instance in memory is copied, and this new instance is passed to value, and my code sets _Socket to reference this instance in memory. Yes?

If this is true, then I can't see why I would want to use properties for anything but native types. I'd imagine there can be quite a performance hit if copying class instances with lots of members. Also, for this code in particular, I'd imagine a copied socket instance wouldn't really work, but I haven't tested it yet.

View 3 Replies

Asp.net - .Net, EventArgs, ByRef And ByVal?

Dec 15, 2011

In VB.Net, I have an object named WorkflowButtonEventArgs that inherits from System.EventArgs.The WorkflowButtonEventArgs class contains two ByRef Properties. These are objects that are in memory, and I do not want them duplicated or copied in any way.

Can I pass the WorkflowButtonEventArgs object ByVal in VB.Net and have it still preserve the two ByRef definitions in WorkflowButtonEventArgs?Specifically, if I pass it ByVal:

Dim e As New WorkflowButtonEventArgs e has some ByRef properties RaiseEvent SomeEventName(e) ' e is passed ByVal Will the ByRef Properties/Members in e (WorkflowButtonEventArgs class) not be copied or duplicated in memory?

Long-story-short: Can I pass e ByVal, or do I need to pass it ByRef since it contains ByRef Properties?

View 3 Replies

Difference Between Byref And ByVal

May 4, 2010

[Code] What is the difference between ByRef and Byval in this function. When i call this function and debug it it shows no difference the two. Can any one explain me actually what happens.

View 8 Replies

Difference Between ByRef And ByVal?

Feb 20, 2009

ByRef (a.k.a. By Reference) points to where the object is in the memory. Any changes made to the object sent ByRef should change the values of the original object ByVal (a.k.a. By Value) points to a copy of the object. Any changes made to the object shouldn't change anything in the original object

Let's make an example:

Private Sub FormLoad()
Dim a As String = "A"
Dim b As String = "B"

[code]...

The second messagebox shows Baaaa - Buuuu instead of the expected A - Buuuu... but why is that? Apparently ByVal and ByRef does exactly the same thing. It seems like it sends the reference to the object when using ByVal, instead of making a new object.

View 2 Replies

Difference Between ByVal And ByRef

Mar 27, 2012

Whenever I'm going to use a new API, I have to decide for each value whether I'm going to use byval or byref. Can someone explain me in what scenarios I should use which and why? Because lacking this knowledge kinda gives me the feeling of having no control over my code.I am aware about the other threads by people asking the same question, I have read them but its still not crystal clear for me.

View 2 Replies

Difference Between ByVal And ByRef?

Jun 5, 2012

I have seen a few people in the past confused on the usage of ByRef & ByVal in a Function/Sub's Signature. I figured i would make a simple example that demonstrates the difference of each.

Option Strict On
Public Class Form1
Dim A As Integer = 100

[code]....

If you want something you've never had, you need to do something you've never done. If you believe something to be true, then one day you will be called upon to demonstrate that truth.

View 10 Replies

Is Not Necesary To Indicate ByVal / ByRef Any More?

Feb 9, 2012

I just installed Visual Studio 2010 Service pack (proposed on Windows Update), and I can see a new feature on the "intellisense" that means when I write a Function or Sub in VB.NET it doesn't auto-complete parameters with ByRef or ByVal...

1) Is there anyway that I can configure this option back to how it was before?

2) If I don't specify ByX, which one is used by default? (it seems like it is always ByRef)

View 2 Replies

What Is The Difference Between ByVal And ByRef

Apr 10, 2009

What is the difference between ByVal and ByRef? Please remember to mark the replies as answers if they help and unmark them if they provide no help.Welcome to the All-In-One Code Framework!

View 5 Replies

ByRef Vs ByVal Generates Errors?

Apr 26, 2010

ByRef vs ByVal generates errors!?I had a method that used an Object Function Foo(ByRef bar as CustomObject) as Boolean this method generated errors, because some strange .NET Runtime things changed the bar object, causing its Dispose()al.A lot of time spent to understand the thing(where the ... object is changed), until somebody replaced ByRef by ByVal and object wasn't change anymore when passing to this method.As in my case the function Foo does NOT modify the bar, shouldn't ByRef or ByVal have the same effect?[code]

View 4 Replies

Is The Return Expression ByRef Or ByVal

Jun 9, 2011

If a function returns a private shared (static) string, or a string declared as a module level variable, is the returned a reference to the shared string's instance or a different string instance having the same value?

View 1 Replies

VS 2008 Passing ByRef Or ByVal?

Jul 23, 2010

I have been working on this for a few days, and I am going around in circles. I can make the program work by including everything in the same sub procedure, but the assignment requires that I do certain tasks by using function procedures.What I need to do is take the contents of a text box, reverse the order of the first and last names, and add them to a list box. I can do that, just not by passing value from a function procedure. Here is my

View 4 Replies

ByRef Vs ByVal Performance When Passing Strings

Jul 22, 2010

Reading [URL] made me wonder whether the comments in there did apply to Strings in terms of performance. Since strings are copied before being passed, isn't it much more efficient (if the callee doesn't need a copy of string course) to pass strings ByRef?

[Code]...

View 1 Replies

Function Return A Value Byref Instead Of The Default Byval?

Jan 18, 2012

Can a function return a value byref instead of the default byval? That is to say, allow me to directly edit the variable that it is retrieving instead of just giving me a copy of that variable.Right now I'm trying to write a function that will return, based on what the user has selected through a combobox, a particular setting (eg. My.Settings.somethingHere). I then want to be able to edit the setting directly through just calling the function. Is that at all possible?

[Code]...

View 1 Replies

Functions Return Values As Byref Or Byval Or?

Oct 20, 2011

i have a strange issue today. Sample code is at the below of the post. The code that i have pointed out is too strange. According to my knowledge using return statement the functions return values as byval and copies the value to the stack. Also how can my class can reach outscope elements and change them. Take a look at to the code below. How this could be?

code
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim b As New ByteClass
Dim sumArray As Long = 0

[Code]...

View 21 Replies

Pass ByRef And ByVal Parameters In Same Routine?

Dec 7, 2010

Is it considered bad practice (VB.NET or any language) to code a function with both ByVal and ByRef parameters as used in my getFile function below?

Function getFile(ByVal channel As Integer, _
ByRef Filename As String, _
ByRef Filesize As String) As Integer
End Function
Dim status As Integer

[Code]...

View 1 Replies

Switching Byref To Byval On Method Calls .NET?

Mar 1, 2010

Switching Byref to Byval on method calls I have many warnings raised due to: "Implicit conversion from xxxx to yyyy in copying the value of 'ByRef' parameter zzzz back to the matching argument."

My feeling is that it would be safe to change the function parameters from byref to byval as nothing special is being done with the reference type pointers inside these methods the reference types are simply being used and I think the behaviour would be exactly the same if running with a copy a pointer rather than the original.

Another consideration is that I have two classes which inherit from a base class. The same situation is occuring in that the byref params are causing implicit casting from the base class to the narrower concrete class. Again I can't see any problems with this code running byval either.Does anyone have any tips regarding use of parameters in functions when dealing with reference types?

Some of the other things that are currently being passed around byref in my project are database connection objects i.e. OracleConnection and SqlConnection. Is there any good reason for passing these around byref?

[Code]...

View 1 Replies

VS 2008 ByVal / ByRef List Parameter

Sep 4, 2010

I have a class OrderManager, that takes a parameter of type LocalFuturesList on construction. Now.. It doesn't seem to matter if I use ByRef or ByVal here.. It still references the parent class instance of it. It also doesn't seem to matter if I type New or omit it.. Probably also because it's just an address reference. But why is it like this? And what type of objects "acts" in this way? Further I find that if I change the object in the parent class by deserializing from a file (with my method call shown), then suddenly this reference is broken in some way, so the OrderManager instance now holds Nothing I believe.If my observations are correct I see two challenges:

1. How to pass a list NOT by reference?

2. How to maintain a list reference through deserialization? [code]

View 17 Replies

VS 2008 Passing Parameters - ByVal/ByRef?

Dec 22, 2010

I have some code that is transforming the coordinates of a line.I want to keep the original coords and I thought passing the line ByVal would be the best way.The original VB6 code used a temporary variable so that the original coords were not updated.I'm confused as when the X & y coords of 'line' are changed 'MyLine' is also changed. I had assumed only 'line' would change and 'MyLine' would remain unchanged'.

Private Sub TransformSaveLine(ByVal MyLine As LineType)
Dim P As Integer
Dim line As LineType
Dim x As Double

[code].....

View 12 Replies

Limit To The Parameters That Can Be Passed ByVal Or ByRef To A Function ?

Jul 2, 2009

Is there a Limit to the parameters that can be passed byVal or byRef to a function or procedure in vb .net ?

[URL]

View 2 Replies

VS 2005 Byref / Byval - Copy The Image Property To A Queue?

Jun 23, 2009

I have a 3rd party (c#) class that raises an event. on accsing this event i want to copy the image property to a queue.

Dim myQ as queue
Private Sub imageprocessor_NewImage() handles camera.NewImage
myQ.Enqueue(imageprocessor.currentimage)
End Sub

But when I view myQ at a later date it tells me the parameters of the images are not valid.Is it adding them by reference?i would have through adding an object to a queue was byval. how can i enforce this?

View 8 Replies

Forms :: Multiplying By Two - Code - Radio Buttons That If Selected Will Display The Price Of A Ticket

Mar 22, 2010

CODE:

Right now i have the following code. it is 4 radio buttons that if selected will display the price of a ticket.

There is a button called "repeat offender" that should take the price and double it. so me, being new to visual basic, were thinking of trying an if statement such as If it is selected decTicketTotal * 2

But this did not work. any help would be appreciated.. just trying to get the repeat offender selection working so when it calculates the price will double.

View 8 Replies

What Are Classes , Objects , A Namespace , Subroutines,functions,methods,properties And Difference Between Byval And Byref

Jun 26, 2010

I want to know what are classes , objects , a namespace , subroutines,functions,methods,properties and differemce betweem byval and byref in your words.

View 18 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved