Jump to content

Why i can't click my button


 Share

Recommended Posts

Hi guys, i made a password generator, but when i try to click the button, nothing happens

#include <file.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

;Началото
GUISetBkColor(0x808080)
$Form1 = GUICreate("Form1", 633, 447, 193, 125)
$hButton = GUICtrlCreateButton("Generate", 64, 328, 147, 41, 0)
GUICtrlSetFont(-1, 14, 800, 0, "Rosewood Std Regular")
GUICtrlSetBkColor(-1, 0x000080)
$Label1 = GUICtrlCreateLabel("Instructions:  1st: Type in the reason you are generating the Password.", 8, 104, 336, 17)
$Label2 = GUICtrlCreateLabel("2nd: Type in how many charaters you want the Password to be.", 8, 120, 304, 17)
$Label3 = GUICtrlCreateLabel("And 3rd: Click the Generate Button", 8, 136, 169, 17)
$Reason = GUICtrlCreateInput("Reason for Generating", 24, 208, 249, 21)
$char = GUICtrlCreateInput("8", 24, 272, 249, 21)
$Label4 = GUICtrlCreateLabel("Reason for Generating.", 24, 192, 114, 17)
$Label5 = GUICtrlCreateLabel("How many characters.", 24, 256, 110, 17)
$Pic1 = GUICtrlCreatePic("C:\Documents and Settings\Administrator\Desktop\background.jpg", 280, 8, 348, 436, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
$Label7 = GUICtrlCreateLabel("Password Generator", 8, 0, 382, 47)
GUICtrlSetFont(-1, 28, 800, 0, "Rosewood Std Regular")
GUISetState(@SW_SHOW)
;Край


While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            Generate()
    EndSwitch

WEnd


Func Generate()
;$n is the lenght of string.
 Local $N
  Local $COUNTER, $ALPHA, $RESULT , $NUMBER 
   If $N < 1 Then
          MsgBox(7, "ERROR", " PLEASE INPUT NUMERS ONLY")
    EndIf
 For $COUNTER = 1 To $N
  If Random() < 0.5 Then
        $ALPHA = Chr(Random(Asc("A"), Asc("Z") + 1))
        $NUMBER = Chr(Random(Asc("1"), Asc("10") + 1))
EndIf
     $RESULT = $RESULT & $ALPHA & $NUMBER
     Next
  Return $RESULT
  InputBox("Random Password","Here you go:", Generate($char))
EndFunc ;==>RandomText
InputBox("Random Password","Here you go:", Generate($char))
_FileWriteLog(@ScriptDir & "\generatedpasswords.txt","Password - " & RandomText($char) & "   ||| Reason For Generating :=: " & ($Reason))
_FileWriteLog(@ScriptDir & "\generatedpasswords.txt","Password Generator by Wander")
_FileWriteLog(@ScriptDir & "\generatedpasswords.txt","-----------------------------------------------------------------------------------------------------------")

Help me please.

Link to comment
Share on other sites

The GUI is fine, the loop is fine, the Function is a mess...

you have Generate() as a Function, with no passing parameters,

then you call it within the Function with parameters??? Generate($char)

... Not possible when you have Func Generate()

8)

NEWHeader1.png

Link to comment
Share on other sites

Valuater is correct. The function is never defined/used properly. Beyond that it only generates a character if the first random is low. Then it generate a number AND a letter every time that happens. The result is returned before the input in the function. The last input will only show when the loop is closed... ie when the gui is closed.

Link to comment
Share on other sites

The following works so you can use it to see what @valuater is talking about. That whole function is wrong as you have it.

#include <file.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

