Jump to content

Problems with If statement..


Damein
 Share

Recommended Posts

I have a snippet of code, and it works for one selection, but not for the second.

Here is the code:

Case $SelectionMenu
            $CurrentSelection = ControlGetText("Paws & Tales", "", $SelectionMenu)
            $var = IniReadSection("C:\Users\***\Desktop\New P&T\Links&Names\Names.ini", "Links and Names")
    For $i = 1 To $var[0][0]
        MsgBox(0, "Test", $var[$i][1] & " = " & $CurrentSelection)
        If ($CurrentSelection = $Var[$i][1]) Then
            MsgBox(0, "Test", $Var[$i][0])
            Exit
        EndIf
    Next

So, in this section I have this in the ini:

[Links and Names]
http://www.oneplace.com/player/paws-and-tales/episode-12-the-honey-buzz-principlegreed-steals-our-joy-138329.html=The Honey Buzz Principle
http://www.oneplace.com/player/paws-and-tales/episode-11-a-race-against-timeputting-others-first-138328.html=A Race Against Time
http://www.oneplace.com/player/paws-and-tales/episode-10-the-lighthouseour-conscience-is-from-god-137373.html=The Lighthouse
http://www.oneplace.com/player/paws-and-tales/god-with-the-wind-127055.html=God With the Wind
http://www.oneplace.com/player/paws-and-tales/a-closer-look-127054.html=A Closer Look
http://www.oneplace.com/player/paws-and-tales/correction-course-127053.html=Correction Course
http://www.oneplace.com/player/paws-and-tales/standing-alone-127052.html=Standing Alone
http://www.oneplace.com/player/paws-and-tales/episode-5-the-princessprayer-126136.html=The Princess
http://www.oneplace.com/player/paws-and-tales/episode-4-high-noonovercoming-fear-126135.html=High Noon
http://www.oneplace.com/player/paws-and-tales/episode-3-to-have-and-give-notsharing-126134.html=To Have and Give Not
http://www.oneplace.com/player/paws-and-tales/episode-2-grace-to-hughgrace-126133.html=Grace to Hugh
http://www.oneplace.com/player/paws-and-tales/episode-48-the-island-of-nedtwo-are-better-than-one-120111.html=The Island of Ned
http://www.oneplace.com/player/paws-and-tales/episode-47-the-story-of-esther-part-3god-will-never-leave-those-who-trust-him-120110.html=The Story of Esther, Part 3
http://www.oneplace.com/player/paws-and-tales/episode-46-the-story-of-esther-part-2god-has-a-plan-for-our-lives-120109.html=The Story of Esther, Part 2
http://www.oneplace.com/player/paws-and-tales/episode-45-the-story-of-esther-part-1god-causes-all-things-to-work-together-for-good-120108.html=The Story of Esther, Part 1
http://www.oneplace.com/player/paws-and-tales/episode-44-the-plans-i-havegod-is-our-rock-in-times-of-change-120107.html=The Plans I Have
http://www.oneplace.com/player/paws-and-tales/episode-40-the-least-of-allall-things-are-possible-with-god-114389.html=The Least of All
http://www.oneplace.com/player/paws-and-tales/episode-39-miss-helga-grisselshowing-grace-to-others-114388.html=Miss Helga Grissel
http://www.oneplace.com/player/paws-and-tales/episode-38-cj-ahabenvy-114387.html=CJ & Ahab
http://www.oneplace.com/player/paws-and-tales/episode-62-shadow-valley-part-6our-future-is-in-christ-114386.html=Shadow Valley, Part 6
http://www.oneplace.com/player/paws-and-tales/shadow-valley-part-5-103706.html=Shadow Valley Part 5
http://www.oneplace.com/player/paws-and-tales/shadow-valley-part-4-103705.html=Shadow Valley Part 4
http://www.oneplace.com/player/paws-and-tales/shadow-valley-part-3-103704.html=Shadow Valley Part 3
http://www.oneplace.com/player/paws-and-tales/shadow-valley-part-2-103703.html=Shadow Valley Part 2
http://www.oneplace.com/player/paws-and-tales/shadow-valley-part-1-103702.html=Shadow Valley Part 1
http://www.oneplace.com/player/paws-and-tales/goliath-100399.html=Goliath
http://www.oneplace.com/player/paws-and-tales/the-tribe-99157.html=The Tribe
http://www.oneplace.com/player/paws-and-tales/whose-name-is-jealous-98125.html=Whose Name Is Jealous
http://www.oneplace.com/player/paws-and-tales/im-a-believer-97342.html=I'm A Believer
http://www.oneplace.com/player/paws-and-tales/cylinder-137k-95248.html=Cylinder 137K
http://www.oneplace.com/player/paws-and-tales/the-gift-95247.html=The Gift
http://www.oneplace.com/player/paws-and-tales/the-grecian-urn-94330.html=The Grecian Urn
http://www.oneplace.com/player/paws-and-tales/eye-of-the-tiger-93150.html=Eye of the Tiger
http://www.oneplace.com/player/paws-and-tales/the-dedication-92508.html=The Dedication
http://www.oneplace.com/player/paws-and-tales/the-gift-85534.html=The Gift
http://www.oneplace.com/player/paws-and-tales/the-grecian-urn-85533.html=The Grecian Urn
http://www.oneplace.com/player/paws-and-tales/if-the-tooth-be-known-85532.html=If the Tooth Be Known
http://www.oneplace.com/player/paws-and-tales/the-scarlet-stain-85531.html=The Scarlet Stain
http://www.oneplace.com/player/paws-and-tales/plans-in-the-breaking-85530.html=Plans In the Breaking
http://www.oneplace.com/player/paws-and-tales/a-pirates-life-85529.html=A Pirate's Life
http://www.oneplace.com/player/paws-and-tales/the-hullabaloo-at-hunker-hill-85528.html=The Hullabaloo At Hunker Hill
http://www.oneplace.com/player/paws-and-tales/blinded-by-the-sight-85527.html=Blinded By the Sight
http://www.oneplace.com/player/paws-and-tales/the-road-to-christmas-85526.html=The Road to Christmas
http://www.oneplace.com/player/paws-and-tales/every-good-thing-85525.html=Every Good Thing
http://www.oneplace.com/player/paws-and-tales/true-riches-85524.html=True Riches
http://www.oneplace.com/player/paws-and-tales/the-perfect-christmas-gift-85523.html=The Perfect Christmas Gift
http://www.oneplace.com/player/paws-and-tales/stacis-dilemma-67857.html=Staci's Dilemma
http://www.oneplace.com/player/paws-and-tales/tiffany-cometh-67856.html=Tiffany Cometh
http://www.oneplace.com/player/paws-and-tales/a-conscious-effort-67855.html=A Conscious Effort
http://www.oneplace.com/player/paws-and-tales/hold-the-anchovies-67854.html=Hold the Anchovies
http://www.oneplace.com/player/paws-and-tales/episode-14-the-great-go-cart-racecooperation-67853.html=The Great Go-Cart Race
http://www.oneplace.com/player/paws-and-tales/episode-13-snake-oil-67852.html=Snake Oil

