Sign in to follow this  
Followers 0
baamr

Help With controlling loops

5 posts in this topic

I made a small script witch reads a barcode and starts different tests

depending on barcode.

Is there a smoother way of looping it?

Local $bLoop = 1

While $bLoop = 1

Global $str = InputBox ( " Test ", "Please read your Barcode with scanner", "", "", 100 , 150 ,700 ,450 )

If @error = 1 Then

SplashTextOn ( "You clicked on Cancel or Exit", "Bye Bye......", 200 , 100 )

Sleep (1500)

SplashOff()

Exitloop

Else

Local $Code_len = StringLen ($str)

Local $Partno = $Code_len - 6

Local $Partnr = StringTrimRight ($str, $Partno)

ClipPut ($str)

If $Partnr = "342323" Then

SplashTextOn ( "Info", "Starting Test 1", 200 , 100 )

Sleep (1000)

SplashOff()

ShellExecute(@ProgramFilesDir & "\something\filename1")

$bLoop = 0 ;

ElseIf $Partnr = "544376" Then

SplashTextOn ( "Info", "Starting Test 2", 200 , 100 )

Sleep (1000)

SplashOff()

ShellExecute(@ProgramFilesDir & "\something\filename2")

$bLoop = 0 ;

ElseIf $Partnr = "895762" Then

SplashTextOn ( "Info", "Starting Test 3", 200 , 100 )

Sleep (1000)

SplashOff()

ShellExecute(@ProgramFilesDir & "\something\filename3")

$bLoop = 0 ;

ElseIf $Partnr = "603444" Then

SplashTextOn ( "Info", "Starting Test 4", 200 , 100 )

Sleep (1000)

SplashOff()

ShellExecute(@ProgramFilesDir & "\something\filename4")

$bLoop = 0 ;

ElseIf $Partnr = "319824" Then

SplashTextOn ( "Info", "Starting Test 5", 200 , 100 )

Sleep (1000)

SplashOff()

ShellExecute(@ProgramFilesDir & "\something\filename5")

$bLoop = 0 ;

ElseIf $Partnr = "324400" Then

SplashTextOn ( "Info", "Starting Test 6", 200 , 100 )

Sleep (1000)

SplashOff()

ShellExecute(@ProgramFilesDir & "\something\filename6")

$bLoop = 0 ;

ElseIf $Partnr = "306713" Then

SplashTextOn ( "Info", "Starting Test 7", 200 , 100 )

Sleep (1000)

SplashOff()

ShellExecute(@ProgramFilesDir & "\something\filename7")

$bLoop = 0 ;

Endif

EndIf

WEnd

Share this post


Link to post
Share on other sites



i don't see why do you use loop in this code at all

maybe you can tell us what is your definition of "smoother way of looping it"

if your definition is short code and easy to understand than this can help

While 1
    $str = InputBox(" Test ", "Please read your Barcode with scanner", "", "", 100, 150, 700, 450)
    If @error Then
        SplashTextOn("You clicked on Cancel or Exit", "Bye Bye......", 200, 100)
        Sleep(1500)
        SplashOff()
        Exit
    EndIf
    $Partnr = StringTrimRight($str, StringLen($str) - 6)
    ClipPut($str)
    Switch $Partnr
        Case "342323"
            somefunc(1)
        Case "544376"
            somefunc(2)
        Case "895762"
            somefunc(3)
        Case "603444"
            somefunc(4)
        Case "319824"
            somefunc(5)
        Case "324400"
            somefunc(6)
        Case "306713"
            somefunc(7)
    EndSwitch
WEnd
Func somefunc($data)
    SplashTextOn("Info", "Starting Test "&$data, 200, 100)
    Sleep(1000)
    SplashOff()
;~ ShellExecute(@ProgramFilesDir & "somethingfilename"&$data)
    Exit
EndFunc

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

i don't see why do you use loop in this code at all

maybe you can tell us what is your definition of "smoother way of looping it"

if your definition is short code and easy to understand than this can help

While 1
$str = InputBox(" Test ", "Please read your Barcode with scanner", "", "", 100, 150, 700, 450)
If @error Then
     SplashTextOn("You clicked on Cancel or Exit", "Bye Bye......", 200, 100)
     Sleep(1500)
     SplashOff()
     Exit
EndIf
$Partnr = StringTrimRight($str, StringLen($str) - 6)
ClipPut($str)
Switch $Partnr
     Case "342323"
         somefunc(1)
     Case "544376"
         somefunc(2)
     Case "895762"
         somefunc(3)
     Case "603444"
         somefunc(4)
     Case "319824"
         somefunc(5)
     Case "324400"
         somefunc(6)
     Case "306713"
         somefunc(7)
EndSwitch
WEnd
Func somefunc($data)
SplashTextOn("Info", "Starting Test "&$data, 200, 100)
Sleep(1000)
SplashOff()
;~ ShellExecute(@ProgramFilesDir & "somethingfilename"&$data)
Exit
EndFunc

Hi BogQ,

Thanks for Your reply.

I just used the Loop because it gave me a working code :-)

I`m a newbe to programming, generally speaking so i try to learn from

This excellent site.

Reason why i used a while Loop is because i wanted a simple Inputbox

for the barcode and it should dissapear after executing correct test.

What`s the difference between using switch/Case and IF/Else IF/Else ?

Share this post


Link to post
Share on other sites

What`s the difference between using switch/Case and IF/Else IF/Else ?

Easier to read and less code to write. When programming, you want to simplify as much as possible. Remember irrational equations in algebra?


Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Share this post


Link to post
Share on other sites

Easier to read and less code to write. When programming, you want to simplify as much as possible. Remember irrational equations in algebra?

I Agree,absolutely less code. And also more easy when adding functions later.

Thanks Again....

Share this post


Link to post
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
Sign in to follow this  
Followers 0