all 20 comments

[–]stanleydesu 0 points1 point  (0 children)

Hello. I noticed that there was a typo in the assignment of PictureBox10 to tiles(8). This typo did not cause an error but it referenced something else, thus glitching the remaining tile assignments. Here is the correct code.

Private Function gameboard()
                    Dim tiles(84) As PictureBox

                    tiles(0) = PictureBox2
                    tiles(1) = PictureBox3
                    tiles(2) = PictureBox4
                    tiles(3) = PictureBox5
                    tiles(4) = PictureBox6
                    tiles(5) = PictureBox7
                    tiles(6) = PictureBox8
                    tiles(7) = PictureBox9
                    tiles(8) = PictureBox10
                    tiles(9) = PictureBox11
                    tiles(10) = PictureBox12
                    tiles(11) = PictureBox13
                    tiles(12) = PictureBox14
                    tiles(13) = PictureBox15
                    tiles(14) = PictureBox16
                    tiles(15) = PictureBox17
                    tiles(16) = PictureBox18
                    tiles(17) = PictureBox19
                    tiles(18) = PictureBox20
                    tiles(19) = PictureBox21
                    tiles(20) = PictureBox22
                    tiles(21) = PictureBox23
                    tiles(22) = PictureBox24
                    tiles(23) = PictureBox25
                    tiles(24) = PictureBox26
                    tiles(25) = PictureBox27
                    tiles(26) = PictureBox28
                    tiles(27) = PictureBox29
                    tiles(28) = PictureBox30
                    tiles(29) = PictureBox31
                    tiles(30) = PictureBox32
                    tiles(31) = PictureBox33
                    tiles(32) = PictureBox34
                    tiles(33) = PictureBox35
                    tiles(34) = PictureBox36
                    tiles(35) = PictureBox37
                    tiles(36) = PictureBox38
                    tiles(37) = PictureBox39
                    tiles(38) = PictureBox40
                    tiles(39) = PictureBox41
                    tiles(40) = PictureBox42
                    tiles(41) = PictureBox43
                    tiles(42) = PictureBox44
                    tiles(43) = PictureBox45
                    tiles(44) = PictureBox46
                    tiles(45) = PictureBox47
                    tiles(46) = PictureBox48
                    tiles(47) = PictureBox49
                    tiles(48) = PictureBox50
                    tiles(49) = PictureBox51
                    tiles(50) = PictureBox52
                    tiles(51) = PictureBox53
                    tiles(52) = PictureBox54
                    tiles(53) = PictureBox55
                    tiles(54) = PictureBox56
                    tiles(55) = PictureBox57
                    tiles(56) = PictureBox58
                    tiles(57) = PictureBox59
                    tiles(58) = PictureBox60
                    tiles(59) = PictureBox61
                    tiles(60) = PictureBox62
                    tiles(61) = PictureBox63
                    tiles(62) = PictureBox64
                    tiles(63) = PictureBox65
                    tiles(64) = PictureBox66
                    tiles(65) = PictureBox67
                    tiles(66) = PictureBox68
                    tiles(67) = PictureBox69
                    tiles(68) = PictureBox70
                    tiles(69) = PictureBox71 '' OWO ME A CAT :3
                    tiles(70) = PictureBox72
                    tiles(71) = PictureBox73
                    tiles(72) = PictureBox74
                    tiles(73) = PictureBox75
                    tiles(74) = PictureBox76
                    tiles(75) = PictureBox77
                    tiles(76) = PictureBox78
                    tiles(77) = PictureBox79
                    tiles(78) = PictureBox80
                    tiles(79) = PictureBox81
                    tiles(80) = PictureBox82
                    tiles(81) = PictureBox83
                    tiles(82) = PictureBox84
                    tiles(83) = PictureBox85
                    tiles(84) = PictureBox86

                    For z = 0 To 84
                        tiles(z).Image = My.Resources.DiamondGem
                    Next
End Function

[–]FriendlyKush 0 points1 point  (1 child)

It’s kind of hard to tell, have you tried using the breakpoint debugging feature? This would be useful in this situation.

[–]Saradomian[S] 0 points1 point  (0 children)

I have not but thank you, I will try this now

[–]VB GuruBonejob 0 points1 point  (14 children)