And in the ComboBox I have:

The Honey Buzz Principle|
A Race Against Time|
The Lighthouse|
God With the Wind|
A Closer Look|
Correction Course|
Standing Alone|
The Princess|
High Noon|
To Have and Give Not|
Grace to Hugh|
The Island of Ned|
The Story of Esther, Part 3|
The Story of Esther, Part 2|
The Story of Esther, Part 1|
The Plans I Have|
The Least of All|
Miss Helga Grissel|
CJ & Ahab|
Shadow Valley, Part 6|
Shadow Valley Part 5|
Shadow Valley Part 4|
Shadow Valley Part 3|
Shadow Valley Part 2|
Shadow Valley Part 1|
Goliath|
The Tribe|
Whose Name Is Jealous|
I'm A Believer|
Cylinder 137K|
The Gift|
The Grecian Urn|
Eye of the Tiger|
The Dedication|
The Gift|
The Grecian Urn|
If the Tooth Be Known|
The Scarlet Stain|
Plans In the Breaking|
A Pirate's Life|
The Hullabaloo At Hunker Hill|
Blinded By the Sight|
The Road to Christmas|
Every Good Thing|
True Riches|
The Perfect Christmas Gift|
Staci's Dilemma|
Tiffany Cometh|
A Conscious Effort|
Hold the Anchovies|
The Great Go-Cart Race|
Snake Oil|

(Excluding the |'s due to making them options in the ComboBox)

So, all in all! When I choose a item in the ComboBox I want to check it against the Ini file and if it matches then give me the link.

It works for the first one: The Honeybuzz Principle, but other then that it doesn't do anything ;)

Any help would be appreciated, I will continue working on it atm though.. but I've been at it for almost an hour ^^;

MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Link to comment
Share on other sites

Nope, that returns a 0 ;)

Here's the entire code:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
HotKeySet("{`}", "ShowGUI")

Opt('MustDeclareVars', 1)
Global $Msg, $OptionsMenu, $RandomItem, $SelectionItem, $SelectionMenu, $hLabel, $CurrentSelection, $Selection, $NamesAndLinksFile, $Var, $EpisodeNames, $EpisodeNameForList, $CurrentSelection

$EpisodeNames = "C:\Users\Rob\Desktop\New P&T\Links&Names\EpisodeNames.txt"

FileDelete("C:\Users\Rob\Desktop\New P&T\Links&Names\EpisodeNames.txt")

