|
-
Jan 11th, 2013, 01:21 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Change string value from a function?
Is it possible to change the value of a string from a function, because I'm having a problem here?
The general idea would be like below, but the string will not change, so is there any way I make that happen?
vb.net Code:
Public Class Form1 Dim MyItem1, MyItem2, MyItem3 As Integer Public Function SetItemStats(ByVal CurrentItemSlot As ComboBox, ByVal CurrentItemName As String) CurrentItemName = CurrentItemSlot.Text End Function Private Sub SetItem1Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SetItem1Button.Click SetItemStats(item1list, MyItem1) ' item1list is the name of my combobox. MsgBox(MyItem1) ' Comes out empty here End Sub End Class
EDIT: Fixed that by changing ByVal into ByRef, I'm such an idiot.
Last edited by Legjendat; Jan 11th, 2013 at 01:34 PM.
-
Jan 11th, 2013, 01:31 PM
#2
Re: Change string value from a function?
there are 2 problems there:
Code:
Public Function SetItemStats(ByVal CurrentItemSlot As ComboBox, ByVal CurrentItemName As String)
CurrentItemName = CurrentItemSlot.Text
'no return???
End Function
try this instead:
Code:
Public Sub SetItemStats(ByVal CurrentItemSlot As ComboBox, ByRef CurrentItemName As String)
CurrentItemName = CurrentItemSlot.Text
End Sub
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 11th, 2013, 01:36 PM
#3
Thread Starter
Addicted Member
Re: Change string value from a function?
 Originally Posted by .paul.
there are 2 problems there:
Code:
Public Function SetItemStats(ByVal CurrentItemSlot As ComboBox, ByVal CurrentItemName As String)
CurrentItemName = CurrentItemSlot.Text
'no return???
End Function
try this instead:
Code:
Public Sub SetItemStats(ByVal CurrentItemSlot As ComboBox, ByRef CurrentItemName As String)
CurrentItemName = CurrentItemSlot.Text
End Sub
Yeah, changing it into ByRef fixes it. Anyway, is there a problem if I leave it as a function? I know since it doesn't return anything it should be a Sub, but I prefer using the word function instead of sub, or just adding a Return 0 maybe 
Thanks btw.
-
Jan 11th, 2013, 01:40 PM
#4
Re: Change string value from a function?
you can leave it as a function + return an unused value if you add a return type
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 11th, 2013, 01:42 PM
#5
Thread Starter
Addicted Member
Re: Change string value from a function?
Yeah, doing that. Thanks again and marking as solved now.
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
|