Carry text string over several win-forms vb.net

Hi Experts,

I'm trying to carry a text string value over several win forms:

1. Form 1: Contact form with multiple Text-boxes. Textbox1 = name. Button1= 'Save' = stream write to text file (textbox1value = file-name.
2. Form 2: Label1.text = form1.Textbox1.text.. etc. Next button
3. Form 3: Label1.text = form1.Textbox1.Text... etc. 'Open' button = StreamReader = file 'Label1' name....

I'm trying to create a profile which is either added to or opened as i go through form 1/2/3/4/5/6/7/8...etc.

I've used a similar method in the passed were you get a value from form2, and loads it into form1.... but I wish to continue through the forms... like an application or journey.

Thanks,
Roberto
RobertoFreemanoAsked:
Who is Participating?
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
For Leithauser's approach, add a MODULE (Project --> Add Module) and make the variable PUBLIC:

    Module Module1

        Public MyString As String

    End Module

Now you can do in Form1:

    MyString = Text1.Text

And in Form2 you can follow that with:

    Label1.Text = MyString

------------------------------------------------------------------------------------------------------------------

For my approach, you would do:

    Public Class Class_prof

        Public Shared user As String

    End Class

To assign the value in Form1:

    Class_prof.user = TextBox1.Text

In Form2, you can read it back out with:

    Label1.Text = Class_prof.user
0
 
Prafull RanjanTechnical LeadCommented:
Here I'm trying to explain a solution, hope It will be helpful
step 1. need to identify fields on form 1, who's value should be available to next form..then define a class with proper datatype for these fields.
- on application start, create a global object of the defined class.
step 2.As soon as you moved to form 1, on any event like btnSave event/page_load event,access that globally created object and move form 1's fields value to the properties of that class.
step 3. when you are on form 2, on laod access this object and assign value to form 2 controls.Same methodlogy for form 3 page load l.
0
 
LeithauserCommented:
Just create a Global (or you can use the keyword Public) string variable in any module in your program (note that it must be a module, not a form). For example,
Global MyString as String
Then put the value into this string when it is input, such as
MyString = Text1.Text
and you can access it from anywhere in the program.
 
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Mike TomlinsonMiddle School Assistant TeacherCommented:
*Technically, it can be a Form or Class if you use the "Shared" keyword.

    Public Class SomeThing
        Public Share SomeValue As String
    End Class

Now you just use the class name, followed by the variable name (without the "New" keyword):

    SomeThing.SomeValue = "value"

This can be done from anywhere.
0
 
LeithauserCommented:
I was trying to keep it simple. No concatinated variables like SomeThing.SomeValue. :-)
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
But that's the best named variable...ever!  =)
0
 
RobertoFreemanoAuthor Commented:
Hi Guys,

Thanks for your prompt reply.

Leithauser, My VB skills are quite poor... I tried your method (but I'm not sure I followed it correct)...

Private MyString as String (in the top for Form1) & ('MyString = Text1.Text)... and retyped it into Form2... nothing happened :(

Idle_Mind, I created a class:
Public Class Class_prof
        Public Share user As String
    End Class

I'm getting 'not declared' when i add: 'Textbox1.text = user

IT'S ME - ISN'T IT :(
0
 
RobertoFreemanoAuthor Commented:
okay, I tried both methods - no result on form2 - Arrrrgggghhhhhhh

IT'S GOTTA ME!!!!!
0
 
RobertoFreemanoAuthor Commented:
here is my process:
form1.JPG
0
 
RobertoFreemanoAuthor Commented:
here is my process:
form2.JPG
0
 
RobertoFreemanoAuthor Commented:
here is my process:
class.JPG
0
 
RobertoFreemanoAuthor Commented:
here is my process:
form1-code.JPG
0
 
RobertoFreemanoAuthor Commented:
here is my process:
form2-code.JPG
0
 
RobertoFreemanoAuthor Commented:
Leithauser, As you can see, there is a Module1 in there too... ;)

I tried both.... I bet it has something to do with the form show method :(
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You need to set the variable BEFORE you show Form2 as it attempts to read that value in the Load() event:

    Class_prof.user = TextBox1.Text ' <-- set the value before Form2 is shown
    Dim frm2 As New Form2
    frm2.Show()
0
 
RobertoFreemanoAuthor Commented:
Thanks Idle_Mind....brb ;)
0
 
LeithauserCommented:
I see forms and a class but no modules in what you have posted.
Put the
Global SharedString As String
or
Public SharedString as String
in a plain old module. These have an extension of bas.
If you do that, any value put in  SharedString will be shared by everything in your program.
 
0
 
RobertoFreemanoAuthor Commented:
Thanks Guys ;)
0
 
RobertoFreemanoAuthor Commented:
Hi Idle_Mind,

Do you think you could answer this question? "How to increase checkbox size?"... This is another question I have open ;)

Thanks again,
Roberto
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
I don't know the answer to that one bud...sorry.
0
 
LeithauserCommented:
Can you point me to it? I would be willing to take a look.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.