$var = IniReadSection("C:\Users\Rob\Desktop\New P&T\Links&Names\Names.ini", "Links and Names")
    For $i = 1 To $var[0][0]
        FileWriteLine($EpisodeNames, $var[$i][1] & "|")
    Next
    
    $EpisodeNameForList = FileRead($EpisodeNames)

    GUICreate("Paws & Tales")
    $OptionsMenu = GuiCtrlCreateMenu("Options")
    $RandomItem = GuiCtrlCreateMenuItem("Random", $OptionsMenu)
    $SelectionItem = GuiCtrlCreateMenuItem("Self-Choose", $OptionsMenu)
    $SelectionMenu = GuiCtrlCreateCombo("Episode List", 10,40)
    GUICtrlSetState($SelectionMenu, $GUI_HIDE)
    GuiCtrlSetData(-1, $EpisodeNameForList)
    $hLabel = GuiCtrlCreateLabel("Please select a choice selection in the options menu",0,0)
    
    $CurrentSelection = ""

While 1
    Switch GuiGetMSG()
    Case $GUI_EVENT_CLOSE
        Exit
        Case $RandomItem
            $Selection = 1
        Case $SelectionItem
            $Selection = 2
        Case $SelectionMenu
            $CurrentSelection = GUICtrlRead($CurrentSelection)
            $var = IniReadSection("C:\Users\Rob\Desktop\New P&T\Links&Names\Names.ini", "Links and Names")
    For $i = 1 To $var[0][0]
        If $CurrentSelection = $Var[$i][1] Then
            MsgBox(0, "Test", $Var[$i][0])
        EndIf
        MsgBox(0, "Test", $var[$i][1] & "=" & $CurrentSelection)
    Next
        EndSwitch
        
        
        If $Selection = 1 Then
            GuiCtrlSetData($hLabel, "You chose Random!")
            GuiCtrlSetState($SelectionMenu, $GUI_HIDE)
            $Selection = 3
        EndIf
        If $Selection = 2 Then
            GuiCtrlSetData($hLabel, "You chose selection!")
            GuiCtrlSetState($SelectionMenu, $GUI_SHOW)
            $Selection = 3
            EndIf
        WEnd
        
        
Func ShowGUI()
    GuiSetState(@SW_SHOW)
EndFunc

MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Link to comment
Share on other sites

Hmm.. I tried that Tvern but it didn't seem to do the trick.

Using:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
HotKeySet("{`}", "ShowGUI")

Opt('MustDeclareVars', 1)
Global $Msg, $OptionsMenu, $RandomItem, $SelectionItem, $SelectionMenu, $hLabel, $CurrentSelection, $Selection, $NamesAndLinksFile, $Var, $EpisodeNames, $EpisodeNameForList, $CurrentSelection

$EpisodeNames = "C:\Users\Rob\Desktop\New P&T\Links&Names\EpisodeNames.txt"

FileDelete("C:\Users\Rob\Desktop\New P&T\Links&Names\EpisodeNames.txt")

$var = IniReadSection("C:\Users\Rob\Desktop\New P&T\Links&Names\Names.ini", "Links and Names")
    For $i = 1 To $var[0][0]
        FileWriteLine($EpisodeNames, $var[$i][1] & "|")
    Next
    
    $EpisodeNameForList = FileRead($EpisodeNames)

    GUICreate("Paws & Tales")
    $OptionsMenu = GuiCtrlCreateMenu("Options")
    $RandomItem = GuiCtrlCreateMenuItem("Random", $OptionsMenu)
    $SelectionItem = GuiCtrlCreateMenuItem("Self-Choose", $OptionsMenu)
    $SelectionMenu = GuiCtrlCreateCombo("Episode List", 10,40)
    GUICtrlSetState($SelectionMenu, $GUI_HIDE)
    GuiCtrlSetData(-1, $EpisodeNameForList)
    $hLabel = GuiCtrlCreateLabel("Please select a choice selection in the options menu",0,0)
    
    $CurrentSelection = ""

While 1
    Switch GuiGetMSG()
    Case $GUI_EVENT_CLOSE
        Exit
        Case $RandomItem
            $Selection = 1
        Case $SelectionItem
            $Selection = 2
        Case $SelectionMenu
            $CurrentSelection = GUICtrlRead($SelectionMenu)
            $CurrentSelection = StringTrimLeft($CurrentSelection, @CR & @LF)
            MsgBox(0, "Test", $CurrentSelection)
            $var = IniReadSection("C:\Users\Rob\Desktop\New P&T\Links&Names\Names.ini", "Links and Names")
    For $i = 1 To $var[0][0]
        MsgBox(0, "Test", $CurrentSelection & " " & $var[$i][1])
        If $CurrentSelection = $Var[$i][1] Then
            MsgBox(0, "Test", $Var[$i][0])
        EndIf
    Next
        EndSwitch
        
        
        If $Selection = 1 Then
            GuiCtrlSetData($hLabel, "You chose Random!")
            GuiCtrlSetState($SelectionMenu, $GUI_HIDE)
            $Selection = 3
        EndIf
        If $Selection = 2 Then
            GuiCtrlSetData($hLabel, "You chose selection!")
            GuiCtrlSetState($SelectionMenu, $GUI_SHOW)
            $Selection = 3
            EndIf
        WEnd
        
        
