4 Replies - 1149 Views - Last Post: 11 January 2014 - 08:09 AM Rate Topic: -----

#1 venomv1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 07-September 13

Matching the Value of User Input to Picturebox Value in an array

Posted 06 January 2014 - 09:28 AM

*I have attached the program at the bottom*

I am recreating battleship in Visual Basic 6, and I am almost complete. The one part that I am unable to complete, is matching an input value to the value of the picturebox. To better explain...

I have 100 Pictureboxes in a control array, and the ships are placed among the 100 spots based off of a generated number. Now, the program is singleplayer instead of multiplayer, so the objective of the game is to find the ships. In order to find the ships, the user is required to input the column value and a row value, which is added together to represent a picturebox in the array. For example, Column 4, row six would be i=53. From there, I wanted the program to use that to check the value of the picture1(i) to see if there was a small, medium, or large ship within that picturebox.

My problem is that I am having trouble matching the value that is inputted from the user to the picturebox in the array to check if any ship or part of a ship is in that picturebox. Also, if the user input value matches a picturebox that contains a piece of a ship, how do I eliminate all of the pieces of that ship?

Thank You for time.

Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: Matching the Value of User Input to Picturebox Value in an array

#2 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3460
  • View blog
  • Posts: 11,727
  • Joined: 12-December 12

Re: Matching the Value of User Input to Picturebox Value in an array

Posted 06 January 2014 - 02:20 PM

Quote

My problem is that I am having trouble matching the value that is inputted from the user to the picturebox in the array to check if any ship or part of a ship is in that picturebox.

What trouble are you having? That is, please explain your question clearly.

I haven't downloaded your application and most people will be reluctant to. You are more likely to receive assistance if you post the specific code relevant to your question directly here in the forum. This is preferred anyway because links eventually break and then your thread will not be meaningful, or helpful, to anyone else in the future.
Was This Post Helpful? 1
  • +
  • -

#3 venomv1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 07-September 13

Re: Matching the Value of User Input to Picturebox Value in an array

Posted 08 January 2014 - 10:04 PM

My problem is that I can not figure out how to match a input value to the value of the picture array to see if there is a part of a ship there, and if there is, remove the entire ship from play

This post has been edited by andrewsw: 09 January 2014 - 05:08 AM
Reason for edit:: Removed previous quote

Was This Post Helpful? 0
  • +
  • -

#4 venomv1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 07-September 13

Re: Matching the Value of User Input to Picturebox Value in an array

Posted 08 January 2014 - 10:18 PM

Here's the code, sorry for the delay. My main problem is in the Location_Click event

Dim placesmall, placemed, placebig As Integer 'ship placement
Dim row, column, spot As Integer 'Ship Guess
Dim i As Integer 'ship random spot

Private Sub Locate_Click()
r = 0 'Zero Values
column = 0 'Zero Values
column = InputBox("Guess the Column")
row = InputBox("Guess the Row")
'Choose the row for the ship location guess
    row = (row * 10) - 10
    column = column - 1
i = row + column
If i = Picture1(i) = LoadPicture(App.Path & "/ss1.jpg") Then 'Test
Picture1(i).BackColor &H8000000D
i = i + 1
Picture1(i).BackColor &H8000000D
End If


End Sub

Private Sub placeship_Click()
'clear the pictureboxes
For i = 0 To 99
Picture1(i).Cls
Next i

'Small ship
placesmall = Int(99 * Rnd + 1)
i = placesmall
    i = 0
    i = Int(99 * Rnd + 1)
Picture1(i) = LoadPicture(App.Path & "/ss1.jpg")
    i = i + 1
Picture1(i) = LoadPicture(App.Path & "/ss2.jpg")

'medium ship
placemed = Int(99 * Rnd + 1)
If placemed = placesmall Or placemed = placesmall + 1 Then 'If the ship is placed over another ship, then it must respot itself
    placemed = 0
    placemed = Int(99 * Rnd + 1)
End If


'Test if ship is going to overlap to the next line

i = placemed
If i = 8 Or 18 Or 28 Or 38 Or 48 Or 58 Or 68 Or 78 Or 88 Or 98 Then
        i = 0
            i = Int(99 * Rnd + 1)
End If
If i = 9 Or 19 Or 29 Or 39 Or 49 Or 59 Or 69 Or 79 Or 89 Or 99 Then
    i = 0
        i = Int(99 * Rnd + 1)
End If


'Print The Ship

Picture1(i) = LoadPicture(App.Path & "/ms1.jpg")
    i = i + 1
Picture1(i) = LoadPicture(App.Path & "/ms2.jpg")
    i = i + 1
Picture1(i) = LoadPicture(App.Path & "/ms3.jpg")

'large ship
placebig = Int(99 * Rnd + 1)
If placebig = placesmall Or placebig = placemed Or placebig = placesmall + 1 Or placebig = placemed + 1 Or placebig = placemed + 2 Then 'If the ship is placed over another ship, then it must respot itself
    placebig = Int(99 * Rnd + 1)
End If
i = placebig

'Stop ship from printing to next line

If i = 7 Or 17 Or 27 Or 37 Or 47 Or 57 Or 67 Or 77 Or 87 Or 97 Then
    i = 0
        i = Int(99 * Rnd + 1)
End If
If i = 8 Or 18 Or 28 Or 38 Or 48 Or 58 Or 68 Or 78 Or 88 Or 98 Then
        i = 0
            i = Int(99 * Rnd + 1)
End If
If i = 9 Or 19 Or 29 Or 39 Or 49 Or 59 Or 69 Or 79 Or 89 Or 99 Then
    i = 0
        i = Int(99 * Rnd + 1)
End If



'Print The Ship

Picture1(i) = LoadPicture(App.Path & "/bs1.jpg")
    i = i + 1
Picture1(i) = LoadPicture(App.Path & "/bs2.jpg")
    i = i + 1
Picture1(i) = LoadPicture(App.Path & "/bs3.jpg")
    i = i + 1
Picture1(i) = LoadPicture(App.Path & "/bs4.jpg")


'For i = 0 To 99
'Picture1(i) = Nothing
'Next i

End Sub


Private Sub quit_Click()
End
End Sub


Was This Post Helpful? 0
  • +
  • -

#5 Minimalist  Icon User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 111
  • Joined: 13-November 13

Re: Matching the Value of User Input to Picturebox Value in an array

Posted 11 January 2014 - 08:09 AM

The first problem you can solve by using the tag property of a picture box and assigning it the name of the picture as:
Picture1(i) = LoadPicture(App.Path & "/ms1.jpg")
Picture1(i).Tag= "ms1.jpg"

That way you got a mechanism of working out if a picture is in a picture box:
tag = "" no picture or tag <> "" hasa oicture in it. Now, if you have more parts of the picture in different picture boxes you just assign the same name to these picture boxes in their tag property. This way you can circle through the pictire boxes array, check the tags and if they are the same clear the pictures out. So the user clicks on a picture box that contains part of the ship, keep the name in memory and if clicks on another matching piece remove this and so on.

This post has been edited by Minimalist: 11 January 2014 - 08:10 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1