Jump to content

Finding Unwanted String


Recommended Posts

I have created a number game:

CODE
#include <GUIConstants.au3>

GUICreate("Number Game", 500, 600)

$numbers=GUICtrlCreateLabel("000", 231, 20, 50)

GUICtrlSetFont($numbers, 18)

$gen = GUICtrlCreateButton("Generate", 210, 50, 80, 25, $BS_DEFPUSHBUTTON)

GUICtrlCreateLabel("Small: Big:", 55, 75)

GUICtrlCreateLabel("Numbers:", 5, 93)

$small = GUICtrlCreateInput(5, 55, 90, 60, 20, $ES_CENTER)

$big = GUICtrlCreateInput(1, 120, 90, 60, 20, $ES_CENTER)

$sum = GUICtrlCreateInput("", 200, 150, 200)

$try = GUICtrlCreateButton("Try", 410, 150)

$sbnumbers = GUICtrlCreateInput("",1000,1000);not used

GUISetState()

While 1

Switch GUIGetMsg()

Case $GUI_EVENT_CLOSE

Exit

Case $gen

Gen()

Case $try

If Execute(GUICtrlRead($sum)) = GUICtrlRead($numbers) Then MsgBox(0, "Well done", "You got " & Execute(GUICtrlRead($sum)) & @CRLF & "You successfully completed the challenge")

If Execute(GUICtrlRead($sum)) <> GUICtrlRead($numbers) Then MsgBox(0, "Unlucky", "You were " & Abs(Execute(GUICtrlRead($sum))-GUICtrlRead($numbers)) & " away from the number")

;~ Case $msg =

;~ Case $msg =

EndSwitch

WEnd

Func Gen()

GUICtrlDelete($sbnumbers)

GUICtrlSetData($sum, "")

For $i = 1 To 20

$rand = Random(100, 999, 1)

GUICtrlSetData($numbers, $rand)

Sleep(50)

If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit

Next

$bign = GUICtrlRead($big)

$smalln = GUICtrlRead($small)

If $smalln + $bign > 6 Then

MsgBox(48, "Numbers", "A maximum of 6 numbers is allowed")

If $bign > $smalln Then

$bigger = 1

ElseIf $bign <= $smalln Then

$bigger = 2

EndIf

Do

$bign = GUICtrlRead($big)

$smalln = GUICtrlRead($small)

If $bigger = 1 Then

GUICtrlSetData($big, $bign - 1)

ElseIf $bigger = 2 Then

GUICtrlSetData($small, $smalln - 1)

EndIf

Until GUICtrlRead($big) + GUICtrlRead($small) = 6

EndIf

$bign = GUICtrlRead($big)

$smalln = GUICtrlRead($small)

$rand = Random(1,4,1)

If $rand = 1 Then $rand = 25

If $rand = 2 Then $rand = 50

If $rand = 3 Then $rand = 75

If $rand = 4 Then $rand = 100

$sbnumbers = GUICtrlCreateLabel($rand, 190, 92, 200)

For $i = 1 To $bign - 1

$rand = Random(1,4,1)

If $rand = 1 Then $rand = 25

If $rand = 2 Then $rand = 50

If $rand = 3 Then $rand = 75

If $rand = 4 Then $rand = 100

GUICtrlSetData($sbnumbers, GUICtrlRead($sbnumbers) & ", " & $rand)

Next

$rand = Random(1,10,1)

GUICtrlSetData($sbnumbers, GUICtrlRead($sbnumbers) & ", " & $rand)

For $i = 1 To $smalln - 1

$rand = Random(1,10,1)

GUICtrlSetData($sbnumbers, GUICtrlRead($sbnumbers) & ", " & $rand)

Next

EndFunc

