You are viewing our Forum Archives. To view or take place in current topics click here.
(Help) Solving for any given moment? (VB)
Posted:
(Help) Solving for any given moment? (VB)Posted:
Status: Offline
Joined: Jan 02, 201212Year Member
Posts: 232
Reputation Power: 8
Status: Offline
Joined: Jan 02, 201212Year Member
Posts: 232
Reputation Power: 8
Hello, Im just wondering if in visual studio 2010, if you can code for any given moment. What i mean? example: instead of having to put code in something like a button "Which only works if the button is pressed" can you code somewhere that like, if at any given moment if x=10 then do this
.. Still doesnt make since let me kinda try an give an example.
instead of puting lets say this code in a button event and making it only work if the button is pressed how do you code "for any given moment"
private sub button1.click()
if x = 10 then
....
elseif
...
else
..
end sub
....
EXAMPLE HERE:
public sub agm()
if x = 10 then
else
end sub
end class
if you guys could help me that'd be great.
Note i know you can code for if the mouse moves do this and if the form is resized do this and if mouse is hovering then do this but that keeps doing the command.
(HELP)?
.. Still doesnt make since let me kinda try an give an example.
instead of puting lets say this code in a button event and making it only work if the button is pressed how do you code "for any given moment"
private sub button1.click()
if x = 10 then
....
elseif
...
else
..
end sub
....
EXAMPLE HERE:
public sub agm()
if x = 10 then
else
end sub
end class
if you guys could help me that'd be great.
Note i know you can code for if the mouse moves do this and if the form is resized do this and if mouse is hovering then do this but that keeps doing the command.
(HELP)?
#2. Posted:
Status: Offline
Joined: Sep 06, 201014Year Member
Posts: 1,069
Reputation Power: 47
Status: Offline
Joined: Sep 06, 201014Year Member
Posts: 1,069
Reputation Power: 47
Well, what is "x" specifically in your project?
- 0useful
- 0not useful
#3. Posted:
Status: Offline
Joined: Jan 02, 201212Year Member
Posts: 232
Reputation Power: 8
Status: Offline
Joined: Jan 02, 201212Year Member
Posts: 232
Reputation Power: 8
Well I was doing a casino type game with a craps table and slot machines and all that but when I coded the slot machine I had/am having a hard time getting the value of the labels to return a value to the users cash pile. At the moment i have this .. and it does work.
Button1.Enabled = True
Button3.Enabled = False
TextBox1.Enabled = True
If Val(Label1.Text) = Val(Label2.Text) And Val(Label1.Text) > 6 And Val(Label2.Text) > 6 Then
MsgBox("Jackpot")
cash = cash + Val(300)
Me.Label5.Text = Format(cash, "C")
ElseIf Val(Label1.Text) > 7 Then
cash = cash + Val(TextBox1.Text) + Val(20) 'adding
Me.Label5.Text = Format(cash, "C")
ElseIf Val(Label2.Text) > 7 Then
cash = cash + Val(TextBox1.Text) + Val(20)
Me.Label5.Text = Format(cash, "C")
ElseIf Val(Label3.Text) > 7 Then
cash = cash + Val(TextBox1.Text) + Val(20)
Me.Label5.Text = Format(cash, "C")
ElseIf Val(Label1.Text) > 7 And Val(Label2.Text) > 7 Then
cash = cash + Val(TextBox1.Text) + Val(40)
Me.Label5.Text = Format(cash, "C")
ElseIf Val(Label1.Text) > 7 And Val(Label3.Text) > 7 Then
cash = cash + Val(TextBox1.Text) + Val(40)
Me.Label5.Text = Format(cash, "C")
ElseIf Val(Label2.Text) > 7 And Val(Label3.Text) > 7 Then
cash = cash + Val(TextBox1.Text) + Val(40)
Me.Label5.Text = Format(cash, "C")
ElseIf Val(Label1.Text) < 7 And Val(Label2.Text) < 7 And Val(Label3.Text) < 7 Then
cash = cash - Val(TextBox1.Text)
cash = cash - 40
Me.Label5.Text = Format(cash, "C")
End If
End Sub
- 0useful
- 0not useful
#4. Posted:
Status: Offline
Joined: Apr 16, 201014Year Member
Posts: 4,309
Reputation Power: 179
Status: Offline
Joined: Apr 16, 201014Year Member
Posts: 4,309
Reputation Power: 179
add a timer and make it have this on it's tick event:
That should work, tell me if it doesn't.
if X = 10 then
timer1.stop()
Button1.Enabled = True
Button3.Enabled = False
TextBox1.Enabled = True
If Val(Label1.Text) = Val(Label2.Text) And Val(Label1.Text) > 6 And Val(Label2.Text) > 6 Then
MsgBox("Jackpot")
cash = cash + Val(300)
Me.Label5.Text = Format(cash, "C")
ElseIf Val(Label1.Text) > 7 Then
cash = cash + Val(TextBox1.Text) + Val(20) 'adding
Me.Label5.Text = Format(cash, "C")
ElseIf Val(Label2.Text) > 7 Then
cash = cash + Val(TextBox1.Text) + Val(20)
Me.Label5.Text = Format(cash, "C")
ElseIf Val(Label3.Text) > 7 Then
cash = cash + Val(TextBox1.Text) + Val(20)
Me.Label5.Text = Format(cash, "C")
ElseIf Val(Label1.Text) > 7 And Val(Label2.Text) > 7 Then
cash = cash + Val(TextBox1.Text) + Val(40)
Me.Label5.Text = Format(cash, "C")
ElseIf Val(Label1.Text) > 7 And Val(Label3.Text) > 7 Then
cash = cash + Val(TextBox1.Text) + Val(40)
Me.Label5.Text = Format(cash, "C")
ElseIf Val(Label2.Text) > 7 And Val(Label3.Text) > 7 Then
cash = cash + Val(TextBox1.Text) + Val(40)
Me.Label5.Text = Format(cash, "C")
ElseIf Val(Label1.Text) < 7 And Val(Label2.Text) < 7 And Val(Label3.Text) < 7 Then
cash = cash - Val(TextBox1.Text)
cash = cash - 40
Me.Label5.Text = Format(cash, "C")
End If
That should work, tell me if it doesn't.
- 0useful
- 0not useful
#5. Posted:
Status: Offline
Joined: Jan 02, 201212Year Member
Posts: 232
Reputation Power: 8
Status: Offline
Joined: Jan 02, 201212Year Member
Posts: 232
Reputation Power: 8
Z61 wrote add a timer and make it have this on it's tick event:
if X = 10 then
timer1.stop()
Button1.Enabled = True
Button3.Enabled = False
TextBox1.Enabled = True
If Val(Label1.Text) = Val(Label2.Text) And Val(Label1.Text) > 6 And Val(Label2.Text) > 6 Then
MsgBox("Jackpot")
cash = cash + Val(300)
Me.Label5.Text = Format(cash, "C")
ElseIf Val(Label1.Text) > 7 Then
cash = cash + Val(TextBox1.Text) + Val(20) 'adding
Me.Label5.Text = Format(cash, "C")
ElseIf Val(Label2.Text) > 7 Then
cash = cash + Val(TextBox1.Text) + Val(20)
Me.Label5.Text = Format(cash, "C")
ElseIf Val(Label3.Text) > 7 Then
cash = cash + Val(TextBox1.Text) + Val(20)
Me.Label5.Text = Format(cash, "C")
ElseIf Val(Label1.Text) > 7 And Val(Label2.Text) > 7 Then
cash = cash + Val(TextBox1.Text) + Val(40)
Me.Label5.Text = Format(cash, "C")
ElseIf Val(Label1.Text) > 7 And Val(Label3.Text) > 7 Then
cash = cash + Val(TextBox1.Text) + Val(40)
Me.Label5.Text = Format(cash, "C")
ElseIf Val(Label2.Text) > 7 And Val(Label3.Text) > 7 Then
cash = cash + Val(TextBox1.Text) + Val(40)
Me.Label5.Text = Format(cash, "C")
ElseIf Val(Label1.Text) < 7 And Val(Label2.Text) < 7 And Val(Label3.Text) < 7 Then
cash = cash - Val(TextBox1.Text)
cash = cash - 40
Me.Label5.Text = Format(cash, "C")
End If
That should work, tell me if it doesn't.
No, that x = 10 was a hypothetical situation. anyway my problem was getting vb to reconize that the user had won witout the user having to click "Claim". i solved this problem by finally giving up and putting in a button that says "claim". If i put the win() function in events such as mousemove() then it keeps giving the user money and i dont want that so does any of this help ?
- 0useful
- 0not useful
#6. Posted:
Status: Offline
Joined: Sep 06, 201014Year Member
Posts: 1,069
Reputation Power: 47
Status: Offline
Joined: Sep 06, 201014Year Member
Posts: 1,069
Reputation Power: 47
If you post the full code it would be a lot easier to make sense of it all. And post the "rules" of the game as well(i.e the only way to win is if all 3 labels are the same correct?).
- 0useful
- 0not useful
#7. Posted:
Status: Offline
Joined: Jan 02, 201212Year Member
Posts: 232
Reputation Power: 8
Status: Offline
Joined: Jan 02, 201212Year Member
Posts: 232
Reputation Power: 8
Do you have teamviewer if so my id is 416 998 516
pass z813fy
pass z813fy
- 0useful
- 0not useful
#8. Posted:
Status: Offline
Joined: Jun 11, 200915Year Member
Posts: 9,897
Reputation Power: 3160
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
Status: Offline
Joined: Jun 11, 200915Year Member
Posts: 9,897
Reputation Power: 3160
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
Hypothetical situation.
You explained it really badly, so I can only assume this is what you're trying to do.
[/code]
Public Function doWork()
'some code here
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x As Integer = 10
If x = 10 Then
doWork()
ElseIf x = 9 Then
MessageBox.Show("Some message")
Else
MessageBox.Show("You didn't win")
End If
End Sub
You explained it really badly, so I can only assume this is what you're trying to do.
[/code]
- 0useful
- 0not useful
#9. Posted:
Status: Offline
Joined: Jan 01, 201113Year Member
Posts: 1,957
Reputation Power: 401
Majesticfalcon wroteZ61 wrote add a timer and make it have this on it's tick event:
if X = 10 then
timer1.stop()
Button1.Enabled = True
Button3.Enabled = False
TextBox1.Enabled = True
If Val(Label1.Text) = Val(Label2.Text) And Val(Label1.Text) > 6 And Val(Label2.Text) > 6 Then
MsgBox("Jackpot")
cash = cash + Val(300)
Me.Label5.Text = Format(cash, "C")
ElseIf Val(Label1.Text) > 7 Then
cash = cash + Val(TextBox1.Text) + Val(20) 'adding
Me.Label5.Text = Format(cash, "C")
ElseIf Val(Label2.Text) > 7 Then
cash = cash + Val(TextBox1.Text) + Val(20)
Me.Label5.Text = Format(cash, "C")
ElseIf Val(Label3.Text) > 7 Then
cash = cash + Val(TextBox1.Text) + Val(20)
Me.Label5.Text = Format(cash, "C")
ElseIf Val(Label1.Text) > 7 And Val(Label2.Text) > 7 Then
cash = cash + Val(TextBox1.Text) + Val(40)
Me.Label5.Text = Format(cash, "C")
ElseIf Val(Label1.Text) > 7 And Val(Label3.Text) > 7 Then
cash = cash + Val(TextBox1.Text) + Val(40)
Me.Label5.Text = Format(cash, "C")
ElseIf Val(Label2.Text) > 7 And Val(Label3.Text) > 7 Then
cash = cash + Val(TextBox1.Text) + Val(40)
Me.Label5.Text = Format(cash, "C")
ElseIf Val(Label1.Text) < 7 And Val(Label2.Text) < 7 And Val(Label3.Text) < 7 Then
cash = cash - Val(TextBox1.Text)
cash = cash - 40
Me.Label5.Text = Format(cash, "C")
End If
That should work, tell me if it doesn't.
No, that x = 10 was a hypothetical situation. anyway my problem was getting vb to reconize that the user had won witout the user having to click "Claim". i solved this problem by finally giving up and putting in a button that says "claim". If i put the win() function in events such as mousemove() then it keeps giving the user money and i dont want that so does any of this help ?
Surely at somepoint there must be user interaction to "spin the reels", so there would be no need to have a claim button, make your win() function and call it at the end of the code to spin the reels, which it seems you have already done without the function???
As Speed has said you havent explained yourself very clearly.
But if you want to do any code which requires no user interaction then you need to make your app multi-threaded. It is far to long to go into here, so here is the MSDN reference for the Thread class
[ Register or Signin to view external links. ]
- 0useful
- 0not useful
You are viewing our Forum Archives. To view or take place in current topics click here.