Validation Technique + Creating Picture Boxes

Unsure of Logic, and an error possibly i cant find?

Page 1 of 1

9 Replies - 2067 Views - Last Post: 14 January 2007 - 07:21 PM Rate Topic: -----

#1 Mr Mooju the Pogostick  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 13-September 06

Validation Technique + Creating Picture Boxes

Posted 08 January 2007 - 07:51 PM

Hey there, I have this game I need to make, and what happens is that I need objects to fall down my screen. To do this, I have created some code that alows me to randomly pick a variable from an array and create a picture box. The problem is that i need to validate that the random number doesn't choose a variable in the array that has already made a picture box. Any help would be greatly appreciated. Also, for some reason when it executes it, the picture boxes wont appear =/

	 Private Sub Enemy_Drop_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Enemy_Drop.Tick
		If EnemyDropInterval = 0 Then
			Create_Enemies()
		Else
			EnemyDropInterval = EnemyDropInterval - 10
		End If

	End Sub

	Private Sub Random_Enemy()
		Do
			Randomize()
			Counter = Int(Rnd() * 20) + 1
		Loop Until Enemies(Counter).Visible = False
	End Sub
	Private Function RandLength()
		Randomize()
		Length = Int(Rnd() * Screen.PrimaryScreen.Bounds.Width) + 10
		Return Length
	End Function
	Private Sub Randomize_Location()
		Enemies(Counter).Location = New Point(RandLength, 0)
	End Sub
	Private Sub ValidateEnemy()
		If Enemies(Counter).Visible = True Then

		End If
	End Sub

	Private Sub Create_Enemies()
		Random_Enemy()
		Enemies(Counter) = New PictureBox
		ValidateEnemy()
		Enemies(Counter).BackColor = Color.Aqua
		Randomize_Location()
		Enemies(Counter).Visible = True

		EnemyDropInterval = 100
	End Sub 


any help would be appreciated. THANKS!

Is This A Good Question/Topic? 0
  • +

Replies To: Validation Technique + Creating Picture Boxes

#2 Mr Mooju the Pogostick  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 13-September 06

Re: Validation Technique + Creating Picture Boxes

Posted 09 January 2007 - 06:57 PM

Desperate for help here, I've spent countless hours just looking at this and I don't know what's wrong. Please anyone, I have updated the code:

	Private Sub CreateNew()
		EnemyCounter = EnemyCounter + 1
		Enemies(EnemyCounter) = New PictureBox
		Enemies(EnemyCounter).BackColor = Color.Black
		If EnemyCounter = 20 Then
			'AllCreated = True
			EnemyCounter = -1
			'CreateOld()
		End If
	End Sub
	Private Sub CreateOld()
		Do
			EnemyCounter = EnemyCounter + 1
			If EnemyCounter = 19 Then
				EnemyCounter = 0
			End If
		Loop Until Enemies(EnemyCounter).Visible = False
	End Sub
	Private Sub Random_Enemy()
		'If AllCreated = False Then
		CreateNew()
		'Else
		'CreateOld()
		'End If
	End Sub
	Private Function RandLength()
		Randomize()
		Length = Int(Rnd() * Screen.PrimaryScreen.Bounds.Width) + 10
		Return Length
	End Function

	Private Sub EnemyProperties()
		Enemies(EnemyCounter).Enabled = True
		Enemies(EnemyCounter).Location = New Point(RandLength, 50)
		Enemies(EnemyCounter).Width = 20
		Enemies(EnemyCounter).Height = 20
		Enemies(EnemyCounter).Image = Image.FromFile("\\images\target.gif")
		Enemies(EnemyCounter).Visible = True
		Enemies(EnemyCounter).SizeMode = PictureBoxSizeMode.Normal

	End Sub
	Private Sub Create_Enemies()
		Random_Enemy()
		EnemyProperties()


		'EnemyTimer(EnemyCounter) = New Timer
		'EnemyTimer(EnemyCounter).Interval = 20
		EnemyDropInterval = 50
	End Sub 


I get no errors, but the images aren't showing. I don't understand what I'm doing wrong, any help would really really be appreciated. I dont need validation help anymore as I changed the logic of the program to fix that, but I can't get the images to appear. Really desperate here. Any help would be appreciated THANKS!

This post has been edited by Mr Mooju the Pogostick: 09 January 2007 - 07:04 PM

Was This Post Helpful? 0
  • +
  • -

#3 m2s87  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 21
  • View blog
  • Posts: 390
  • Joined: 28-November 06

