VB MADNESS

Anything else. Post a funny site or tell us about yourself. Discuss current events or whatever else you want. Post off topic threads here.
Post Reply
Vandango
Senior Member
Posts: 4143
Joined: Sat Jun 03, 2006 3:23 pm
Quick Reply: Yes
Location: Babel

VB MADNESS

Post by Vandango »

right about know im coding a little program for my college assignment which is to make 5 lights show in a sequnce

now

there are 2 things
my teacher whos an exeprt programmer in a lot of langues Hex/Vb/Java and so on thinks this code is perfect yet there are still thing we could not figure out

Private Sub Timer1_Timer()

'ElseIf Shape2.FillStyle = 0 Then
'Shape2.FillStyle = 1 And Shape3.FillStyle = 0
'
'
'ElseIf Shape3.FillStyle = 0 Then
'Shape3.FillStyle = 1 And Shape4.FillStyle = 0
'
'
'ElseIf Shape4.FillStyle = 0 Then
'Shape4.FillStyle = 1 And Shape5.FillStyle = 0
'
'
'ElseIf Shape5.FillStyle = 0 Then
'Shape5.FillStyle = 1 And Shape1.FillStyle = 0

End Sub


ignore the ' i was trying to re write the code in order to get it working

Now For Some Reason it would Ignore the code in bold and stop there as i was trying to get the program to loop

also the program was also Ignoring the timer i had set for it yes this code was placed inside the timer event and properites of the timer were set correctly and for some reason it would still ignore the timer

i was wondering if you could figure out why it was ignoring the timer

i would give you the files for it to take a look at but i have no idea were to upload em

i also pmed curor but i think he might take a while to respond
<<banned from SRF for bot admission. -SG>>

User avatar
Blackchocob0
Addicted Member
Posts: 2840
Joined: Fri Sep 29, 2006 7:33 am
Quick Reply: Yes
Location: HIV, CA

Post by Blackchocob0 »

Whooza? I don't know bout that stuff sorry. :(
Peace.

User avatar
Gul
Valued Member
Posts: 385
Joined: Wed Sep 13, 2006 7:37 pm
Quick Reply: Yes
Location: Where?
Contact:

Re: VB MADNESS

Post by Gul »

Karlos Vandango wrote:Private Sub Timer1_Timer()

'ElseIf Shape2.FillStyle = 0 Then
'Shape2.FillStyle = 1 And Shape3.FillStyle = 0
'
'
'ElseIf Shape3.FillStyle = 0 Then
'Shape3.FillStyle = 1 And Shape4.FillStyle = 0
'
'
'ElseIf Shape4.FillStyle = 0 Then
'Shape4.FillStyle = 1 And Shape5.FillStyle = 0
'
'
'ElseIf Shape5.FillStyle = 0 Then
'Shape5.FillStyle = 1 And Shape1.FillStyle = 0

End Sub

I've never coded in VB, but it looks like a bunch of syntax errors.

Aren't you supposed to have a "If" statement before even using an "ElseIf"?

Wheres the "End If"?

User avatar
Anh_Hung_Rom
Loyal Member
Posts: 1699
Joined: Mon Jun 05, 2006 8:13 pm
Quick Reply: Yes
Location: Silicon Valley

Post by Anh_Hung_Rom »

It doesn't ignore the bold text. it fails there.

You do have the object Shape1 right?

Does the code for the other objects work? I mean, have you successfully force the program to execute the line above the bold text? Was this function fired before at all?

I don' t have a VB complier with me ATM. Paste the whole file and PM to me see if I can help.
Sig
"Never argue with an idiot. They will drag you down to their level and beat you with experience." Anonymous

Vandango
Senior Member
Posts: 4143
Joined: Sat Jun 03, 2006 3:23 pm
Quick Reply: Yes
Location: Babel

Post by Vandango »

Anh_Hung_Rom wrote:It doesn't ignore the bold text. it fails there.

You do have the object Shape1 right?

Does the code for the other objects work? I mean, have you successfully force the program to execute the line above the bold text? Was this function fired before at all?

