Jump to content
Sign in to follow this  
Yata

Check if an input is empty and then exempt it from evaluation

Recommended Posts

Yata

Hello again,

I need help with the program I've been writing. The way the program works is this:

The user inputs deviantART art page URLs and when the user presses a button, it is processed by calling upon a function to trim the URLS of the undeeded parts and pass along the needed part to a result function which is called right after the process function. This function displays the results in a GUI.

The problem is that if a user leaves a field blank the program crashes with:

Posted Image

But if all fields are filled correctly the program works as expected.

I need for the script to not evaluate blank fields, and exempt the correct parts of the text in the result GUI so that there's no lose ends. But I have no idea where to start, or what to do. Here is my source code. Please don't steal it for your own programs.

#include <GUIConstants.au3>
#NoTrayIcon

Func thumbextract()

    $a = StringRegExp ( $string,'.+-(\d+)',3 )
    $a2 = StringRegExp ( $string2,'.+-(\d+)',3 )
    $a3 = StringRegExp ( $string3,'.+-(\d+)',3 )
    $a4 = StringRegExp ( $string4,'.+-(\d+)',3 )
    $a5 = StringRegExp ( $string5,'.+-(\d+)',3 )

EndFunc

Func results()
    
    GUICreate("Thumbs Extracted", 300, 150, -1 )
    GUICtrlCreateEdit( ":thumb" & $a[0] & ": " & ":thumb" & $a2[0] & ": " & ":thumb" & $a3[0] & ": " & ":thumb" & $a4[0] & ": " & ":thumb" & $a5[0] & ": ", 10, 12, 275, 100, 0x0800)
    GUISetState(@SW_SHOW)
    
EndFunc

GUICreate("Thumb Extract", 425, 259)
    $input1 = GUICtrlCreateInput ( "", 10, 15, 400 )
    $input2 = GUICtrlCreateInput ( "", 10, 50 )
    $input3 = GUICtrlCreateInput ( "", 10, 85 )
    $input4 = GUICtrlCreateInput ( "", 10, 120 )
    $input5 = GUICtrlCreateInput ( "", 10, 155 )
    $button = GUICtrlCreateButton ( "Gather Thumbcode", 60, 190, 100, 23 )
    $help = GUICtrlCreateButton ( "Need Help?", 240, 190, 100, 23 )
    GUISetState (@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Select
        
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
            
        Case $msg = $button
            $string = GUICtrlRead($input1)
            $string2 = GUICtrlRead($input2)
            $string3 = GUICtrlRead($input3)
            $string4 = GUICtrlRead($input4)
            $string5 = GUICtrlRead($input5)
        
            $a = $string
            $a2 = $string2
            $a3 = $string3
            $a4 = $string4
            $a5 = $string5
        
            Call ( "thumbextract" )
            Call ( "results" )
        
    EndSelect
    
Wend

Thank you.

Share this post


Link to post
Share on other sites
evilertoaster

try this-

#include <GUIConstants.au3>
#NoTrayIcon

GUICreate("Thumb Extract", 425, 259)
$input1 = GUICtrlCreateInput ( "", 10, 15, 400 )
$input2 = GUICtrlCreateInput ( "", 10, 50 )
$input3 = GUICtrlCreateInput ( "", 10, 85 )
$input4 = GUICtrlCreateInput ( "", 10, 120 )
$input5 = GUICtrlCreateInput ( "", 10, 155 )
$button = GUICtrlCreateButton ( "Gather Thumbcode", 60, 190, 100, 23 )
$help = GUICtrlCreateButton ( "Need Help?", 240, 190, 100, 23 )
GUISetState (@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $button
            $string = GUICtrlRead($input1)
            $string2 = GUICtrlRead($input2)
            $string3 = GUICtrlRead($input3)
            $string4 = GUICtrlRead($input4)
            $string5 = GUICtrlRead($input5)
            $a = $string
            $a2 = $string2
            $a3 = $string3
            $a4 = $string4
            $a5 = $string5
            Call ( "thumbextract" )
            Call ( "results" )
    EndSelect
Wend

Func thumbextract()
    $a = StringRegExp ( $string,'.+-(\d+)',3 )
    $a2 = StringRegExp ( $string2,'.+-(\d+)',3 )
    $a3 = StringRegExp ( $string3,'.+-(\d+)',3 )
    $a4 = StringRegExp ( $string4,'.+-(\d+)',3 )
    $a5 = StringRegExp ( $string5,'.+-(\d+)',3 )
EndFunc

Func results()
    GUICreate("Thumbs Extracted", 300, 150, -1 )
    $parse=""
    if UBound($a)<>0 then $parse&=":thumb" & $a[0] & ": "
    if UBound($a2)<>0 then $parse&=":thumb" & $a2[0] & ": "
    if UBound($a3)<>0 then $parse&=":thumb" & $a3[0] & ": "
    if UBound($a4)<>0 then $parse&=":thumb" & $a4[0] & ": "
    if UBound($a5)<>0 then $parse&=":thumb" & $a5[0] & ": "
    GUICtrlCreateEdit( $parse, 10, 12, 275, 100, 0x0800)
    GUISetState(@SW_SHOW)
EndFunc

Share this post


Link to post
Share on other sites
Yata

Ah, thank you so much. I didn't even think about doing it like that. It works perfectly too.

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  

×