Func ShowGUI()
    GuiSetState(@SW_SHOW)
EndFunc

I still only get the link with The Honey Buzz Principle, any other selection does not match up.

***** EDIT *****

I fixed with doing a left trim of 2 chars, thanks! ;)

Edited by Damein

MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Link to comment
Share on other sites

Alright.. I spoke to soon...

It works, true, but now it doesn't work for The Honey Buzz Principle because it removes the characters th instead of the | for the others.

So, I can make it work by doing:

If $CurrentSelection = "The Honey Buzz Principle"
$NewSelection = $CurrentSelection
Else
$NewSelection = StringTrimLeft($CurrentSelection, 2)
EndIf

Which works, but this will only work if The Honey Buzz Principle is the first in the list... which it won't always be :/

So, once again.. here is my code, lol.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <IE.au3>

HotKeySet("{`}", "ShowGUI")

Opt('MustDeclareVars', 1)
Global $GUIWINDOW, $PanTask, $PanGUI, $CreateWindow, $NewSelection, $Msg, $OptionsMenu, $RandomItem, $SelectionItem, $SelectionMenu, $hLabel, $CurrentSelection, $Selection, $NamesAndLinksFile, $Var, $EpisodeNames, $EpisodeNameForList, $CurrentSelection

$EpisodeNames = "C:\Users\***\Desktop\New P&T\Links&Names\EpisodeNames.txt"

FileDelete("C:\Users\***\Desktop\New P&T\Links&Names\EpisodeNames.txt")

$var = IniReadSection("C:\Users\***\Desktop\New P&T\Links&Names\Names.ini", "Links and Names")
    For $i = 1 To $var[0][0]
        FileWriteLine($EpisodeNames, $var[$i][1] & "|")
    Next
    
    $EpisodeNameForList = FileRead($EpisodeNames)

    GUICreate("Paws & Tales")
    $OptionsMenu = GuiCtrlCreateMenu("Options")
    $RandomItem = GuiCtrlCreateMenuItem("Random", $OptionsMenu)
    $SelectionItem = GuiCtrlCreateMenuItem("Self-Choose", $OptionsMenu)
    $SelectionMenu = GuiCtrlCreateCombo("Episode List", 10,40)
    GUICtrlSetState($SelectionMenu, $GUI_HIDE)
    GuiCtrlSetData(-1, $EpisodeNameForList)
    $hLabel = GuiCtrlCreateLabel("Please select a choice selection in the options menu",0,0)
    
    $CurrentSelection = ""

While 1
    Switch GuiGetMSG()
    Case $GUI_EVENT_CLOSE
        Exit
        Case $RandomItem
            $Selection = 1
        Case $SelectionItem
            $Selection = 2
        Case $SelectionMenu
            $CurrentSelection = GUICtrlRead($SelectionMenu)
            $NewSelection = StringTrimLeft($CurrentSelection, 2)
            $var = IniReadSection("C:\Users\***\Desktop\New P&T\Links&Names\Names.ini", "Links and Names")
    For $i = 1 To $var[0][0]
        If $NewSelection = $Var[$i][1] Then
            GUISETSTATE(@SW_HIDE)
            $PanTask = _IECreateEmbedded()
            $GUIWINDOW = GUICreate($NewSelection, 600, 500)
            $PanGUI = GUICtrlCreateObj($PanTask,0,0,600,500)
            GUICtrlSetPos($PanGUI, 0, -140, 600, 340)
            GUISetState()
            $CreateWindow = _IENavigate ($PanTask, $Var[$i][0], 0)
        EndIf
    Next
        EndSwitch
        
        
        If $Selection = 1 Then
            GuiCtrlSetData($hLabel, "You chose Random!")
            GuiCtrlSetState($SelectionMenu, $GUI_HIDE)
            $Selection = 3
        EndIf
        If $Selection = 2 Then
            GuiCtrlSetData($hLabel, "You chose selection!")
            GuiCtrlSetState($SelectionMenu, $GUI_SHOW)
            $Selection = 3
            EndIf
        WEnd
        
        
Func ShowGUI()
    GuiSetState(@SW_SHOW)
EndFunc

Everything but the Honey Buzz Principle works, suggestions?

Thanks!

MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Link to comment
Share on other sites

Sweet, StringStrip seems to of done the trick. Thanks again Tvern ;)

MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

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...