when you click generate, six numbers appear, the idea is you must get the large 3 digit number using the six numbers at most once each and +-/* I want my program to check that any numbers except the six random ones are not allowed

It might go something like this:

_CheckOnlyStrings("string", "allowed|allowed2")
And _CheckOnlyStrings("string", "allowed|allowed2") would return 0 if "string" had anything except allowed or allowed2


            
                


    Edited  by RazerM
    
    

            
        

        

        
            

    
        

        
            
My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
        
    

        
    

    

    




    Link to comment
    
        
    
    
    

    
    Share on other sites
    

    
        
            

    

        
            

    

        
            

    

        
            

    

        
    


    
    More sharing options...

    


    

                    
                    
                    
                

                    

                    
                    





    

    

    
        
            
                


    
        
    

                
                
                    
                        

                    
                
            
        
        
            
                


elgabionline
            
            
                Posted 
                
            
        
    
    
        


elgabionline
            
        
        
            
                
                    


    
        
    

                    
                    
                        

                    
                
            
            
                Active Members
                
            
            
                
                    
                        
                            
                                
                            
                                 105
                            
                                
                            
                        
                        
                    
                
            
            
                

            
        
    
    
        



    
        
            
                
                    
                    
                    
                    
                    
                
            
            
                
                    
                    
                        
                        
                            Share
                        
                        
                        
                        
                        
                            
                                
                            
                            
                            
                            
                            
                            
                        
                    
                
                
            
        

        
            Posted 
            
            
                
                
            
        
    

    

    

    
        
        
            I have created a number game:

It might go something like this:
_CheckOnlyStrings("string", "allowed|allowed2")
And _CheckOnlyStrings("string", "allowed|allowed2")

would return 0 if "string" had anything except allowed or allowed2

Allow me to see if I have the point...

#include <GUIConstants.au3>
GUICreate("Number Game", 500,600)
$numbers=GUICtrlCreateLabel("000", 231, 20, 50)
GUICtrlSetFont($numbers, 18)
$gen = GUICtrlCreateButton("Generate", 210, 50, 80, 25,$BS_DEFPUSHBUTTON)
GUICtrlCreateLabel("Small:           Big:", 55,75)
GUICtrlCreateLabel("Numbers:", 5, 93)
$small = GUICtrlCreateInput(5, 55, 90, 60, 20, $ES_CENTER)
$big = GUICtrlCreateInput(1, 120, 90, 60, 20, $ES_CENTER)
$sum = GUICtrlCreateInput("", 200, 150, 200)
$try = GUICtrlCreateButton("Try",  410, 150)
$sbnumbers =GUICtrlCreateInput("",1000,1000);not usedGUISetState()
GUISetState ()
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $gen
            Gen()
        Case $try
            If Not _CheckOnlyStrings(GUICtrlRead($sum), GUICtrlRead ($sbnumbers)) then;<=========== This you need?
                MsgBox (0,"Bad done","Your input is not valid")
            Else
                If Execute(GUICtrlRead($sum)) = GUICtrlRead($numbers) Then MsgBox(0, "Well done", "You got " & Execute(GUICtrlRead($sum)) & @CRLF & "You successfully completed the challenge")
                If Execute(GUICtrlRead($sum)) <> GUICtrlRead($numbers) Then MsgBox(0, "Unlucky", "You were " & Abs(Execute(GUICtrlRead($sum))-GUICtrlRead($numbers)) & " away from the number")
            EndIf
                
;~ Case $msg = 
;~ Case $msg =
    EndSwitch
WEnd

Func Gen()
    GUICtrlDelete($sbnumbers)
    GUICtrlSetData($sum, "")
    For $i = 1 To 20
        $rand = Random(100, 999, 1)
        GUICtrlSetData($numbers, $rand)
        Sleep(50)
        If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
    Next
    $bign = GUICtrlRead($big)
    $smalln = GUICtrlRead($small)
    If $smalln + $bign > 6 Then
        MsgBox(48, "Numbers", "A maximum of 6 numbers is allowed")
        If $bign > $smalln Then
            $bigger = 1
        ElseIf $bign <= $smalln Then
            $bigger = 2
        EndIf
        Do
            $bign = GUICtrlRead($big)
            $smalln = GUICtrlRead($small)
            If $bigger = 1 Then
                GUICtrlSetData($big, $bign - 1)
            ElseIf $bigger = 2 Then
                GUICtrlSetData($small, $smalln - 1)
            EndIf
        Until GUICtrlRead($big) + GUICtrlRead($small) = 6
    EndIf
    $bign = GUICtrlRead($big)
    $smalln = GUICtrlRead($small)
    $rand = Random(1,4,1)
    If $rand = 1 Then $rand = 25
    If $rand = 2 Then $rand = 50
    If $rand = 3 Then $rand = 75
    If $rand = 4 Then $rand = 100
    $sbnumbers = GUICtrlCreateLabel($rand, 190, 92, 200)
    For $i = 1 To $bign - 1
        $rand = Random(1,4,1)
        If $rand = 1 Then $rand = 25
        If $rand = 2 Then $rand = 50
        If $rand = 3 Then $rand = 75
        If $rand = 4 Then $rand = 100
        GUICtrlSetData($sbnumbers, GUICtrlRead($sbnumbers) & ", " & $rand)
    Next
    $rand = Random(1,10,1)
    GUICtrlSetData($sbnumbers, GUICtrlRead($sbnumbers) & ", " & $rand)
    For $i = 1 To $smalln - 1
        $rand = Random(1,10,1)
        GUICtrlSetData($sbnumbers, GUICtrlRead($sbnumbers) & ", " & $rand)
    Next
EndFunc



Func _CheckOnlyStrings($s_COS1, $s_COS2)
    
    Local $bool=False
    $s_COS2=StringReplace ($s_COS2," ","")
    $s_COS2=StringSplit ($s_COS2,",")
    
    If not IsArray ($s_COS2) Then
        Return
    Else
        For $loop=1 To $s_COS2[0]
            If $s_COS2[$loop]=$s_COS1 Then $bool=True
        Next
        Return $bool
    EndIf
EndFunc

Does that make what is supposed that has to make? Or were you looking for for another thing?

Link to comment
Share on other sites

thanks that is perfect

Edited by RazerM
My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
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...