Jump to content

Define variable for one loop through


 Share

Recommended Posts

Is it possible to have a defined variable within a loop and then midway through the loop redefine the variable and run the loop through with the new definition??

I don't have any code yet for this I am just brainstorming

This might be an example

While 1

$a = 5
$b = 10
$c= 4
$d = 8

If some statement Then
$a = $c And $b = $d

Wend

How can you run this loop without $a being redefined back to 5, but just for one loop through and then $a needs to go back to 5. Is there a way to do this??

Link to comment
Share on other sites

put your initial declarations outside the loop

$a = 5
$b = 10
$c= 4
$d = 8



While 1

If some statement Then
$a = $c And $b = $d

Wend

The speed of sound is defined by the distance from door to computer divided by the time interval needed to close the media player and pull up your pants when your mom shouts "OH MY GOD WHAT ARE YOU DOING!!!"

Link to comment
Share on other sites

Would you be able to put the loop inside a function?

Define the variables outside of the function, call the function, then have the function exit the loop if the vars are re-defined, and then re-enter the function with the new variable defs.

Just throwing that out there...

Edit: Beat to the punch again.

Edited by DoctorX
-DRX
Link to comment
Share on other sites

Ok but how would I go back to the original definitions after one loop?

Define the variables outside of the function, call the function, then have the function exit the loop if the vars are re-defined, and then re-enter the function with the new variable defs.

That is a confusing sentance is this saying the same thing that Shibuya is talking about?

Link to comment
Share on other sites

after reading this thread twice, I'm finding myself lost at your question

it's easier if you'll tell us what you want to do.

what's and where's this "one loop"?

if you want to make $a = 5 after 1 round of the while loop, then i think your original script works fine

DoctorX is basically saying very much the same thing, except that he reccomends to define a function for the "if some statement" part

The speed of sound is defined by the distance from door to computer divided by the time interval needed to close the media player and pull up your pants when your mom shouts "OH MY GOD WHAT ARE YOU DOING!!!"

Link to comment
Share on other sites

While 1

.....

Wend

Is a neverending loop right? So if I want to run through that loop one time with a variable being defined as x then the next time run through the loop with that same variable defined as y then z and then back to x.

I am not sure if that made any more sense at all.

I am trying to integrate it into my existing code to form a iteration

While 1
    
$dealcard = CHECK_VALUE("nValuedeal")
$card1 = CHECK_VALUE1("nValue1")
$card2 = CHECK_VALUE2("nValue2")
$card3 = CHECK_VALUE3("nValue3")
$card4 = CHECK_VALUE4("nValue4")
$card5 = CHECK_VALUE5("nValue5")
$spt1 = CHECK_VALUEspt1("nValuespt1")
$spt2 = CHECK_VALUEspt2("nValuespt2")
$spt3 = CHECK_VALUEspt3("nValuespt3")
$spb1 = CHECK_VALUEspb1("nValuespb1")
$spb2 = CHECK_VALUEspb2("nValuespb2")
$spb3 = CHECK_VALUEspb3("nValuespb3")

If (($card1 == 11) AND ($card1 + $card2 + $card3 + $card4 + $card5 > 21)) Then $card1 = 1
If (($card2 == 11) AND ($card1 + $card2 + $card3 + $card4 + $card5 > 21)) Then $card2 = 1
If (($card3 == 11) AND ($card1 + $card2 + $card3 + $card4 + $card5 > 21)) Then $card3 = 1
If (($card4 == 11) AND ($card1 + $card2 + $card3 + $card4 + $card5 > 21)) Then $card4 = 1
If (($card5 == 11) AND ($card1 + $card2 + $card3 + $card4 + $card5 > 21)) Then $card5 = 1