I don' t have a VB complier with me ATM. Paste the whole file and PM to me see if I can help.


yes there all correct there just Named Shape1 Shape2 And So on till 5
<<banned from SRF for bot admission. -SG>>

User avatar
[SD]Master_Wong
Forum God
Posts: 9509
Joined: Wed Jan 04, 2006 8:02 pm
Quick Reply: Yes
Location: Plymouth, University

Post by [SD]Master_Wong »

il check over my class notes and see if i can figure it out but i actually failed that unit and now im farked because unit 8 is programming aswell :banghead:


html ftw though
MaStEr
Image
credits zelzin ^^

User avatar
MastaChiefX
Senior Member
Posts: 4526
Joined: Fri Nov 03, 2006 1:18 am
Quick Reply: Yes
Location: Life.

Post by MastaChiefX »

I would guess you havent intialized the Shape5. Or if you have, something is off.
Not the biggest fan of VB, and wong, html isnt much better lol
Image
^Thanks 0l3n!
Gone. Never really gone, but never really here.
"If Pac-Man had affected us as kids, we’d all be running around in dark rooms, munching pills and listening to repetitive electronic music"

User avatar
Rockshmo
Frequent Member
Posts: 1062
Joined: Mon May 29, 2006 5:00 pm
Quick Reply: Yes
Location: rehab
Contact:

Post by Rockshmo »

Make sure all the shapes, timers, etc are initialized and like Gul said it seems like it's missing an If statement...

If Shape1.FillStyle = 0 Then
Shape1.FillStyle = 1 And Shape2.FillStyle = 0

^ Maybe? I dunno, it's hard to tell without seeing the rest of the code.. also I think you can replace "And" with && then again I haven't used anything for VB or written in VB for about 3 years now.
Image
[Sparta][Pure STR][Lvl 5x]

Vandango
Senior Member
Posts: 4143
Joined: Sat Jun 03, 2006 3:23 pm
Quick Reply: Yes
Location: Babel

Post by Vandango »

Private Sub speed_Click()
If Text = "Slow" Then
Timer1.Interval = 2000
End If
'This will set the timer to run each light every 2 seconds
If Text = "Normal" Then
Timer1.Interval = 1000
End If
'This will set the timer to run each light every second
If Text = Fast Then
Timer1.Interval = 500
End If
'This will set the time to run each light every 0.5 seconds
If Text = Insane Then
Timer1.Interval = 250
End If
'This will set the timer to run each light ever 0.25 seconds
If Text = Godly Then
Timer1.Interval = 125
'This will set the timer to run each light ever 0.125 seconds
End If
End Sub

Private Sub start_Click()
Timer1.Enabled = True
'This will start the light show
End Sub

Private Sub stop_Click()
Timer1.Enabled = False
'This will stop the light show
End Sub

Private Sub Timer1_Timer()
If Shape1.FillStyle = 0 Then
Shape1.FillStyle = 1
Shape2.FillStyle = 0
Shape3.FillStyle = 1
Shape4.FillStyle = 1
Shape5.FillStyle = 1

ElseIf Shape2.FillStyle = 0 Then
Shape1.FillStyle = 1
Shape2.FillStyle = 1
Shape3.FillStyle = 0
Shape4.FillStyle = 1
Shape5.FillStyle = 1


ElseIf Shape3.FillStyle = 0 Then
Shape1.FillStyle = 1
Shape2.FillStyle = 1
Shape3.FillStyle = 1
Shape4.FillStyle = 0
Shape5.FillStyle = 1


ElseIf Shape4.FillStyle = 0 Then
Shape1.FillStyle = 1
Shape2.FillStyle = 1
Shape3.FillStyle = 1
Shape4.FillStyle = 1
Shape5.FillStyle = 0

ElseIf Shape5.FillStyle = 0 Then
Shape1.FillStyle = 0
Shape2.FillStyle = 1
Shape3.FillStyle = 1
Shape4.FillStyle = 1
Shape5.FillStyle = 1
End If

