|
-
Aug 4th, 2003, 05:52 PM
#1
Thread Starter
Frenzied Member
How can you create public variables that all forms can read? *resolved*
I tried
Public zText as String in form1, but form2 cant read it (undeclared)
what am i doing wrong?
Last edited by VaxoP; Aug 5th, 2003 at 01:22 AM.
-
Aug 4th, 2003, 06:01 PM
#2
Hyperactive Member
You need to create a public class so that it becomes a shared member: as in:
Public Class Result
Public Shared Msg As String
End Class
then in one form:
Result.msg = "set to my values"
and in the other form interrogating the string
my string = result.msg
You do not need to create an instance of the class, it is there for any other class / form to use and the Public Shared can be anything you want, even an object. Take the time to read up on shared members, one of the most useful aspects of VB .Net
-
Aug 4th, 2003, 10:17 PM
#3
Thread Starter
Frenzied Member
no luck..
at the bottom of the code in form1 i have this
End Class 'End form1's class
Public Class Result
Public Shared InfoAbout As String
End Class
and then on a listview doubleclick i have
Dim Frm3 As New Form3()
Result.InfoAbout = LVW.SelectedItems.Item(0).Text
Frm3.Show()
and in form3 load, i have
MsgBox(Result.InfoAbout)
i get a blank string..
-
Aug 5th, 2003, 12:36 AM
#4
How can you have a selecteditem before you've even shown the form?
-
Aug 5th, 2003, 12:58 AM
#5
Thread Starter
Frenzied Member
Originally posted by Edneeis
How can you have a selecteditem before you've even shown the form?
wha?
VB Code:
End Class 'End form1's class
Public Class Result
Public Shared InfoAbout As String
End Class
This is the code used to create the public class. the 'end class' at the beginning shows form1's end class - it just demonstrates i put the new class after the form1 class.
VB Code:
Dim Frm3 As New Form3()
Result.InfoAbout = LVW.SelectedItems.Item(0).Text
Frm3.Show()
this code is in form1, on a listview double click i load up form3. i want to send the selected item text variable to form3 so it can read it.
this is the code in form3's form_load. it msgboxes an empty string.
-
Aug 5th, 2003, 01:21 AM
#6
Thread Starter
Frenzied Member
got it
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
|