That depends on what the function does. A function could need a string to output, or to manipulate, but it would return an integer. An example is a function that gets the length of a string, you would pass a string as an argument, but it would return an integer.
ByVal - " Specifies that an argument is passed in such a way that the called procedure or property cannot change the value of a variable underlying the argument in the calling code." - MSDN
He means that, you can pass arguments of any type even if it's different than the function's type. Function's type is the type of data that it returns, argument's type is the type of argument that is passed to the function.
Stranger error, but its an annoying one I did this perfectly fine and I had no errors it works. I re open the project the code still works however some of it is underlined in red? EDIT: Okay this is happening on like everything now, even on things like Console.ReadLine it keeps underlining them in red when its fine and it is working OK I don't know what has happened but it is extremely annoying. I need to do screenshots for evidence but I can't with this there and there is nothing wrong with the code. The thing the error keeps saying is "Option Strict On disallows implicit conversions from String to Integer" This error has never come up for me before until the past hour or so I don't know if I have turned on a setting somewhere or what
assume variable "input"=10 assume a function named "newFunction" that increments the argument 1) using myVar i.e. newFunction(myVar x as integer) bla bla --> x +=1 newFunction(input) the result will be 11 console.writeline(input) the result will pe 10 2) using myRef i.e. newFunction(myRef x as integer) bla bla --> x +=1 newFunction(input) the result will be 11 console.writeline(input) the result will pe 11
MessageBox.Show("It's also a good idea to try doing things on your own without the tutorials. I've learned alot as well without watching the tutorials", "My Comment",MessageBoxButtons.OK)
Private Function Divide(ByVal num1 As Double, ByVal num2 As Double) Return num1 / num2 End Function Private Function Multiply(ByVal num1 As Double, ByVal num2 As Double) Return num1 * num2 End Function Private Function Subtract(ByVal num1 As Double, ByVal num2 As Double) Return num1 - num2 End Function End Class
ByVal isn't even needed in VB 2013, and I have done outcome comparisons and nothing changes. It's useless, and Microsoft kept ByVal there. It must change something that we know nothing about. Or maybe it really doesn't do anything Edit:It's official: ByVal is rendered useless in Visual Basic on Visual Studio 2013
***** Sorry if this is a stupid question but I'm very new to programming. So you mean we can remove ByVal and it would work without replacing it with something?
I still don't understand what ByVal does. Does is dim the variables outside the function? Cause you didn't dim num1 and num2 in sub but function. Also, the perimeter (TextBox1.text, TextBox2.text) confuses me allot.
Could anybody tell me if textbox.text return number value or string? if it return a string, why we can pass this string to the arguments of double datatype in subtractNumbers function? sorry my English isn't good. i'm learning it.
Sorry for the 5 year late reply, Textbox.text returns any value depending on the variable you want to display in the textbox. So, if you want to display a string in the textbox, thats fine. Works with an Integer as well as doubles.
Public Class Form1 Private Sub BtnSubtract_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSubtract.Click Dim Answer As Double = Subtract(TextBox1.Text, TextBox2.Text) MessageBox.Show(Answer) End Sub