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.
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.
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
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.
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
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
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
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)
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?
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
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.
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.
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
I didn't know so simple calculator can be made. TY
Why use ByVal at all? Why not just do
private function subtract(num1 as double, num2 as double) as double
return num1 - num2
end function
this is tutorial so that someone like me can learn the basic thing that maybe can be use in big thing.
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.
what if i want characters e.g "a,g,h," instead of numbers as the variable?
instead change it is "As String"
@techstuffs27 double click on "My Project" on the side, and a Windows will open with an Application tab selected. You will find the icon selection.
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.
Good tutorial man! Nice job :)
Yeah, it work exactly the same without the ByVal. Someone explain this to me =="
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
great work....................bro
it is a bad example of byval, coz when i tried to change it to byref, it gave the same result.
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
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
it is pretty good
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)
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?
SCIFIDW Yes. ByVal is useless in the new VB
like a couple numbers of your video style.. You made the some showing same way to show..
ty somuch ur op
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
SIMPLE CALCULATOR ENJOY :D
C++.
10th to caomment...
"where beginner javascript tutorial?"
@fillecool2
Think its
My.computer.audio.Xxxxxxxxxx
Cant remember the rest soz intellisense will know though
hehe
5th yes yes
8th comment! Lol