|
-
Jul 19th, 2009, 09:33 PM
#1
Thread Starter
Junior Member
Variable/String assignment
How can I save/assign a string so that I can recall it in different windows? Dim doesn't work and I can't find anything else. Thanks
Second part of thread split into its own thread here
Last edited by Hack; Jul 20th, 2009 at 06:23 AM.
-
Jul 19th, 2009, 09:38 PM
#2
Re: Variable/String assignment
 Originally Posted by crazymao
How can I save/assign a string so that I can recall it in different windows? Dim doesn't work and I can't find anything else.
Dim does what it does and nothing else. Dim declares a variable. Passing data to a form is just like passing data to any other object. You would generally need the data assigned to a variable first, and that variable would need to be declared with the Dim key word.
There's a link in my signature that provides information on passing data between forms.
 Originally Posted by crazymao
PS: If someone knows a good tutorial on how to make a chat can you please show me? (this has nothing to do with the original question)
And therefore there's absolutely no reason to post it in this thread. One thread per topic and one topic per thread please. In future please take the extra 10 seconds required to create a new thread for a new question.
-
Jul 19th, 2009, 09:38 PM
#3
New Member
Re: Variable/String assignment
Use Public in place of Dim.
For instance, use Public MyString As String
And if that was called in Form1, you'd refer to it in other forms as Form1.MyString.
Beaten to it... :P
-
Jul 19th, 2009, 09:45 PM
#4
Thread Starter
Junior Member
Re: Variable/String assignment
 Originally Posted by jmcilhinney
In future please take the extra 10 seconds required to create a new thread for a new question.
i'm sorry. i know i should have done that but i thought that people would say that i post too much
and thanks for your help
 Originally Posted by CaptainDingo
Use Public in place of Dim.
For instance, use Public MyString As String
And if that was called in Form1, you'd refer to it in other forms as Form1.MyString.
Beaten to it... :P
thanks but i get an error saying that public is not valid on a local variable declaration
Last edited by crazymao; Jul 19th, 2009 at 09:53 PM.
-
Jul 19th, 2009, 11:13 PM
#5
Re: Variable/String assignment
In a procedure you can only use Dim or Static to declare a variable. If you're wanting to 'save' it's value then you would have to declare it at the class level.
vb.net Code:
Public Class Form1 'Declare here Public s As String Public Sub SomeMethod() End Sub End Class
Edit: here's a link to Access Modifiers since they tie together.
Last edited by ForumAccount; Jul 19th, 2009 at 11:20 PM.
-
Jul 20th, 2009, 03:10 PM
#6
Thread Starter
Junior Member
Re: Variable/String assignment
 Originally Posted by ForumAccount
In a procedure you can only use Dim or Static to declare a variable. If you're wanting to 'save' it's value then you would have to declare it at the class level.
vb.net Code:
Public Class Form1 'Declare here Public s As String Public Sub SomeMethod() End Sub End Class
Edit: here's a link to Access Modifiers since they tie together.
ok thanks, but is there a command like that which i can enter into a private sub?
EDIT: The error i keep getting is: '...' is not valid on local variable declaration. so what i'm looking for is a valid local variable declaration besides Dim which I can use/recall in multiple forms
Last edited by crazymao; Jul 20th, 2009 at 03:29 PM.
-
Jul 20th, 2009, 04:26 PM
#7
Re: Variable/String assignment
you can't ... it's a LOCAL variable... if you need to use it outside the sub, then it needs to be declared out side the sub.... further, if it is needed outside the form,, then you need to use Public so that it can be used outside the form....
-tg
-
Jul 20th, 2009, 05:00 PM
#8
Thread Starter
Junior Member
Re: Variable/String assignment
 Originally Posted by techgnome
you can't ... it's a LOCAL variable... if you need to use it outside the sub, then it needs to be declared out side the sub.... further, if it is needed outside the form,, then you need to use Public so that it can be used outside the form....
-tg
i tried that but it doesnt work for what i want to do. i want to make it so that when the user presses a button it saves whatever is in textbox1.text to a variable or string which can be recalled in another form. but i cant do what youre proposing for an action of a button
-
Jul 20th, 2009, 05:05 PM
#9
Re: Variable/String assignment
Did you read the link I gave you?
vb.net Code:
Public Class Form1 Public MyAccessibleVariable As String = String.Empty Public Sub ButtonClick(sender blah blah...) Handles blah MyAccessibleVariable = MyButton1.Text End Sub End Class Public Class Form1 Public Sub SomeMethod() 'Assuming Form1 is instantiated MessageBox.Show(Form1.MyAccessibleVariable) End Sub End Class
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
|