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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
*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
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

LeithauserCommented:
I was trying to keep it simple. No concatinated variables like SomeThing.SomeValue. :-)
0
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
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
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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 TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
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 TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
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 TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.