$mytotal = $card1 + $card2 + $card3 + $card4 + $card5
$results = $mytotal & @CRLF & $dealcard & @CRLF & $card1 & @CRLF & $card2 & @CRLF & $card3 & @CRLF & $card4 & @CRLF & $card5
ToolTip($results, 0, 0)
sleep(5000)
ClipPut($results)

    If $dealcard == 1 Then
        Select
        Case (($card1 == 2 AND $card2 == 2) Or ($card1 == 3 AND $card2 == 3) Or ($card1 == 4 AND $card2 == 4) Or ($card1 == 5 AND $card2 == 5) Or ($card1 == 6 AND $card2 == 6) Or ($card1 == 7 AND $card2 == 7)) 
        ControlClick("Program Name", "209", "209")
        Case ($card1 == 8 AND $card2 == 8) 
        If ControlCommand( "Program Name", "214", "214", "IsVisible", "1" ) Then
        ControlClick("Program Name", "214", "214")
        ElseIf ControlCommand( "Program Name", "214", "214", "IsVisible", "0" ) Then
        ControlClick("Program Name", "211", "211")

($card1 = $spt1 And $card2 = $spt2)

EndIf
        Case (($card1 == 9 AND $card2 == 9) Or ($card1 == 10 AND $card2 == 10)) 
        ControlClick("Program Name", "208", "208")
        Case ($card1 == 1 AND $card2 == 1) 
        ControlClick("Program Name", "211", "211")
        Case (($mytotal < 11) AND ($card1 <> 11 Or $card2 <> 11)) 
        ControlClick("Program Name", "209", "209")
        Case (($mytotal == 11) AND ($card1 <> 11 Or $card2 <> 11)) 
        ControlClick("Program Name", "210", "210")
        $currentvalue = (IniRead ("counter.ini", "counter", "currentcount", "0" ) + 1)
      Iniwrite ( "counter.ini", "counter", "currentcount", $currentvalue)
        Case (($mytotal >= 12 And $mytotal <= 14) AND ($card1 <> 11 Or $card2 <> 11)) 
        ControlClick("Program Name", "209", "209")
        Case (($mytotal >= 15 And $mytotal <= 16) AND ($card1 <> 11 Or $card2 <> 11))
        If ControlCommand( "Program Name", "214", "214", "IsVisible", "1" )  Then
        ControlClick("Program Name", "214", "214")
        ElseIf ControlCommand( "Program Name", "214", "214", "IsVisible", "0" ) Then
        ControlClick("Program Name", "209", "209")
        EndIf
        Case (($mytotal == 17) AND ($card1 <> 11 Or $card2 <> 11)) 
        If ControlCommand( "Program Name", "214", "214", "IsVisible", "1" ) Then
        ControlClick("Program Name", "214", "214")
        ElseIf ControlCommand( "Program Name", "214", "214", "IsVisible", "0" ) Then
        ControlClick("Program Name", "208", "208")
        EndIf
        Case ($mytotal >= 13 And $mytotal <= 18) 
        ControlClick("Program Name", "209", "209")
        Case ($mytotal >= 19 And $mytotal <= 20) 
        ControlClick("Program Name", "208", "208")
         Case Else
      If ControlCommand( "Program Name", "112", "112", "IsVisible", "1" ) Then
      ControlClick("Program Name", "112", "112")    
  EndIf
EndSelect
Sleep(1000)
EndIf
WEnd

Then I would like to run it back through the next time with

($card1 = $spb1 And $card2 = $spb2)

Then after that I want it to reset back to $card1 = CHECK_VALUE1("nValue1")

I hope this makes more sense

By the way for some reason this code gets stuck at If Else If statement within the case and I am not sure why this is

Link to comment
Share on other sites

yes, the while loop is never ending

Honestly, I have no idea what you're driving at

My best understanding of your description is this:

$x = 1, $y = 2, $z = 3

While 1

$temp = $x
$x = $y
$y = $z
$z = $temp

MsgBox(0, "Testing...", "x:" & $x & @CRLF & "y:" & $y & @CRLF & "z:" & $z)

WEnd

The speed of sound is defined by the distance from door to computer divided by the time interval needed to close the media player and pull up your pants when your mom shouts "OH MY GOD WHAT ARE YOU DOING!!!"

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...