Jump to content

Stringreplace and misunderstood concepts


Recommended Posts

Hello,

my topic might be a little misleading but I think that I did not quite understand the concept of stringreplace. Whenever I use a fix string, everything works fine. But as soon as I use a variable it's not working.

But see for yourself:

#include <GUIConstantsEx.au3>

GUICreate("nerve", 300, 300)
GUICtrlCreateLabel("Please select your option. Input might be disabled if needed!", 10, 10)
$sapphirebutton = GUICtrlCreateButton ("Activate/Sapphire", 30, 50, 100)
$trapcodebutton = GUICtrlCreateButton ("Activate/Trapcode", 180, 50, 100)
$wakeonlan = GUICtrlCreateButton ("Start/the/Farm", 105, 90, 100)
$customer = GUICtrlCreateInput ("Customer Code", 105, 160)
$project = GUICtrlCreateInput ("Project Name", 105, 190, 100)
$createdir = GUICtrlCreateButton ("Create Directory", 105, 230, 100)
GUISetState(@SW_SHOW)

While 1
  $msg = GUIGetMsg()

  Select
    Case $msg = $sapphirebutton
        Run ("\\work\administration\scripts_batchdateien\Sapphire_registrieren\plugin_sapphire_aktivieren.exe
")
;      MsgBox(0, "GUI Event", "You pressed OK!")

    Case $msg = $trapcodebutton
        Run ("\\work\administration\scripts_batchdateien\Trapcode_registrieren\Trapcode_registrieren.exe")

    Case $msg = $wakeonlan
        Run ("\\work\administration\scripts_batchdateien\FRA_wake_farm.bat")

    Case $msg = $createdir
    StringReplace ($project, " ", "-")
        $path = GuiCtrlRead($customer) & GuiCtrlRead($project)
        MsgBox (4096, "Test", $path)
       

    Case $msg = $GUI_EVENT_CLOSE
;      MsgBox(0, "GUI Event", "You clicked CLOSE! Exiting...")


        ExitLoop
  EndSelect
WEnd

cheers Felix

Link to comment
Share on other sites

  • Moderators

StringReplace (GUICtrlRead($project), " ", "-")

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

no did not work :P

#include <GUIConstantsEx.au3>

GUICreate("nerve", 300, 300)
GUICtrlCreateLabel("Please select your option. Input might be disabled if needed!", 10, 10)
$sapphirebutton = GUICtrlCreateButton ("Activate/Sapphire", 30, 50, 100)
$trapcodebutton = GUICtrlCreateButton ("Activate/Trapcode", 180, 50, 100)
$wakeonlan = GUICtrlCreateButton ("Start/the/Farm", 105, 90, 100)
$customer = GUICtrlCreateInput ("Customer Code", 105, 160)
$project = GUICtrlCreateInput ("Project Name", 105, 190, 100)
$createdir = GUICtrlCreateButton ("Create Directory", 105, 230, 100)
GUISetState(@SW_SHOW)

While 1
  $msg = GUIGetMsg()

  Select
    Case $msg = $sapphirebutton
        Run ("\\work\administration\scripts_batchdateien\Sapphire_registrieren\plugin_sapphire_aktivieren.exe")
;      MsgBox(0, "GUI Event", "You pressed OK!")

    Case $msg = $trapcodebutton
        Run ("\\work\administration\scripts_batchdateien\Trapcode_registrieren\Trapcode_registrieren.exe")

    Case $msg = $wakeonlan
        Run ("\\work\administration\scripts_batchdateien\FRA_wake_farm.bat")

    Case $msg = $createdir
    
$project = StringReplace ($project, " ", "-")
    $path = GuiCtrlRead ($customer) & "-" & GUICtrlRead ($project)
        MsgBox (4096, "Test", $path)
    Case $msg = $GUI_EVENT_CLOSE

        ExitLoop
  EndSelect
WEnd
Link to comment
Share on other sites

  • Moderators

no did not work :P

#include <GUIConstantsEx.au3>

GUICreate("nerve", 300, 300)
GUICtrlCreateLabel("Please select your option. Input might be disabled if needed!", 10, 10)
$sapphirebutton = GUICtrlCreateButton ("Activate/Sapphire", 30, 50, 100)
$trapcodebutton = GUICtrlCreateButton ("Activate/Trapcode", 180, 50, 100)
$wakeonlan = GUICtrlCreateButton ("Start/the/Farm", 105, 90, 100)
$customer = GUICtrlCreateInput ("Customer Code", 105, 160)
$project = GUICtrlCreateInput ("Project Name", 105, 190, 100)
$createdir = GUICtrlCreateButton ("Create Directory", 105, 230, 100)
GUISetState(@SW_SHOW)

While 1
  $msg = GUIGetMsg()

  Select
    Case $msg = $sapphirebutton
        Run ("\\work\administration\scripts_batchdateien\Sapphire_registrieren\plugin_sapphire_aktivieren.exe")
;      MsgBox(0, "GUI Event", "You pressed OK!")

    Case $msg = $trapcodebutton
        Run ("\\work\administration\scripts_batchdateien\Trapcode_registrieren\Trapcode_registrieren.exe")

    Case $msg = $wakeonlan
        Run ("\\work\administration\scripts_batchdateien\FRA_wake_farm.bat")

    Case $msg = $createdir
    
$project = StringReplace ($project, " ", "-")
    $path = GuiCtrlRead ($customer) & "-" & GUICtrlRead ($project)
        MsgBox (4096, "Test", $path)
    Case $msg = $GUI_EVENT_CLOSE

        ExitLoop
  EndSelect
WEnd
Didn't work? You didn't use it! (Unless you were talking about the other guys post.

Also, you're work is so garbled in the forum output, I'm going to assume you did some hack job on the script to post it there, but next time could you use Tidy in the SciTE editor before posting? Thanks...

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Such lovely words in the morning. :P

I actually meant the first reply. But I just tried yours and it didn't work either. It still outputs the name with the spaces in the project name.

Regarding the Tidy option... I can't find it. I installed the very recent version of autoit+scite.

Thank you

Felix

Link to comment
Share on other sites

  • Moderators

Such lovely words in the morning. :P

I actually meant the first reply. But I just tried yours and it didn't work either. It still outputs the name with the spaces in the project name.

Regarding the Tidy option... I can't find it. I installed the very recent version of autoit+scite.

Thank you

Felix

Full Scite Download

I don't know what other help you could receive... I showed you that you were only using the control id of the control, and not reading the actual text value of it. As we have absolutely no idea what that input holds, you can receive no more helpful information.

Edit:

I see your mistake... you are changing $project from a Control to a String, then trying to use GUICtrlRead on a string when it is meant for a control... try this:

#include <GUIConstantsEx.au3>

GUICreate("nerve", 300, 300)
GUICtrlCreateLabel("Please select your option. Input might be disabled if needed!", 10, 10)
$sapphirebutton = GUICtrlCreateButton("Activate/Sapphire", 30, 50, 100)
$trapcodebutton = GUICtrlCreateButton("Activate/Trapcode", 180, 50, 100)
$wakeonlan = GUICtrlCreateButton("Start/the/Farm", 105, 90, 100)
$customer = GUICtrlCreateInput("Customer Code", 105, 160)
$project = GUICtrlCreateInput("Project Name", 105, 190, 100)
$createdir = GUICtrlCreateButton("Create Directory", 105, 230, 100)
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()

    Select
        Case $msg = $sapphirebutton
            Run("\\work\administration\scripts_batchdateien\Sapphire_registrieren\plugin_sapphire_aktivieren.exe")
            ;      MsgBox(0, "GUI Event", "You pressed OK!")
        Case $msg = $trapcodebutton
            Run("\\work\administration\scripts_batchdateien\Trapcode_registrieren\Trapcode_registrieren.exe")

        Case $msg = $wakeonlan
            Run("\\work\administration\scripts_batchdateien\FRA_wake_farm.bat")

        Case $msg = $createdir
            $path = GUICtrlRead($customer) & "-" & StringReplace(GUICtrlRead($project), " ", "-")
            MsgBox(4096, "Test", $path)
        Case $msg = $GUI_EVENT_CLOSE

            ExitLoop
    EndSelect
WEnd
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Hello SmOke_N ,

the input right now doesn't seem to be the issue here. Whatever I try to put in the box (my name or the default entry of the field: "Project Name") the string doesn't replace anything. But whenever I use StringReplace ("something something", " ", "-") it works.

Felix

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