Link to home
Start Free TrialLog in
Avatar of MBHEY131
MBHEY131

asked on

reference variable instances

here's my code:
Public Class frmMain

    Private Sub btnShopRO_Click(sender As Object, e As EventArgs) Handles btnShopRO.Click

        Dim sform As New frmShopHandMain
        sform.Show()

    End Sub
End Class

Open in new window

there is other code there but I condensed it to the pertinent data.
sform variable opens and app starts fine however I would like to know the best way to access  this variable instance of update some text boxes when I launch another form from the sform instance (I don't want to make in a GLOBAL VARIABLE or anything close to that)
I would like to know the best way to declare the FORM variable and keep it as narrow instance as possible.
 I am trying to understand the FRIEND, PROTECTED FREIND, etc. access levels but would like some input as this is my first incursion to this coding area.
Avatar of F P
F P
Flag of United States of America image

By definition, the variable scope of your subroutine is Private. That means that the variables you're creating are only going to be seen within that private method, within that class. You pretty much have only a couple options aside from going global.

Local storage on the client side with a cookie, session storage on the server side with a server side cookie, or throw it into a database field and access it again when you need.
Avatar of MBHEY131
MBHEY131

ASKER

Local storage on the client side with a cookie,

++++++++++++++++++++++++++++++++++++++
that sounds like the best option in that I have been down the Global route before and learned some painful lessons
could you give me some instruction (very general would be fine) as I need to learn this -

or in this case as my project is going to be on a server - and thus many clients will be launching the app from the server - is staying away from GLOBAL a wise idea (as I don't even like that word)

any advice would be appreciated
I have been looking into:
"Shared sform as frmshophandmain"  declared in the form level would not serve my purpose I don't believe
You need to make sure you've declared the include for HttpCookieCollection and have a look here about how to use Response.Cookie and Request.Cookie to access, create, and general usage of client side storage in ASP.NET:

How to work with Client-Side State Management in ASP.NET:
http://mrbool.com/how-to-work-with-client-side-state-management-in-asp-net/26364

ASP.NET State Management Recommendations:
https://msdn.microsoft.com/en-us/library/z1hkazw7%28v=vs.140%29.aspx
Unless you're using another .NET technology, in which case client side storage is still an option.
Avatar of Fernando Soto
Hi MBHEY131;

Visual Basic allows you to get a reference to a form by first getting a collection of FormCollection using the Application.OpenForms Property then you can find the form by name by using then FormCollection.Item Property (String) of the FormCollection.
Visual Basic allows you to get a reference to a form by first getting a collection of FormCollection using the Application.OpenForms Property then you can find the form by name by using then FormCollection.Item Property (String) of the FormCollection.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Yes, I'm familiar with the above Property and use it to check for an open instance.

e.g. - "If Application.OpenForms().OfType(Of frmShopHandMain).Count > 0 Then", etc
but how to I access the open instance by the variable "sform" and then reference the textboxes on the said form
without going GLOBAL

============================================================================================
Let me ask this:
Is it possible to DIM "sform" in a new block and set it equal to (my.application.openforms oftype(frmshophandmain))
or something similar.
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
perfect:
I will test FIRST thing in the AM
That worked perfectly and solved all current issues
Thanx a bunch
thanx again
Not a problem MBHEY131, glad I was able to help.