|
-
Apr 25th, 2010, 10:22 AM
#1
Thread Starter
Fanatic Member
-
Apr 25th, 2010, 10:34 AM
#2
Re: Simple question I can't answer xD
ByVal means to pass a copy of the VALUE of the parameter. This means any changes to the variable is done on the copy, preserving the original.
ByRef means to pass a copy of the ADDRESS (or pointer) to the parameter. Any changes to the variable is then done to the value at that address.
So, in short change
Code:
Testfunc(ByVal Testval As Integer)
to
Code:
Testfunc(ByRef Testval As Integer)
-tg
-
Apr 25th, 2010, 10:36 AM
#3
Thread Starter
Fanatic Member
Re: Simple question I can't answer xD
Thank you! Knew the answer was simple 
Thanks for the fast reply
-
Apr 25th, 2010, 10:43 AM
#4
Fanatic Member
Re: Simple question I can't answer xD
Try changing your code to what's below. You should get the result you're looking for. You weren't setting Testfunc equal to anything in the Function Testfunc and you had Testfunc(testval) in the Button1_Click sub but you weren't setting testval equal to it.
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim testval As Integer = 1
MsgBox("Before: " & testval)
testval = Testfunc(testval)
MsgBox("After: " & testval)
End Sub
Public Overridable Function Testfunc(ByVal Testval As Integer) As Integer
Testfunc = 2
End Function
Or you can have Testfunc(ByRef Testval As Integer) As Integer. You need the function to be decalared as something. If Option Strict is Off you get a warning and if Option Strict is On then it isn't allowed if the function isn't declared as an integer or something.
Last edited by EntityX; Apr 25th, 2010 at 10:54 AM.
 Make as many mistakes as you can as quickly as you can. We want to make sure that we make a great enough number of mistakes in a given amount of time so that we can be successful.
"Persistence is the magic of success." Paramahansa Yogananda
-
Apr 25th, 2010, 10:43 AM
#5
Re: Simple question I can't answer xD
However, you generally have to be returning a value to be using a Function. Since you have no return value, you should be using a Sub. Changing the arguments of a method, while possible, as you can see, is what is known as a side effect. There are situations where a side effect is the only way for the code to work, but they often create trouble, as people don't usually expect a method to alter its parameters.
My usual boring signature: Nothing
 
-
Apr 25th, 2010, 10:44 AM
#6
Re: Simple question I can't answer xD
Well, as I was typing that, EntityX snuck in with an example of what I was saying.
My usual boring signature: Nothing
 
-
Apr 25th, 2010, 11:44 AM
#7
Thread Starter
Fanatic Member
Re: Simple question I can't answer xD
LOL well it was just an example 
This is what I really tried to do:
Code:
Public Function RenderPictureNode(ByRef pnode As PictureNode) As Image
If pnode.ColorChanged = True Then
pnode.ColoredImage = ColorImage(pnode.TextureImage, pnode.Color.A / 255, pnode.Color.R / 255, pnode.Color.G / 255, pnode.Color.B / 255)
End If
If pnode.SizeChanged = True Or pnode.ColorChanged = True Then
pnode.SizedImage = ResizeImage(pnode.ColoredImage, pnode.Size.Width, pnode.Size.Height, True)
End If
If pnode.PosRotChanged = True Or pnode.SizeChanged = True Or pnode.ColorChanged = True Then
pnode.FinalImage = New Bitmap(800, 600)
Dim g As Graphics = Graphics.FromImage(pnode.FinalImage)
g.TranslateTransform(pnode.DRotationMid.X + 400, pnode.DRotationMid.Y + 300)
g.RotateTransform(pnode.DRotation)
g.TranslateTransform((pnode.Position.X + pnode.DOffsetX) - pnode.DRotationMid.X - 400 + pnode.SizedImage.Width * 0.5, (pnode.Position.Y + pnode.DOffsetY) - pnode.DRotationMid.Y - 300 + pnode.SizedImage.Height * 0.5)
g.RotateTransform(pnode.StaticRotation)
g.TranslateTransform(pnode.SizedImage.Width * -0.5, pnode.SizedImage.Height * -0.5)
g.DrawImage(pnode.SizedImage, New Point(0, 0))
g.Dispose()
End If
pnode.SizeChanged = False
pnode.PosRotChanged = False
pnode.ColorChanged = False
Return pnode.FinalImage
End Function
BTW it's for a image-edit like program that supports "nodes".
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|