_load

  • Thread starter Thread starter perceval
  • Start date Start date
P

perceval

hi

Why i can't have "hello" in my other sub ..??? the _load is "public "
!!



Public sub menu_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim myString as string = "hello"
end Sub

Private Sub PictureBox4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles PictureBox4.Click
label1.text = myString
End Sub
 
perceval said:
Why i can't have "hello" in my other sub ..??? the _load is "public "
!!

Public sub menu_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim myString as string = "hello"
end Sub

Private Sub PictureBox4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles PictureBox4.Click
label1.text = myString
End Sub

myString is a local variable - it only exists within menu_Load. There
*is* no myString as far as PictureBox4_Click is concerned.
 
Jon Skeet [C# MVP] a pensé très fort :
myString is a local variable - it only exists within menu_Load. There
is no myString as far as PictureBox4_Click is concerned.

ok but if i want to have it... how i can do this?
 
perceval said:
Jon Skeet [C# MVP] a pensé très fort :
myString is a local variable - it only exists within menu_Load. There
is no myString as far as PictureBox4_Click is concerned.

ok but if i want to have it... how i can do this?

You'll need to make it an instance variable.

I think at this stage it would be worth ignoring UIs for the moment,
and learning the basics of VB.NET first with simple console apps. That
way you won't have the difficulties of UI programming on top of the
difficulties of working in an unfamiliar language. Start with some
simple console apps which don't require any input, and work up from
there.
 
put private myString as string = "hello" somewhere outside of a sub or procedure and then it will be accessible from other subs. Jon has a good idea though; start small and work your way up. It'll save lots of time in the end.


--
Brian P. Hammer
hi

Why i can't have "hello" in my other sub ..??? the _load is "public "
!!



Public sub menu_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim myString as string = "hello"
end Sub

Private Sub PictureBox4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles PictureBox4.Click
label1.text = myString
End Sub
 
Back
Top