End Sub

this is same thing but different code and it still dosent loop and again ignores the timer

Anh_Hung_Rom ive correct a few errors but its basicly the same code alos took out the last part
<<banned from SRF for bot admission. -SG>>

User avatar
Anh_Hung_Rom
Loyal Member
Posts: 1699
Joined: Mon Jun 05, 2006 8:13 pm
Quick Reply: Yes
Location: Silicon Valley

Post by Anh_Hung_Rom »

Put double quote around String value like "Godly". Try to compile your code.

Initialize the Shape1.FillStyle, shape2.FillStyle.... at the beginning. I'm not sure if you did.

Private Sub Timer1_Timer() is the function that supposed to be called every loop right? Replace the code with something simple, say a print statement, and make sure it's called correctly.
Sig
"Never argue with an idiot. They will drag you down to their level and beat you with experience." Anonymous

User avatar
[SD]Master_Wong
Forum God
Posts: 9509
Joined: Wed Jan 04, 2006 8:02 pm
Quick Reply: Yes
Location: Plymouth, University

Post by [SD]Master_Wong »

MastaChiefX wrote:I would guess you havent intialized the Shape5. Or if you have, something is off.
Not the biggest fan of VB, and wong, html isnt much better lol


ofc it isnt its a different language essentiially well for different things

i just prefer html myself i find it more simple
MaStEr
Image
credits zelzin ^^

User avatar
Anh_Hung_Rom
Loyal Member
Posts: 1699
Joined: Mon Jun 05, 2006 8:13 pm
Quick Reply: Yes
Location: Silicon Valley

Post by Anh_Hung_Rom »

HTML is not even a programming language wong.
Sig
"Never argue with an idiot. They will drag you down to their level and beat you with experience." Anonymous

User avatar
Cruor
Loyal Member
Posts: 1999
Joined: Wed Apr 12, 2006 1:22 am
Quick Reply: Yes
Location: Off topic

Post by Cruor »

I have never even touched VB. Anyway, you say it only runs through the Timer1_Timer function once then stops? I looked at the Timer class on MSDN and it says something about using a "tick" event. I think the Timer1_Timer function is just being run through once because you don't have a "tick" event to call it repeatedly.
Image

User avatar
Innovacious
Advanced Member
Posts: 2446
Joined: Mon Sep 11, 2006 9:24 pm
Quick Reply: Yes
Location: Off Topic
Contact:

Post by Innovacious »

there are 2 ways to get it to work

either replace yout timer code with this

Code: Select all

Private Sub Timer1_Timer()
If Shape1.FillStyle = 1 Then
Shape1.FillStyle = 0
Shape2.FillStyle = 1
Shape3.FillStyle = 0
Shape4.FillStyle = 0
Shape5.FillStyle = 0

ElseIf Shape2.FillStyle = 1 Then
Shape1.FillStyle = 0
Shape2.FillStyle = 0
Shape3.FillStyle = 1
Shape4.FillStyle = 0
Shape5.FillStyle = 0


ElseIf Shape3.FillStyle = 1 Then
Shape1.FillStyle = 0
Shape2.FillStyle = 0
Shape3.FillStyle = 0
Shape4.FillStyle = 1
Shape5.FillStyle = 0


ElseIf Shape4.FillStyle = 1 Then
Shape1.FillStyle = 0
Shape2.FillStyle = 0
Shape3.FillStyle = 0
Shape4.FillStyle = 0
Shape5.FillStyle = 1

ElseIf Shape5.FillStyle = 1 Then
Shape1.FillStyle = 1
Shape2.FillStyle = 0
Shape3.FillStyle = 0
Shape4.FillStyle = 0
Shape5.FillStyle = 0
End If

End Sub


or

change the fillstyle in all of the shapes properties to 0, if they are already on 0 then neither of these will fix it and i dont know what is wrong

edit: you also need to work on the presentation of the code, dosnt help it work better but there are certain naming conventions and stuff that are preffered by most programmers.

