ju4711

If,then,else does not work in variables?

9 posts in this topic

#1 ·  Posted

Hello Guys. I want to create a little programm where you can make messageboxes and save them (for people who dont know how to do that themself :3). I have some kinda radio field buttons to decide what icon the messagebox should show. With the inputboxes, i do it like this:

 

            $FinalTitle = GUICtrlRead($Title)
            $FinalMessage = GUICtrlRead($Message)
            MsgBox($FinalIcon,$FinalTitle,$FinalMessage)

 

But for some reason the one with the icon does not work properly: 

 

            $FinalIcon = If GUICtrlRead($Error) = 1 Then
             <syntax error>
            GUICtrlSetData($FinalIcon,16)

 

 

Please help me, im a noob :D

Share this post


Link to post
Share on other sites



#2 ·  Posted

24 minutes ago, ju4711 said:

  $FinalIcon = If GUICtrlRead($Error) = 1 Then

This isn't valid syntax. You should probably look into Select...Case...EndSelect in the help file.

Share this post


Link to post
Share on other sites

#3 ·  Posted

are you trying to do something like the CodeWizard that is available in the Full Scite install under the Tools menu?

 

Also, what Danp2 said is correct.


Share this post


Link to post
Share on other sites

#4 ·  Posted

@ju4711 it is a bit difficult to ascertain what you are trying to do from such a small non-runnable snippet. You appear to be trying to read from a control on your GUI named $Error, but you're leaving us to guess whether this is an input, a combo box, etc. How about helping us help you and posting your code, or at least a runnable reproducer? ;)

 

1 person likes this

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#5 ·  Posted

Well , youre right. I will just copy and paste the whole script in here:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1_1 = GUICreate("My MsgBox", 654, 221, 174, 117)
$Exit = GUICtrlCreateMenu("&Exit")
$Credits = GUICtrlCreateMenu("&Credits")
$Help = GUICtrlCreateMenu("&Help")
$Generate = GUICtrlCreateButton("Generate", 248, 128, 155, 49)
$Error = GUICtrlCreateRadio("Error (Icon)", 32, 48, 115, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$Warning = GUICtrlCreateRadio("Warning (Icon)", 32, 96, 115, 17)
$Information = GUICtrlCreateRadio("Information (Icon)", 32, 144, 115, 17)
$Title = GUICtrlCreateInput("Type in your title here.", 248, 48, 153, 21)
$Message = GUICtrlCreateInput("Type in your message here.", 248, 88, 153, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

#NoTrayIcon

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Generate
            $FinalIcon = If GUICtrlRead($Error) = $GUI_CHECKED  Then
                GUICtrlSetData($FinalIcon,16)
                GUICtrlRead($FinalIcon)
            $FinalTitle = GUICtrlRead($Title)
            $FinalMessage = GUICtrlRead($Message)
            MsgBox($FinalIcon,$FinalTitle,$FinalMessage)

 

 

Okay, i hope you can work with that xd ^^. $Error for example is just the radio field button to choose an icon and $FinalError is that what comes out from "GuiCtrlRead"

Share this post


Link to post
Share on other sites

#6 ·  Posted

Better, but still confusing. You have an IF with no EndIF. So, if $Error is checked, do you want to perform one of the actions below, or all of them?

GUICtrlSetData($FinalIcon,16)
GUICtrlRead($FinalIcon)
$FinalTitle = GUICtrlRead($Title)
$FinalMessage = GUICtrlRead($Message)
MsgBox($FinalIcon,$FinalTitle,$FinalMessage)

 

1 person likes this

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#7 ·  Posted

oh. Well, if $Error is checked, the programm should change the data of $FinalIcon to 16 so that the msgbox showes the right icon.

I guess that would mean... After the "GuiCtrlRead($FinalIcon)" there should be an Endif. (Im not sure tbh :/)

Share this post


Link to post
Share on other sites

#8 ·  Posted

ju4711,

Is this what you are trying to do...?

; *** Start added by AutoIt3Wrapper ***
#include <GUIConstantsEx.au3>
; *** End added by AutoIt3Wrapper ***

#include <WindowsConstants.au3>

#AutoIt3Wrapper_Add_Constants=n

#Region ### START Koda GUI section ### Form=
$Form1_1 = GUICreate("My MsgBox", 654, 221, 174, 117)
$Exit = GUICtrlCreateMenu("&Exit")
$Credits = GUICtrlCreateMenu("&Credits")
$Help = GUICtrlCreateMenu("&Help")
$Generate = GUICtrlCreateButton("Generate", 248, 128, 155, 49)
$Error = GUICtrlCreateRadio("Error (Icon)", 32, 48, 115, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$Warning = GUICtrlCreateRadio("Warning (Icon)", 32, 96, 115, 17)
$Information = GUICtrlCreateRadio("Information (Icon)", 32, 144, 115, 17)
$Title = GUICtrlCreateInput("Type in your title here.", 248, 48, 153, 21)
$Message = GUICtrlCreateInput("Type in your message here.", 248, 88, 153, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

#NoTrayIcon

Local $finalicon

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Generate
            If GUICtrlRead($Error) = $GUI_CHECKED Then $finalicon = 16
            If GUICtrlRead($Warning) = $GUI_CHECKED Then $finalicon = 48
            If GUICtrlRead($Information) = $GUI_CHECKED Then $finalicon = 64
            $FinalTitle = GUICtrlRead($Title)
            $FinalMessage = GUICtrlRead($Message)
            MsgBox($finalicon, $FinalTitle, $FinalMessage)
    EndSwitch
WEnd

kylomas

1 person likes this

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#9 ·  Posted

Thank you very much. I appreciate it :)

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