Jump to content

Easy if and else


Go to solution Solved by argumentum,

Recommended Posts

Posted

Hello,

I have this code :

Global $nbClass = Number(GUICtrlRead($ClassNumber))
                           
                            If $nbClass > 0 Then
                            
                            While $ok2

                                            MsgBox(0, '', "is ok")    
                                    Else
                                        
                                        while $ok4
                                        
                                    
                                        _logMessage("Class number must be one number.", 0)
                                    
                                            $ok4 = False                                        
                                        WEnd
                                   
                                WEnd
                            EndIf

 

I want show message logmessage if $classnumber is up to 0.

 

But why i exit all loop, i want repeat error

_logMessage("Class number must be one number.", 0)

And when is one number  up to 0, I exit all loop.

 

THX

Posted

hello.

I send my code :

 

Global $ok2 = True 
                        Global $ok3 = True
                        
                        MsgBox(0, '$ok2', $ok2)
                        MsgBox(0, '$ok3', $ok3)
                        

                        
                        Global $nbFarm = Number(GUICtrlRead($ClassNumber))
                        
                        while $ok2
                        
                            While $ok3
                        If $nbclass Then 
                        
                            
                            MsgBox(0, '', 'class ok')
                            
                            
                            $ok2 = False
                            
                            
                        Else
                            
                            MsgBox(0, 'ERROR', "Class number must be one number.")
                            
                            $ok2 = False
                            ;ExitLoop 
                             
                        EndIf
                    WEnd 
                    WEnd

 

Posted
Global $ok2 = True 
                        Global $ok3 = True
                        
                        MsgBox(0, '$ok2', $ok2)
                        MsgBox(0, '$ok3', $ok3)
                        

                        
                        Global $nbclass = Number(GUICtrlRead($ClassNumber))
                        
                        while $ok2
                        
                            While $ok3
                        If $nbclass Then 
                        
                            
                            MsgBox(0, '', 'class ok')
                            
                            
                            $ok2 = False
                            
                            
                        Else
                            
                            MsgBox(0, 'ERROR', "Class number must be one number.")
                            
                            $ok2 = False
                            ;ExitLoop 
                             
                        EndIf
                    WEnd 
                    WEnd

 

Posted (edited)

Please post a code with the needed gui elements ...

something that we can copy/paste and run to see what is not going ok.

 

something like this:
 

GUICreate("hi", 320, 200)
$ClassNumber = GUICtrlCreateInput("1", 1, 1, 30, 30)
GUISetState()

Global $ok2 = True
Global $ok3 = True

MsgBox(0, '$ok2', $ok2)
MsgBox(0, '$ok3', $ok3)

While $ok2

    While $ok3
        Global $nbclass = Number(GUICtrlRead($ClassNumber))
        If $nbclass Then
            MsgBox(0, '', 'class ok' & @crlf & $nbclass & @CRLF & "Is it a number: " & IsNumber($nbclass) & @crlf & "Is it an integer: " & IsInt($nbclass))
            $ok2 = False
        Else
            MsgBox(0, 'ERROR', "Class number must be one number.")
            $ok2 = False
            ;ExitLoop
        EndIf
    WEnd
WEnd

 

Edited by Dan_555

Some of my script sourcecode

  • Developers
Posted (edited)
24 minutes ago, Kralamour said:

hello.

I send my code :

Guess you haven't tried to run that, as it won't run!
Also, please try to make your code better readable by tidying it with proper indentations:

Global $ok2 = True
Global $ok3 = True

MsgBox(0, '$ok2', $ok2)
MsgBox(0, '$ok3', $ok3)
Global $nbclass = Number(GUICtrlRead($ClassNumber))
While $ok2
    While $ok3
        If $nbclass Then
            MsgBox(0, '', 'class ok')
            $ok2 = False
        Else
            MsgBox(0, 'ERROR', "Class number must be one number.")
            $ok2 = False
            ;ExitLoop
        EndIf
    WEnd
WEnd

This way you can see that the code really doesn't make any sense having these 2 While-Wend loops, of which one depends on $ok3, which will never change in your code. Also the ok2 will never change as you aren't updating $nbclass inside the While-Wend loops.

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

Thank you.

If i take this code :

GUICreate("hi", 320, 200)
$ClassNumber = GUICtrlCreateInput("1", 1, 1, 30, 30)
GUISetState()

Global $nbclass = Number(GUICtrlRead($ClassNumber))
While $ok2
    While $ok3
        If $nbclass Then
            MsgBox(0, '', 'class ok')
            $ok2 = False
        Else
            MsgBox(0, 'ERROR', "Class number must be one number.")
            $ok2 = False
            ;ExitLoop
        EndIf
    WEnd