ok first of ll, the objects (text boxes, buttons etc) in this program for example a good way to name the buttons is cmdSpeed, cmdStart etc. This is a naming convention used by most people (cmd is short for command button) the same thing applies to text boxes, they would have txt at the begginging (txtText for example. not sure about the shapes, i never really use them.

also, indentation helps when reading the code, like this

Code: Select all

private sub procedure()
      code
      code
      if
              code
      elseif
              code
      end if
end sub
ImageImage

Vandango
Senior Member
Posts: 4143
Joined: Sat Jun 03, 2006 3:23 pm
Quick Reply: Yes
Location: Babel

Post by Vandango »

Yay i finnaly got it working this is the working code

Private Sub speed_Click()
If speed.Text = "Slow" Then
Timer1.Interval = 2000
End If
'This will set the timer to run each light every 2 seconds
If speed.Text = "Normal" Then
Timer1.Interval = 1000
End If
'This will set the timer to run each light every second
If speed.Text = "Fast" Then
Timer1.Interval = 500
End If
'This will set the time to run each light every 0.5 seconds
If speed.Text = "Insane" Then
Timer1.Interval = 250
End If
'This will set the timer to run each light ever 0.25 seconds
If speed.Text = "Godly" Then
Timer1.Interval = 125
'This will set the timer to run each light ever 0.125 seconds
End If
End Sub

Private Sub Start_Click()
Timer1.Enabled = True
'This will start the light show
End Sub

Private Sub Stop_Click()
Timer1.Enabled = False
'This will stop the light show
End Sub

Private Sub Timer1_Timer()
If Shape1.FillStyle = 0 Then
Shape1.FillStyle = 1
Shape2.FillStyle = 0
Shape3.FillStyle = 1
Shape4.FillStyle = 1
Shape5.FillStyle = 1

ElseIf Shape2.FillStyle = 0 Then
Shape1.FillStyle = 1
Shape2.FillStyle = 1
Shape3.FillStyle = 0
Shape4.FillStyle = 1
Shape5.FillStyle = 1


ElseIf Shape3.FillStyle = 0 Then
Shape1.FillStyle = 1
Shape2.FillStyle = 1
Shape3.FillStyle = 1
Shape4.FillStyle = 0
Shape5.FillStyle = 1


ElseIf Shape4.FillStyle = 0 Then
Shape1.FillStyle = 1
Shape2.FillStyle = 1
Shape3.FillStyle = 1
Shape4.FillStyle = 1
Shape5.FillStyle = 0

ElseIf Shape5.FillStyle = 0 Then
Shape1.FillStyle = 0
Shape2.FillStyle = 1
Shape3.FillStyle = 1
Shape4.FillStyle = 1
Shape5.FillStyle = 1
End If

End Sub

change the fillstyle in all of the shapes properties to 0, if they are already on 0 then neither of these will fix it and i dont know what is wrong


0 is to make it Opaque(Spelling xD)
i only want 1 shape showing at a time

ill finsh this messege when i get home
<<banned from SRF for bot admission. -SG>>

User avatar
satman83
Site Contributor
Posts: 9541
Joined: Tue Oct 31, 2006 9:54 pm
Quick Reply: Yes
Location: London
Contact:

Post by satman83 »

smeghead :P
Image

User avatar
Innovacious
Advanced Member
Posts: 2446
Joined: Mon Sep 11, 2006 9:24 pm
Quick Reply: Yes
Location: Off Topic
Contact:

Post by Innovacious »

hmm. your not using vb.net are you? i cant stand that version
ImageImage

Vandango
Senior Member
Posts: 4143
Joined: Sat Jun 03, 2006 3:23 pm
Quick Reply: Yes
Location: Babel

Post by Vandango »

Innovacious wrote:hmm. your not using vb.net are you? i cant stand that version


i think it is yes but i never look lol
i had to rewrite the whole program form scratch due to my MP3 player with my work on kicked the bucket
<<banned from SRF for bot admission. -SG>>

Post Reply

Return to “Off Topic Lounge”