Re: Validation Technique + Creating Picture Boxes

Posted 09 January 2007 - 11:40 PM

If i have the time i will try to fix it.
I could not understand what basic are you using vb 6, vb 7, vb 8, vb 9 or ?
As different versions support different styles that is important to know. But as this is classic vb (not .net) then i am guessing you are using vb6.

I did not how the program flow should go or what the program is supposed to do, but you where trying to access elements globally that you created privately.

Should the picture box be event driven a la do you need to detect if any picture box was clicked?

Probably the easiest way that you can do this is do premake an array of picturebox. And then just toggle visibility&position.

I can mention that using Enemies(EnemyCounter) = New PictureBox would probably not do what you would wish.

So if you can mention what version of basic you are using and how should the picture box be set invisible (the reason or event that would cause it) we could help you.

Hope it helped :D
Was This Post Helpful? 0
  • +
  • -

#4 Mr Mooju the Pogostick  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 13-September 06

Re: Validation Technique + Creating Picture Boxes

Posted 09 January 2007 - 11:46 PM

sorry i forgot, im using vb 2005, and the actual procedure itself is based on a timer and isnt really even driven, it should automatically randomly make picture boxes appear. So basically, what I wanted was not to put all these different picutre boxes on invisible because i get the feeling it would slow down the processing? i dont know, really unsure there, but apart from that, what i wanted was that once the timer reached 0 or so [my timer is ok] it would create a new picture box which would randomly appear at X,Y position. The idea of the part of the program i posted was to produce images randomly starting at the top of the screen slowly moving downwards - i hadnt gotten up to the downward section yet.
Was This Post Helpful? 0
  • +
  • -

#5 m2s87  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 21
  • View blog
  • Posts: 390
  • Joined: 28-November 06

Re: Validation Technique + Creating Picture Boxes

Posted 12 January 2007 - 04:33 PM

View PostMr Mooju the Pogostick, on 9 Jan, 2007 - 11:46 PM, said:

sorry i forgot, im using vb 2005, and the actual procedure itself is based on a timer and isnt really even driven, it should automatically randomly make picture boxes appear. So basically, what I wanted was not to put all these different picutre boxes on invisible because i get the feeling it would slow down the processing? i dont know, really unsure there, but apart from that, what i wanted was that once the timer reached 0 or so [my timer is ok] it would create a new picture box which would randomly appear at X,Y position. The idea of the part of the program i posted was to produce images randomly starting at the top of the screen slowly moving downwards - i hadnt gotten up to the downward section yet.

If you will have a lot of picture boxes, you should think of reusing the picture boxes or disposing some of them.

Well i think i made a good example, that does abut what you wanted. The code i wrote:
Public Class Form1
	Dim WithEvents nupp As New Button
	Private Sub lisa()
		Dim x As New liigu
		Randomize()

		x.Pilt.Left = Rnd() * (Me.Width + 2 * x.Pilt.Width) - x.Pilt.Width
		x.Pilt.BackColor = System.Drawing.Color.FromArgb( _
						   Rnd() * 255, Rnd() * 255, Rnd() * 255, Rnd() * 255)
		x.Kell1.Start()
	End Sub
	Private Sub nupp_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles nupp.Click
		For i As Byte = 1 To 5
			Call lisa()
			System.Threading.Thread.Sleep(20)
			Application.DoEvents()
		Next i
	End Sub

	Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
		Me.WindowState = FormWindowState.Maximized
		Me.Controls.Add(nupp)
		With nupp
			.Left = 0
			.Top = 0
			.Text = "Add some"
			.Visible = True
		End With
	End Sub
End Class
Public Class liigu
	Friend WithEvents Kell1 As System.Windows.Forms.Timer
	Friend WithEvents Pilt As System.Windows.Forms.PictureBox
	Sub New()
		'Kell
		Me.Kell1 = New System.Windows.Forms.Timer(New System.ComponentModel.Container)
		Me.Kell1.Interval = 1200

		'Pilt
		Me.Pilt = New System.Windows.Forms.PictureBox
		CType(Me.Pilt, System.ComponentModel.ISupportInitialize).BeginInit()
		Form1.SuspendLayout()
		With Me.Pilt
			.Location = New System.Drawing.Point(12, 12)
			.Size = New System.Drawing.Size(100, 50)
			.BackColor = System.Drawing.Color.SkyBlue
			.Name = "PictureBox1"
			.TabIndex = 0
			.TabStop = False
		End With
		Form1.Controls.Add(Me.Pilt)
		CType(Me.Pilt, System.ComponentModel.ISupportInitialize).EndInit()
	End Sub
	Private Sub Kell1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Kell1.Tick
		Debug.Print(Form1.Bottom & "<" & Pilt.Top)
		If Form1.Bottom < Me.Pilt.Bottom Then
			Me.Pilt.Top = 34
			Me.Pilt.Left = 200
			'or Raiseevent disposeMe
		Else
			Me.Pilt.Top += 3
		End If

	End Sub
