473,407 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Matching The Value Of User Input To Picturebox Value In An Array VB6

*Program is attached as well, due to there being pictures of the ships that are required to get the full experience of the program*

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?

*Code Below*
Expand|Select|Wrap|Line Numbers
  1. Dim placesmall, placemed, placebig As Integer 'ship placement
  2. Dim row, column, spot As Integer 'Ship Guess
  3. Dim i As Integer 'ship random spot
  4.  
  5. Private Sub Locate_Click()
  6. r = 0 'Zero Values
  7. column = 0 'Zero Values
  8. column = InputBox("Guess the Column")
  9. row = InputBox("Guess the Row")
  10. 'Choose the row for the ship location guess
  11.     row = (row * 10) - 10
  12.     column = column - 1
  13. i = row + column
  14.  
  15.  
  16. End Sub
  17.  
  18. Private Sub placeship_Click()
  19. 'clear the pictureboxes
  20. For i = 0 To 99
  21. Picture1(i).Cls
  22. Next i
  23.  
  24. 'Small ship
  25. placesmall = Int(99 * Rnd + 1)
  26. i = placesmall
  27.     i = 0
  28.     i = Int(99 * Rnd + 1)
  29. Picture1(i) = LoadPicture(App.Path & "/ss1.jpg")
  30.     i = i + 1
  31. Picture1(i) = LoadPicture(App.Path & "/ss2.jpg")
  32.  
  33. 'medium ship
  34. placemed = Int(99 * Rnd + 1)
  35. If placemed = placesmall Or placemed = placesmall + 1 Then 'If the ship is placed over another ship, then it must respot itself
  36.     placemed = 0
  37.     placemed = Int(99 * Rnd + 1)
  38. End If
  39.  
  40.  
  41. 'Test if ship is going to overlap to the next line
  42.  
  43. i = placemed
  44. If i = 8 Or 18 Or 28 Or 38 Or 48 Or 58 Or 68 Or 78 Or 88 Or 98 Then
  45.         i = 0
  46.             i = Int(99 * Rnd + 1)
  47. End If
  48. If i = 9 Or 19 Or 29 Or 39 Or 49 Or 59 Or 69 Or 79 Or 89 Or 99 Then
  49.     i = 0
  50.         i = Int(99 * Rnd + 1)
  51. End If
  52.  
  53.  
  54. 'Print The Ship
  55.  
  56. Picture1(i) = LoadPicture(App.Path & "/ms1.jpg")
  57.     i = i + 1
  58. Picture1(i) = LoadPicture(App.Path & "/ms2.jpg")
  59.     i = i + 1
  60. Picture1(i) = LoadPicture(App.Path & "/ms3.jpg")
  61.  
  62. 'large ship
  63. placebig = Int(99 * Rnd + 1)
  64. 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
  65.     placebig = Int(99 * Rnd + 1)
  66. End If
  67. i = placebig
  68.  
  69. 'Stop ship from printing to next line
  70.  
  71. If i = 7 Or 17 Or 27 Or 37 Or 47 Or 57 Or 67 Or 77 Or 87 Or 97 Then
  72.     i = 0
  73.         i = Int(99 * Rnd + 1)
  74. End If
  75. If i = 8 Or 18 Or 28 Or 38 Or 48 Or 58 Or 68 Or 78 Or 88 Or 98 Then
  76.         i = 0
  77.             i = Int(99 * Rnd + 1)
  78. End If
  79. If i = 9 Or 19 Or 29 Or 39 Or 49 Or 59 Or 69 Or 79 Or 89 Or 99 Then
  80.     i = 0
  81.         i = Int(99 * Rnd + 1)
  82. End If
  83.  
  84.  
  85.  
  86. 'Print The Ship
  87.  
  88. Picture1(i) = LoadPicture(App.Path & "/bs1.jpg")
  89.     i = i + 1
  90. Picture1(i) = LoadPicture(App.Path & "/bs2.jpg")
  91.     i = i + 1
  92. Picture1(i) = LoadPicture(App.Path & "/bs3.jpg")
  93.     i = i + 1
  94. Picture1(i) = LoadPicture(App.Path & "/bs4.jpg")
  95.  
  96.  
  97. 'For i = 0 To 99
  98. 'Picture1(i) = Nothing
  99. 'Next i
  100.  
  101. End Sub
  102.  
  103.  
  104. Private Sub quit_Click()
  105. End
  106. End Sub
  107.  
Attached Files
File Type: zip battleship.zip (13.2 KB, 53 views)
Jan 10 '14 #1
0 1028

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: reneeccwest | last post by:
Different user input boxes are automatically populated based on a value of the dropdown box. Can anyone help me on that?
13
by: Stumped and Confused | last post by:
Hello, I really, really, need some help here - I've spent hours trying to find a solution. In a nutshell, I'm trying to have a user input a value in form's textfield. The value should then be...
4
by: Alex | last post by:
Is there any way to delete the value of a html hidden input field from code-behind? I use an html hidden input to store an array of data. I collect this data using Request.Form or Request.Params....
0
by: Paulers | last post by:
hello VB masters I have an issue that I am hoping you can help me with. I am creating an application that accepts user input via a richtextbox. the user can enter multiple entries and I need to...
2
by: danielboendergaard | last post by:
Hey Im making a homepage in php. I use a html form to put data into mysql and i want to make some buttons which inserts user input values into a textarea. I have used a button like this: <input...
3
by: A TO Consultant | last post by:
Hi All, I am working on a web application that uses both asp classic and asp.net pages. We need to validate user input to avoid attacks like sql injection. Can a component be created that both...
2
by: wertqt | last post by:
hi there, im having a slight problem in matching the user input(textbox's text) with the values in one of the columns from a MS Access database. Im using C#.NET. The situation is this : My...
6
by: AZRebelCowgirl73 | last post by:
Here is my problem: I have two java files: One named Car.java and the other named CarDealerApp.java: In the CarDealerApp program, I read in through user input the make, model, year and price of...
14
by: n3o | last post by:
Hello Comp.Lang.C Members, I have an issue with user input that I have been trying to figure out for the longest. For instance, let's say you have something like this: void foo() { int num;...
6
by: michelle eccles | last post by:
I have an array with limit of 5 values. The code as writen allows the user to enter a 6th number before averaging the first five number. I want to stop the user from being able to enter that 6th...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.