Sign in to follow this  
Followers 0
acidfear

Need help with alternatives

3 posts in this topic

#1 ·  Posted (edited)

I'm starting to learn Japanese. Along with my learning, I will be making little programs here and there to help me progress. So far, everything is running OK. I've made a small little program (which I will be expanding on as I go) that helps with words and their definitions.

I'm asking for some alternatives to the way I've coded the decision statements. Right now I've written every possibility manually. Are there any other ways I can code this so that I don't have to manually write it the way I did. (I'm hoping you will realize what I mean from what I have so far.

I know this isn't much, but I'd rather try to find an alternative method to this before I begin expanding on it. Thanks!'

#include <GuiConstants.au3>

GuiCreate("Learn Japanese - Beginners", 379, 150,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$Label_1 = GuiCtrlCreateLabel("", 10, 10, 100, 40,bitor($ss_center,$ss_sunken))
$Label_2 = GuiCtrlCreateLabel("", 130, 10, 100, 40,bitor($ss_center,$ss_sunken))
$Input_3 = GuiCtrlCreateInput("", 260, 30, 110, 20)
$Button_4 = GuiCtrlCreateButton("New Word", 260, 10, 60, 20)
$Button_5 = GuiCtrlCreateButton("Check", 320, 10, 50, 20)
$Label_6 = GuiCtrlCreateLabel("", 10, 80, 100, 40,bitor($ss_center,$ss_sunken))
$Label_7 = GuiCtrlCreateLabel("", 130, 80, 100, 40,bitor($ss_center,$ss_sunken))
$Input_8 = GuiCtrlCreateInput("", 260, 100, 110, 20)
$Button_9 = GuiCtrlCreateButton("New Word", 260, 80, 60, 20)
$Button_10 = GuiCtrlCreateButton("Check", 320, 80, 50, 20)

$info = GUICtrlCreateLabel("Japanese words - Konnichiwa,   Konbanwa,   Ohyaoo gozaimasu",10, 125)
$info2 = GUICtrlCreateLabel("English word - Good morning,    Good afternoon,   Good evening",10, 55)

$GoodMorning = "Ohyaoo gozaimasu"
$GoodAfternoon = "Konnichiwa"
$GoodEvening = "Konbanwa"
$HowAreYou = "O genki desu ka"

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $Button_4
        $Rand = int(Random(1,4))
        GUICtrlSetData($label_2,"")
        GUICtrlSetData($Input_3,"")
        if $Rand = "1" Then
            GUICtrlSetData($Label_1,$GoodMorning)
        ElseIf $Rand = "2" Then 
            GUICtrlSetData($Label_1, $GoodAfternoon)
        ElseIf $Rand = "3" then 
            GUICtrlSetData($Label_1, $GoodEvening)
        EndIf
    Case $msg = $Button_5
        $input = GUICtrlRead($Input_3)
        if $Rand = "1" And $input = "good morning" Then 
            GUICtrlSetData($Label_2,"Correct")
        Elseif $Rand = "2" And $input = "good afternoon" Then
            GUICtrlSetData($label_2,"Correct")
        Elseif $rand = "3" And $input = "good evening" Then
            GUICtrlSetData($label_2,"Correct")
        Else    
            GUICtrlSetData($label_2,"Wrong")
        EndIf
    Case $msg = $Button_9
        $rand = 0
        $Rand = int(Random(1,4))
        GUICtrlSetData($label_7,"")
        GUICtrlSetData($Input_8,"")
        if $Rand = "1" Then
            GUICtrlSetData($Label_6,"Good Morning")
        ElseIf $Rand = "2" Then 
            GUICtrlSetData($Label_6, "Good Afternoon")
        ElseIf $Rand = "3" then 
            GUICtrlSetData($Label_6, "Good Evening")
        EndIf
    Case $msg = $Button_10
        $input = GUICtrlRead($Input_8)
        if $Rand = "1" And $input = $GoodMorning Then 
            GUICtrlSetData($Label_7,"Correct")
        Elseif $Rand = "2" And $input = $GoodAfternoon Then
            GUICtrlSetData($label_7,"Correct")
        Elseif $rand = "3" And $input = $GoodEvening Then
            GUICtrlSetData($label_7,"Correct")
        Else    
            GUICtrlSetData($label_7,"Wrong")
        EndIf
    EndSelect
WEnd
Exit
Edited by acidfear

Share this post


Link to post
Share on other sites



I'd say this really lends itself to using the COM Scripting.Dictionary object. It works like a Perl associative array.

You'll find some topics searching the forum. Here is a web page with some background: http://www.4guysfromrolla.com/webtech/102898-1.shtml

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

This looks something like qbasic read data statements. I'll search around for some info as you suggested.

Thanks for the quick reply!

Added a few things, and changed it a bit so far:

#include <GuiConstants.au3>
#include <GuiList.au3>
GuiCreate("Learn Japanese - Beginners", 379, 300,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$Label_1 = GuiCtrlCreateLabel("", 10, 10, 100, 40,bitor($ss_center,$ss_sunken))
$Label_2 = GuiCtrlCreateLabel("", 130, 10, 100, 40,bitor($ss_center,$ss_sunken))
$Input_3 = GuiCtrlCreateInput("", 260, 30, 110, 20)
$Button_4 = GuiCtrlCreateButton("Word", 260, 10, 60, 20)
$Button_5 = GuiCtrlCreateButton("Check", 320, 10, 50, 20)
$Label_6 = GuiCtrlCreateLabel("", 10, 80, 100, 40,bitor($ss_center,$ss_sunken))
$Label_7 = GuiCtrlCreateLabel("", 130, 80, 100, 40,bitor($ss_center,$ss_sunken))
$Input_8 = GuiCtrlCreateInput("", 260, 100, 110, 20)
$Button_9 = GuiCtrlCreateButton("Word", 260, 80, 60, 20)
$Button_10 = GuiCtrlCreateButton("Check", 320, 80, 50, 20)

$List1 = GUICtrlCreateList("",10,125,250,160,bitor($LBS_NOSEL,$LBS_NOSEL))
$view = GUICtrlCreateListView(" Japanese Words        |  English Words        ",10,125,250)
GUICtrlCreateListViewItem("Konnichiwa | Good Afternoon",$view)
GUICtrlCreateListViewItem("Ohyaoo gozaimasu | Good Morning",$view)
GUICtrlCreateListViewItem("Konbanwa | Good Evening",$view)
GUICtrlCreateListViewItem("Ja mata | Goodbye",$view)
GUICtrlCreateListViewItem("O-yasumi nasai | See you later",$view)
GUICtrlCreateListViewItem("Shitsuree shimasu | Good night",$view)
GUICtrlCreateListViewItem("Arigatoo | Thanks",$view)
GUICtrlCreateListViewItem("Doomo | Thank you",$view)


$GoodMorning = "Ohyaoo gozaimasu"
$GoodAfternoon = "Konnichiwa"
$GoodEvening = "Konbanwa"
$Goodbye = "Shitsuree shimasu"
$SeeYoulater = "Ja mata"
$Goodnight = "O-yasumi nasai"
$ThankYou = "Arigatoo"
$Thanks = "Doomo"




GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $Button_4
        $Rand = int(Random(1,9))
        GUICtrlSetData($label_2,"")
        GUICtrlSetData($Input_3,"")
        if $Rand = "1" Then
            GUICtrlSetData($Label_1,$GoodMorning)
        ElseIf $Rand = "2" Then 
            GUICtrlSetData($Label_1, $GoodAfternoon)
        ElseIf $Rand = "3" then 
            GUICtrlSetData($Label_1, $GoodEvening)
        ElseIf $rand = "4" Then
            GUICtrlSetData($Label_1,$Goodbye)
        ElseIf $rand = "5" Then
            guictrlsetdata($Label_1,$SeeYoulater)
        ElseIf $rand = "6" then 
            GUICtrlSetData($Label_1,$Goodnight)
        ElseIf $rand = "7" then 
            GUICtrlSetData($Label_1,$ThankYou)
        ElseIf $rand = "8" then 
            GUICtrlSetData($Label_1,$Thanks)
        EndIf
    Case $msg = $Button_5
        $input = GUICtrlRead($Input_3)
        if $Rand = "1" And $input = "good morning" Then 
            GUICtrlSetData($Label_2,"Correct")
        Elseif $Rand = "2" And $input = "good afternoon" Then
            GUICtrlSetData($label_2,"Correct")
        Elseif $rand = "3" And $input = "good evening" Then
            GUICtrlSetData($label_2,"Correct")
        Elseif $rand = "4" And $input = "goodbye" Then
            GUICtrlSetData($label_2,"Correct")
        Elseif $rand = "5" And $input = "see you later" Then
            GUICtrlSetData($label_2,"Correct")
        Elseif $rand = "6" And $input = "good night" Then
            GUICtrlSetData($label_2,"Correct")
        Elseif $rand = "7" And $input = "thank you" Then
            GUICtrlSetData($label_2,"Correct")
        Elseif $rand = "8" And $input = "thanks" Then
            GUICtrlSetData($label_2,"Correct")
        Else    
            GUICtrlSetData($label_2,"Wrong")
        EndIf
        
    Case $msg = $Button_9
        $Rand = int(Random(1,9))
        GUICtrlSetData($label_7,"")
        GUICtrlSetData($Input_8,"")
        if $Rand = "1" Then
            GUICtrlSetData($Label_6,"Good Morning")
        ElseIf $Rand = "2" Then 
            GUICtrlSetData($Label_6, "Good Afternoon")
        ElseIf $Rand = "3" then 
            GUICtrlSetData($Label_6, "Good Evening")
        ElseIf $Rand = "4" Then 
            GUICtrlSetData($Label_6, "Goodbye")
        ElseIf $Rand = "5" then 
            GUICtrlSetData($Label_6, "See You Later")
        ElseIf $Rand = "6" Then 
            GUICtrlSetData($Label_6, "Goodnight")
        ElseIf $Rand = "7" then 
            GUICtrlSetData($Label_6, "Thank You")
        ElseIf $Rand = "8" then 
            GUICtrlSetData($Label_6, "Thanks")
        EndIf
    Case $msg = $Button_10
        $input = GUICtrlRead($Input_8)
        if $Rand = "1" And $input = $GoodMorning Then 
            GUICtrlSetData($Label_7,"Correct")
        Elseif $Rand = "2" And $input = $GoodAfternoon Then
            GUICtrlSetData($label_7,"Correct")
        Elseif $rand = "3" And $input = $GoodEvening Then
            GUICtrlSetData($label_7,"Correct")
        Elseif $rand = "4" And $input = $Goodbye Then
            GUICtrlSetData($label_7,"Correct")
        Elseif $rand = "5" And $input = $SeeYoulater Then
            GUICtrlSetData($label_7,"Correct")
        Elseif $rand = "6" And $input = $Goodnight Then
            GUICtrlSetData($label_7,"Correct")
        Elseif $rand = "7" And $input = $ThankYou Then
            GUICtrlSetData($label_7,"Correct")
        Elseif $rand = "8" And $input = $Thanks Then
            GUICtrlSetData($label_7,"Correct")
        Else    
            GUICtrlSetData($label_7,"Wrong")
        EndIf
    EndSelect
WEnd
Exit
Edited by acidfear

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