;????????
GUISetBkColor(0x808080)
$Form1 = GUICreate("Form1", 633, 447, 193, 125)
$hButton = GUICtrlCreateButton("Generate", 64, 328, 147, 41, 0)
GUICtrlSetFont(-1, 14, 800, 0, "Rosewood Std Regular")
;GUICtrlSetBkColor(-1, 0x000080)
$Label1 = GUICtrlCreateLabel("Instructions:  1st: Type in the reason you are generating the Password.", 8, 104, 336, 17)
$Label2 = GUICtrlCreateLabel("2nd: Type in how many charaters you want the Password to be.", 8, 120, 304, 17)
$Label3 = GUICtrlCreateLabel("And 3rd: Click the Generate Button", 8, 136, 169, 17)
$Reason = GUICtrlCreateInput("Reason for Generating", 24, 208, 249, 21)
$char = GUICtrlCreateInput("8", 24, 272, 249, 21)
$Label4 = GUICtrlCreateLabel("Reason for Generating.", 24, 192, 114, 17)
$Label5 = GUICtrlCreateLabel("How many characters.", 24, 256, 110, 17)
$Pic1 = GUICtrlCreatePic("C:\Documents and Settings\Administrator\Desktop\background.jpg", 280, 8, 348, 436, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
$Label7 = GUICtrlCreateLabel("Password Generator", 8, 0, 382, 47)
GUICtrlSetFont(-1, 28, 800, 0, "Rosewood Std Regular")
GUISetState(@SW_SHOW)
;????


While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            MsgBox(0, "TEST", Generate(GUICtrlRead($char)))
    EndSwitch

WEnd


Func Generate($n)
;$n is the lenght of string.
;Local $N
  Local $COUNTER, $ALPHA, $RESULT , $NUMBER 
   If $N < 1 Then
          MsgBox(7, "ERROR", " PLEASE INPUT NUMERS ONLY")
    EndIf
For $COUNTER = 1 To $N
  If Random() < 0.5 Then
        $ALPHA = Chr(Random(Asc("A"), Asc("Z") + 1))
        $NUMBER = Chr(Random(Asc("1"), Asc("10") + 1))
EndIf
     $RESULT = $RESULT & $ALPHA & $NUMBER
     Next
  Return $RESULT
 ;; << The following line has no effect because you have already returned $Result
 ;InputBox("Random Password","Here you go:", Generate(GUICtrlRead($char)))
EndFunc

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

The following works so you can use it to see what @valuater is talking about. That whole function is wrong as you have it.

#include <file.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

;????????
GUISetBkColor(0x808080)
$Form1 = GUICreate("Form1", 633, 447, 193, 125)
$hButton = GUICtrlCreateButton("Generate", 64, 328, 147, 41, 0)
GUICtrlSetFont(-1, 14, 800, 0, "Rosewood Std Regular")
;GUICtrlSetBkColor(-1, 0x000080)
$Label1 = GUICtrlCreateLabel("Instructions:  1st: Type in the reason you are generating the Password.", 8, 104, 336, 17)
$Label2 = GUICtrlCreateLabel("2nd: Type in how many charaters you want the Password to be.", 8, 120, 304, 17)
$Label3 = GUICtrlCreateLabel("And 3rd: Click the Generate Button", 8, 136, 169, 17)
$Reason = GUICtrlCreateInput("Reason for Generating", 24, 208, 249, 21)
$char = GUICtrlCreateInput("8", 24, 272, 249, 21)
$Label4 = GUICtrlCreateLabel("Reason for Generating.", 24, 192, 114, 17)
$Label5 = GUICtrlCreateLabel("How many characters.", 24, 256, 110, 17)
$Pic1 = GUICtrlCreatePic("C:\Documents and Settings\Administrator\Desktop\background.jpg", 280, 8, 348, 436, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
$Label7 = GUICtrlCreateLabel("Password Generator", 8, 0, 382, 47)
GUICtrlSetFont(-1, 28, 800, 0, "Rosewood Std Regular")
GUISetState(@SW_SHOW)
;????


While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            MsgBox(0, "TEST", Generate(GUICtrlRead($char)))
    EndSwitch

WEnd


Func Generate($n)
;$n is the lenght of string.
;Local $N
  Local $COUNTER, $ALPHA, $RESULT , $NUMBER 
   If $N < 1 Then
          MsgBox(7, "ERROR", " PLEASE INPUT NUMERS ONLY")
    EndIf
For $COUNTER = 1 To $N
  If Random() < 0.5 Then
        $ALPHA = Chr(Random(Asc("A"), Asc("Z") + 1))
        $NUMBER = Chr(Random(Asc("1"), Asc("10") + 1))
EndIf
     $RESULT = $RESULT & $ALPHA & $NUMBER
     Next
  Return $RESULT
;; << The following line has no effect because you have already returned $Result
;InputBox("Random Password","Here you go:", Generate(GUICtrlRead($char)))
EndFunc
ok i fixed it but when i generate a password i doesn't makes a log file

#include <file.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

;????????
GUISetBkColor(0x808080)
$Form1 = GUICreate("Form1", 633, 447, 193, 125)
$hButton = GUICtrlCreateButton("Generate", 64, 328, 147, 41, 0)
GUICtrlSetFont(-1, 14, 800, 0, "Rosewood Std Regular")
GUICtrlSetBkColor(-1, 0x000080)
$Label1 = GUICtrlCreateLabel("Instructions:  1st: Type in the reason you are generating the Password.", 8, 104, 336, 17)
$Label2 = GUICtrlCreateLabel("2nd: Type in how many charaters you want the Password to be.", 8, 120, 304, 17)
$Label3 = GUICtrlCreateLabel("And 3rd: Click the Generate Button", 8, 136, 169, 17)
$Reason = GUICtrlCreateInput("Reason for Generating", 24, 208, 249, 21)
$char = GUICtrlCreateInput("8", 24, 272, 249, 21)
$Label4 = GUICtrlCreateLabel("Reason for Generating.", 24, 192, 114, 17)
$Label5 = GUICtrlCreateLabel("How many characters.", 24, 256, 110, 17)
$Pic1 = GUICtrlCreatePic("C:\Documents and Settings\Administrator\Desktop\background.jpg", 280, 8, 348, 436, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
$Label7 = GUICtrlCreateLabel("Password Generator", 8, 0, 382, 47)
GUICtrlSetFont(-1, 28, 800, 0, "Rosewood Std Regular")
GUISetState(@SW_SHOW)
;????


While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            MsgBox(0, "TEST", Generate(GUICtrlRead($char)))
    EndSwitch

WEnd


Func Generate($n)
;$n is the lenght of string.
;Local $N
  Local $COUNTER, $ALPHA, $RESULT , $NUMBER 
   If $N < 1 Then
          MsgBox(7, "ERROR", " PLEASE INPUT NUMERS ONLY")
    EndIf
For $COUNTER = 1 To $N
  If Random() < 0.5 Then
        $ALPHA = Chr(Random(Asc("A"), Asc("Z") + 1))
        $NUMBER = Chr(Random(Asc("1"), Asc("10") + 10))
   Else
            $ALPHA = Chr(Random(Asc("a"), Asc("z") + 1))
            $NUMBER = Chr(Random(Asc("1"), Asc("10") + 10))
EndIf
     $RESULT = $RESULT & $ALPHA & $NUMBER
     Next
  Return $RESULT
_FileWriteLog(@ScriptDir & "\generatedpasswords.txt","Password - " & Generate($char) & "   ||| Reason For Generating :=: " & ($Reason))
_FileWriteLog(@ScriptDir & "\generatedpasswords.txt","Password Generator by Wander")
_FileWriteLog(@ScriptDir & "\generatedpasswords.txt","-----------------------------------------------------------------------------------------------------------")
;; << The following line has no effect because you have already returned $Result
;InputBox("Random Password","Here you go:", Generate(GUICtrlRead($char)))
EndFunc

Help with the log pls

Link to comment
Share on other sites

When your running your GUI your within the loop. When you close the GUI you are immediately exiting the loop. The code for the log is down at the bottom outside of the loop and outside of a function.

Place the code for writing the log inside the generate function (before it returns) then it will log when it generates.

Link to comment
Share on other sites

What part of Return don't you understand? Once you Return from a function nothing past that point will be processed. Besides that log code is all wrong anyway. You can't just use a control to set the text. You have to READ the control. Secondly by calling

_FileWriteLog(@ScriptDir & "\generatedpasswords.txt","Password - " & Generate($char) & " ||| Reason For Generating :=: " & ($Reason))

you will generate another password. Unless I'm mistaken, thats NOT what you want to do. You just want to write the already generated password to the file which is $result.

_FileWriteLog(@ScriptDir & "\generatedpasswords.txt","Password - " & $Result & "   ||| Reason For Generating :=: " & (GUICtrlRead($Reason)))
_FileWriteLog(@ScriptDir & "\generatedpasswords.txt","Password Generator by Wander")
_FileWriteLog(@ScriptDir & "\generatedpasswords.txt","-----------------------------------------------------------------------------------------------------------")
Return $RESULT

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

I'm thinking someone just grabbed some code and put in all on one page... :)

8)

And it's supposed to work without even looking to see what the various functions will do. I have a simple term for this kind of thing but I'm being nice today.

People really should learn to read the help file, it would make this kind of an issue pretty much non-existant.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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