End Class


Hope it helped :D
Was This Post Helpful? 0
  • +
  • -

#6 Mr Mooju the Pogostick  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 13-September 06

Re: Validation Technique + Creating Picture Boxes

Posted 13 January 2007 - 02:36 AM

thanks heaps!!! ill try it out! ill post a reply when ive tried it. i owe you heaps man! ive been pondering this for HOURS
Was This Post Helpful? 0
  • +
  • -

#7 Mr Mooju the Pogostick  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 13-September 06

Re: Validation Technique + Creating Picture Boxes

Posted 14 January 2007 - 01:35 AM

ive looked at it, and the problem is, i dont understand what you've done, and i can't implement it into my program >.< and i was wondering about another way of going about things.

In VB 6 you were able to create control arrays yeah? but in vb 2005, you're not able to. But in the MSDN it said you were able to create control arrays in vb 2005, how do you do that?
Was This Post Helpful? 0
  • +
  • -

#8 m2s87  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 21
  • View blog
  • Posts: 390
  • Joined: 28-November 06

Re: Validation Technique + Creating Picture Boxes

Posted 14 January 2007 - 01:37 AM

View PostMr Mooju the Pogostick, on 14 Jan, 2007 - 01:35 AM, said:

ive looked at it, and the problem is, i dont understand what you've done, and i can't implement it into my program >.< and i was wondering about another way of going about things.

In VB 6 you were able to create control arrays yeah? but in vb 2005, you're not able to. But in the MSDN it said you were able to create control arrays in vb 2005, how do you do that?


Add them in a collection?
Was This Post Helpful? 0
  • +
  • -

#9 Mr Mooju the Pogostick  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 13-September 06

Re: Validation Technique + Creating Picture Boxes

Posted 14 January 2007 - 06:53 PM

yeah i did that and all, but then i dont know how to access each one of them individually if i need to =/ i can only access ALL of them at once, and i cant access them individually one at a time
Was This Post Helpful? 0
  • +
  • -

#10 Mr Mooju the Pogostick  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 13-September 06

Re: Validation Technique + Creating Picture Boxes

Posted 14 January 2007 - 07:21 PM

i just found some better code, that i think might be useful for any new vb 2005-ers out there, because it simulates EXACTLY what a control array does and it is so so so so sOSOOOOOOOO simple, that it destroys the official solution that microsoft gave out,
[code] Dim i As Single, av2 As String

'Comb2 is the name of your array control,

' "(Of ComboBox)" Means the array is going to include combo boxes only, so change it to "(Of ComboBox)" if you are dealing with text boxes, vice versa for all others, keep an eye on the object types within your array.

Public Comb2 As New System.Collections.Generic.List(Of ComboBox)

Sub New()
InitializeComponent()
Comb2.Add(ComboBox1) 'Comb2(item=0)
Comb2.Add(ComboBox2) 'Comb2 is your array name
Comb2.Add(ComboBox3) 'ComboBox1, ComBox2 etc are the objects, NOT variables
Comb2.Add(ComboBox4)
Comb2.Add(ComboBox5)
Comb2.Add(ComboBox6)
End Sub 'This new sub declaration added ComBox1~6 to the array

' THE BELOW WILL NOT WORK "BY ITSELF", so if you simply copy and paste, nothing good will happen. You have to trigger it, with an event, such as button click

For i = 0 To 5
av2 = "TextArray" 'text
Comb2.Item(i).Text = av2 'Collection
Comb2.Item(i).ForeColor = Color.White
Comb2.Item(i).BackColor = Color.Black
Next i

[code]

thankyou for all your help m2s87. thanks for helping me get through it all though, i really do appreciate it =] FOR ALL YOU VB 2005 ERS OUT THERE, HERE IS THE CONTROL ARRAY STUFF THAT YOU'VE ALL BEEN WANTING ALL YOUR LIFE

This post has been edited by Mr Mooju the Pogostick: 14 January 2007 - 07:53 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1