_load

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
 
J

Jon Skeet [C# MVP]

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.
 
P

perceval

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?
 
J

Jon Skeet [C# MVP]

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.
 
B

Brian P. Hammer

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top