Results 1 to 8 of 8

Thread: [RESOLVED] Problem with Arry's.

  1. #1

    Thread Starter
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Resolved [RESOLVED] Problem with Arry's.

    Hi All,

    I've tryed to create some arrays, but it didn't worked.

    That's my array for my PictureBoxes:

    VB Code:
    1. Dim arr As PictureBox() = {PictureBox1, PictureBox2, PictureBox3}

    It gave me the error : Name 'PictureBox2' is not declared.
    Name 'PictureBox3' is not declared.

    What I'm doing wrong here!
    Read also from the beginning because I'm still trying to create.

    Thanks in advance,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Problem with Arry's.

    You would have to have created the PictureBoxes themselves in the designer first.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: Problem with Arry's.

    Hi jmc,

    That wasn't the intention to create several PictureBoxes in the designer.

    It's for a calculation app.

    I want just one PictureBox and the possibility to load several Pictures in it.

    After I loaded a Picture I want to controle it.

    Example: I have a Picture with 5 cars then the user has to put 5 into a textBox.

    If the answer is correct then Next Picture.....

    That's why I thougth to use an Array.
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Problem with Arry's.

    In that case you just need to create an array that CAN hold a certain number of PictureBoxes. The way you have done it you are trying to initialise the array as well. If you want an array that can hold 5 PictureBoxes then declare the variable and create the array but do not initialise it:
    VB Code:
    1. Dim arr(4) As PictureBox
    Note that without specifying the upper bound you are simply creating a variable of type PictureBox(). By specifying the upper bound the actual array object will be created with enough room to hold the number of objects that you specify. Each element is basically a variable of type PictureBox, but there are no PictureBox objects at this stage. Remember that .NET arrays are reference type objects, i.e. instances of the Array class.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Problem with Arry's.

    Reading what you wrote again, are you sure that you aren't confusing a PictureBox with an Image? A PictureBox is a control in which you can display an Image. If you're only displaying one image at a time then you should only need one PictureBox and simply change its Image property.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: Problem with Arry's.

    Quote Originally Posted by jmcilhinney
    Reading what you wrote again, are you sure that you aren't confusing a PictureBox with an Image? A PictureBox is a control in which you can display an Image. If you're only displaying one image at a time then you should only need one PictureBox and simply change its Image property.
    Yes I know how to display an Image into a PictureBox, but how can I control each picture then into my TextBox.
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Problem with Arry's.

    Quote Originally Posted by sparrow1
    Yes I know how to display an Image into a PictureBox, but how can I control each picture then into my TextBox.
    I'm afriad I don't really know what you mean.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: Problem with Arry's.

    Quote Originally Posted by jmcilhinney
    I'm afriad I don't really know what you mean.
    Hi jmc,

    It could be that I made it to difficult to explain, but like I wrote in the beginning of this thread, I wanted to control an Image!

    But anyway, I found it!!!!
    I know there are other ways to do it, but it works for me!
    Here's my code:

    VB Code:
    1. Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         Dim arr(2) As PictureBox
    3.         Button2.Visible = False
    4.     End Sub
    5.  
    6.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    7.         ChangeImage()
    8.         Button2.Visible = True
    9.  
    10.     End Sub
    11.     Private Sub ChangeImage()
    12.         Static Dim iImage As Integer
    13.  
    14.         Select Case iImage
    15.             Case 0
    16.                 PictureBox.Visible = True
    17.                 PictureBox.Image = Image.FromFile(Application.StartupPath & "\Image\blablabla.jpg")
    18.                 TextBox1.Focus()
    19.                 Button1.Visible = False
    20.                 iImage += 1
    21.             Case 1
    22.                 PictureBox.Visible = True
    23.                 PictureBox.Image = Image.FromFile(Application.StartupPath & "\Image\blablabla.jpg")
    24.                 TextBox1.Focus()
    25.  
    26.                 iImage += 1
    27.             Case 2
    28.                 PictureBox.Visible = True
    29.                 PictureBox.Image = Image.FromFile(Application.StartupPath & "\Image\blablabla.jpg")
    30.                 TextBox1.Focus()
    31.  
    32.                 iImage += 1
    33.             Case 3
    34.                 PictureBox.Visible = False
    35.                 Label1.Visible = True
    36.                 iImage = 0
    37.         End Select
    38.     End Sub
    39.     Private Sub CheckImage()
    40.         Static Dim iImage As Integer
    41.  
    42.         Select Case iImage
    43.             Case 0
    44.                 If Not TextBox1.Text = "17" Then
    45.                     MsgBox("Sorry ! You made a Mistake !", MsgBoxStyle.OKOnly, )
    46.                     TextBox1.Text = ""
    47.                     TextBox1.Focus()
    48.                 Else
    49.                     MsgBox("Congratulations ! It's Correct !", MsgBoxStyle.OKOnly, "PERFECT")
    50.                     TextBox1.Text = ""
    51.                     Button1.Visible = True
    52.                     Button2.Visible = False
    53.                     iImage += 1
    54.                 End If
    55.             Case 1
    56.                 If Not TextBox1.Text = "47" Then
    57.                     MsgBox("Sorry ! You made a Mistake !", MsgBoxStyle.OKOnly, )
    58.                     TextBox1.Text = ""
    59.                     TextBox1.Focus()
    60.                 Else
    61.                     MsgBox("Congratulations ! It's Correct !", MsgBoxStyle.OKOnly, "PERFECT")
    62.                     TextBox1.Text = ""
    63.                     Button1.Visible = True
    64.                     Button2.Visible = False
    65.                     iImage += 1
    66.                 End If
    67.             Case 2
    68.                 If Not TextBox1.Text = "24" Then
    69.                     MsgBox("Sorry ! you made a Mistake !", MsgBoxStyle.OKOnly, )
    70.                     TextBox1.Text = ""
    71.                     TextBox1.Focus()
    72.                 Else
    73.                     MsgBox("Congratulations! It's correct !", MsgBoxStyle.OKOnly, "PERFECT")
    74.                     TextBox1.Text = ""
    75.                     Button1.Visible = True
    76.                     Button2.Visible = False
    77.                     iImage += 1
    78.                 End If
    79.             Case 3
    80.                 PictureBox.Visible = False
    81.                 Label1.Visible = True
    82.                 iImage = 0
    83.         End Select
    84.     End Sub
    85.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    86.         CheckImage()
    87.     End Sub
    88.  
    89. End Class

    I'm very pleased, thanks for your help!

    Wkr,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width