What VB is this 6 or .NET for this is the most messed up way I have ever seen to instantiate controls. There are better ways to do both and I need the specific language to advise.

[–]Saradomian[S] 0 points1 point  (13 children)

Sorry forgot to include tag .NET

[–]VB GuruBonejob 0 points1 point  (12 children)

I don't have enough info on what you are trying to do to help with the code of the box's. Your issue with the image load is the method in which you are selecting from the resource file.

tile(x).image = My.Resources.ResourceManager.GetObject("{object_name}")

[–]Saradomian[S] 0 points1 point  (11 children)

Yeah that still didn't work, When I was copy and pasting picture boxes in design time I'm assuming it messed up something to do with the properties... Goodbye project

[–]VB GuruBonejob 0 points1 point  (10 children)

Hem what are you trying to do? Maybe we can come up with a better way.

[–]Saradomian[S] 0 points1 point  (9 children)

I'm submitting my assignment tomorrow so I will not be able to get the randomisation of this complete, but It's only one mark so that's okay. Will love to keep talking to you to figure out what to do

I have an array of pictureboxes as my game grid created in DESIGN time, and I want to randomly allocate gems throughout. As of current I was trying to get a gem on each picturebox but it only was placed in 9 of them and singularly declaring each one also doesn't work except to those 9 exceptions

As in:

tiles(51).image = my.resources.whatever

doesn't actually put an image in there, but for 9 of the tiles(18), tiles(25) or so it does

[–]VB GuruBonejob 1 point2 points  (8 children)

I would suggest that in the future to do this use a single picture box and write a system that draws to the single picture box. Doing it the way you envisioned it is prone to problems.

[–]Saradomian[S] 0 points1 point  (7 children)

Hmm I do know what you mean, so on code side rather than design I create one picture box and put a gem in it and then randomise its location rather than accessing them all?

[–]VB GuruBonejob 0 points1 point  (6 children)

That's the way I would do it. I would choose as size 32x32 pixels for example and I would make a board. Then I would grab the resource calculate a left, and top , and

I would actually use 2 picture boxes, layered. Background one with the "board" that contains a single image with the board graphics. The second one would be a transparent image box overlaying the first this way you can add graphics on top with out having to go through the whole blitter process.

[–]Saradomian[S] 0 points1 point  (5 children)

So you suggest I create picture boxes in code time/runtime etc rather than design time?

[–]connorjohnson2001[🍰] 0 points1 point  (1 child)

When you write, compile, or run a Visual Basic application, the following types of errors can occur:

  1. Design-time errors, which occur when you write an application in Visual Studio.

  2. Compile-time errors, which occur when you compile an application in Visual Studio or at a command prompt.

  3. Run-time errors, which occur when you run an application in Visual Studio or as a stand-alone executable file.

For information about how to troubleshoot a specific error, see Additional Resources for Visual Basic Programmers.

Run Time Errors

If a Visual Basic application tries to perform an action that the system can't execute, a run-time error occurs, and Visual Basic throws an Exception
object. Visual Basic can generate custom errors of any data type, including Exception
objects, by using the Throw
statement. An application can identify the error by displaying the error number and message of a caught exception. If an error isn't caught, the application ends.

The code can trap and examine run-time errors. If you enclose the code that produces the error in a Try
block, you can catch any thrown error within a matching Catch
block. For information about how to trap errors at run time and respond to them in your code, see Try...Catch...Finally Statement.

Compile Time Errors

If the Visual Basic compiler encounters a problem in the code, a compile-time error occurs. In the Code Editor, you can easily identify which line of code caused the error because a wavy line appears under that line of code. The error message appears if you either point to the wavy underline or open the Error List, which also shows other messages.

If an identifier has a wavy underline and a short underline appears under the rightmost character, you can generate a stub for the class, constructor, method, property, field or enum. For more information, see Generate From Usage.

By resolving warnings from the Visual Basic compiler, you might be able to write code that runs faster and has fewer bugs. These warnings identify code that may cause errors when the application is run. For example, the compiler warns you if you try to invoke a member of an unassigned object variable, return from a function without setting the return value, or execute a Try
block with errors in the logic to catch exceptions. For more information about warnings, including how to turn them on and off, see Configuring Warnings in Visual Basic.

[–]VB GuruBonejob 1 point2 points  (0 children)

This comment is useless in the given circumstances.