WEnd

 

I don't know how to ask everytime a class value in input and not send error if classnumber is one number up to 1 value

 

THX

 

  • Developers
Posted (edited)

Just THINK and RTFM in an effort to understand your own code. comeback when you have some progress to show for.

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

I have this but don't work at 100%

I don't know hot close message box for edit input because is 0 or not number

 

I have write and try is my code, i can't make more :

 

Global $ok2 = True 

GUICreate("test", 320, 200)
$ClassNumber = GUICtrlCreateInput("1", 1, 1, 30, 30)
GUISetState()



Global $nbclass = Number(GUICtrlRead($ClassNumber))

while $ok2

  If $nbclass > 0 Then 

    MsgBox(0, '', 'class ok, number up to 0')
    ;exit while
    $ok2 = False

  Else

    MsgBox(0, 'ERROR', "Class number must be one number = or upo to 0.")

    $ok2 = False
    
    #ASK AGAIN A NUMBER BECAUSE IS WRONG

  EndIf

WEnd

Please i very need help.

I think is easy but i have never make this.

Posted
Global $ok2 = True 

GUICreate("test", 320, 200)
$ClassNumber = GUICtrlCreateInput("1", 1, 1, 30, 30)
GUISetState()



Global $nbclass = Number(GUICtrlRead($ClassNumber))

while $ok2

  If $nbclass > 0 Then 

    MsgBox(0, '', 'class ok, number up to 0')
    ;exit while
    $ok2 = False

  Else

    MsgBox(0, 'ERROR', "Class number must be one number = or upo to 0.")

    $ok2 = False
    
    ;ASK AGAIN A NUMBER BECAUSE IS WRONG

  EndIf

WEnd

 

Posted

Hello thank you.

I have this now :

GUICreate("test", 320, 200)
$ClassNumber = GUICtrlCreateInput("1", 1, 1, 30, 30)
GUISetState()

While $ok2

        
        Global $ok2 = True
        Global $ok3 = True
        
        MsgBox(0, '', $ok2)
        
        Global $nbclass = Number(GUICtrlRead($ClassNumber))
        
        If $nbclass Then
            MsgBox(0, '', 'class ok')
            $ok2 = False
        Else
            
         While $ok3
            
            MsgBox(0, 'ERROR', "Class number must be one number.")
            $ok3 = False
            ExitLoop
             
        WEnd 
            
        EndIf
    WEnd

All is ok but why i not exit loop in *else*

Every time he show erreor msgbox.
 

Posted
35 minutes ago, Kralamour said:

I have this now :

My english is limited. I tend to speak code but I'll use language because your coding is.... without practical use.
What do you envision ?, what's the idea ?. If you present your practical need for a real scenario maybe we ( any of us here ) can give you a better head start.

Welcome to coding..., does your nick mean "king of love" ?, meh, welcome to the forum :ILA2:

42 minutes ago, Kralamour said:
While $ok2

        
        Global $ok2 = True
        Global $ok3 = True

...and, don't declare a global in a loop. Do something like:

... ...
Global $ok2 = True, $ok3 = True
While $ok2
        $ok2 = True
        $ok3 = True
        ... ...

:) 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted

Hello.

From where are you ?

For my code i have edit :

Global $ok2 = True
Global $ok3 = True

GUICreate("test", 320, 200)
$ClassNumber = GUICtrlCreateInput("1", 1, 1, 30, 30)
GUISetState()

While $ok2
        
        Global $nbclass = Number(GUICtrlRead($ClassNumber))
        
        If $nbclass Then
            MsgBox(0, '', 'class ok')
            $ok2 = False
        Else
            
         While $ok3
            
            MsgBox(0, 'ERROR', "Class number must be one number.")
            $ok3 = False
            ExitLoop
             
        WEnd 
            
        EndIf
    WEnd

But when i have click on error message after if i edit classnumber i don"t have message.

I think isd because he is on one loop.

 

Can you help me please ?

Posted
51 minutes ago, Kralamour said:

From where are you ?

Argentina

51 minutes ago, Kralamour said:

Can you help me please ?

..not really because:

1 hour ago, argumentum said:

What do you envision ?, what's the idea ?. If you present your practical need for a real scenario maybe we ( any of us here ) can give you a better head start.

 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted

I have one INPUT on my GUI.

I want check if this INPUT are up to 0.

If INPUT VALUE is 0 i want say withg MsgBox to enter a true value.

If all is ok, leave loop

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
  • Recently Browsing   0 members

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