Luigi Posted May 1, 2011 Share Posted May 1, 2011 (edited) Greetings! I will write a simple code to phone book with SQLite, exist only the window and a pop-up box to input a Name and Telephone. In this code have a little code to validate the Name... If you type the Name with: Name < 2 characters = red icon Name >= 2 or Name <=50 characters = green icon Name > 50 characters = red icon This is a problem... When I starting the program and open the button "Adicionar contato / Add contact" in the name start with green icon... should be starting with red icon. If you type 3 characters and deleta all... the icon change to red icon. Type 1 character, the icon is red. Tyep 2 characters the icon is changed to green! From this point, the algoritm is working fine! But does not work when you open the window "Adicionar contato / Add contact". I thinking is a problem in the code to change color icons... Then I rewrite all te code in a single window and touché! Everything working fine! The second code open name box with a red icon... and you type two or more characters the color's icon changed to green! I can't find the error in the code with a pop-up that change colors... Someone can help me? This is a code with a pop-up window (color icons does not work) expandcollapse popup#Include <Configuracoes.au3> #include <GUIConstantsEx.au3> #include <GUIEdit.au3> #include <SQLite.au3> #include <SQLite.dll.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt('MustDeclareVars', 0) Global $Titulo = "Agenda telefônica" Global $VersaoDoPrograma = "0.01" Global $JanelaLargura = 700 Global $JanelaAltura = 400 Global $BotaoLargura = 70 Global $BotaoAltura = 25 Global $Menu, $MenuItem, $MenuItemRecentes, $Separador ;Global $BaseIcone = "C:\Windows\SysWOW64\ActionCenterCPL.dll" ;for Windows 7 Global $BaseIcone = "C:\Windows\SysWOW64\shell32.dll" ;for Windows XP Local $IniciarBase, $Base, $Indice $IniciarBase = _SQLite_Startup () IF not FileExists ("telefones.db") Then $Base = _SQLite_Open("telefones.db") _SQLite_Exec (-1, "CREATE TABLE telefones (nome, telefone, email);") ;_SQLite_Exec (-1, "INSERT INTO access (control,value) VALUES ('1','5');") _SQLite_Close() _SQLite_Shutdown() EndIf If @error Then ;ConsoleWrite("ERRO DE BANCO DE DADOS" & @CRLF & "SQLite.dll não pode ser encontrado") MsgBox(2,"Erro no banco de dados","SQLite.dll não pode ser encontrado",30) Exit - 1 EndIf _SQLite_Close() _SQLite_Shutdown () _Main() Func _Main() _SQLite_Startup () _SQLite_Open("base.db") Local $Sair, $MenuAjuda, $MenuSobre, $BotaoOK, $BotaoSair, $Janela, $Versao Local $JanelaCadastro, $BotaoFecharCadastro, $Cadastro, $BotaoAdicionarCadastro Local $Mensagem, $file, $Ferramentas, $Configuracoes, $BotaoAdicionar, $eee Local $EntradaNome = "", $Telefone Local $Luzinha = False, $LuzinhaON = True, $Efeitos Dim $Tab[26] $Janela = GUICreate($Titulo, $JanelaLargura, $JanelaAltura,-1,-1) $Menu = GUICtrlCreateMenu("Ar&quivo") $Ferramentas = GUICtrlCreateMenu("Ferramentas") ;$MenuItem = GUICtrlCreateMenuItem("&Abrir...", $Menu) ;$MenuItemRecentes = GUICtrlCreateMenu("Arquivos recentes", $Menu) ;$Separador = GUICtrlCreateMenuItem("", $Menu) $Sair = GUICtrlCreateMenuItem("Sai&r", $Menu) $Configuracoes = GUICtrlCreateMenuItem("Configurações", $Ferramentas) ;$MenuAjuda = GUICtrlCreateMenu("Sobr&e") ;$MenuSobre = GUICtrlCreateMenuItem("Autor", $MenuAjuda) ;$versao = GUICtrlCreateMenuItem("Versão", $MenuAjuda) ;$BotaoOK = GUICtrlCreateButton("OK", $JanelaLargura - 70 * 2, $JanelaAltura-20*2, 70, 20) $BotaoSair = GUICtrlCreateButton("Sair", $JanelaLargura - 70, $JanelaAltura-20*2, 70, 20) $BotaoAdicionar = GUICtrlCreateButton("Adicionar contato", $JanelaLargura - 70 * 3, $JanelaAltura-20*2, 140, 20) $Indice = GUICtrlCreateTab(19, 10, $JanelaLargura*0.95, $JanelaAltura*0.86,0x0000 + 0x0200) ; 0x0100 For $a = 0 to 25 $Tab[$a] = GUICtrlCreateTabItem(Chr($a+65)) Next GUISetState() ; JanelaCadastro $JanelaCadastro = GUICreate("Adicionar contato...", $JanelaLargura/2, $JanelaAltura/2,-1,-1) GUICtrlCreateLabel("Nome:", 56, 40) $EntradaNome = GUICtrlCreateInput('',90,37,$JanelaLargura/3 - $JanelaLargura/15,20) GUICtrlCreateIcon($BaseIcone, 4, 280 , 39 ,16,16) GUICtrlCreateLabel("Telefone:", 42, 69) $Telefone = GUICtrlCreateInput("",90,67,$JanelaLargura/3 - $JanelaLargura/15,20) GUICtrlCreateIcon($BaseIcone, 4, 280 , 69 ,16,16) GUICtrlSetState($Telefone,$GUI_DISABLE) $BotaoFecharCadastro = GUICtrlCreateButton("Fechar",$JanelaLargura/2 - $BotaoLargura*2,$JanelaAltura/2 - $BotaoAltura,$BotaoLargura,25) $BotaoAdicionarCadastro = GUICtrlCreateButton("Adicionar",$JanelaLargura/2 - $BotaoLargura,$JanelaAltura/2 - $BotaoAltura,$BotaoLargura,25) GUISetState(@SW_HIDE, $JanelaCadastro) While 1 $Mensagem = GUIGetMsg() Select Case ($Mensagem = $GUI_EVENT_CLOSE AND $Cadastro = FALSE) OR ($Mensagem = $Sair AND $Cadastro = FALSE) OR ($Mensagem = $BotaoSair AND $Cadastro = FALSE) _SQLite_Close() _SQLite_Shutdown() ExitLoop Case ($Mensagem = $GUI_EVENT_CLOSE AND $Cadastro = TRUE) OR ($Mensagem = $Sair AND $Cadastro = TRUE) OR ($Mensagem = $BotaoSair AND $Cadastro = TRUE) $Cadastro = FALSE GUISetState(@SW_HIDE, $JanelaCadastro) ;Case $Mensagem = $BotaoAdicionar ; $eee = GUICreate("Adicionar",200,200,-1,-1,BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD),$Janela) ; GUICtrlSetState($eee,$Janela) ; GUISetState() ; GUISwitch($Janela) ; If @error <> 1 Then GUICtrlCreateMenuItem($file, $MenuItemRecentes) ;Case $Mensagem = $MenuItem ; $file = FileOpenDialog("Choose file...", @TempDir, "All (*.*)") ; If @error <> 1 Then GUICtrlCreateMenuItem($file, $MenuItemRecentes) Case $Mensagem = $Sair _SQLite_Close() _SQLite_Shutdown() ExitLoop Case $Mensagem = $BotaoAdicionar $Cadastro = TRUE GUISetState(@SW_SHOW, $JanelaCadastro) GUISetState() Case $Mensagem = $BotaoFecharCadastro $Cadastro = FALSE GUISetState(@SW_HIDE, $JanelaCadastro) Case $Mensagem = $BotaoAdicionarCadastro ;Case $Mensagem = $BotaoOK ; MsgBox(0, "Click", "You clicked OK!") ;Case $Mensagem = $MenuSobre ; MsgBox(0, "Sobre", $Titulo & @CRLF &"Criado por:" & @CRLF & "Detefon" & @CRLF & "m(o.O)m") ;Case $Mensagem = $versao ; MsgBox(0, "Versão", $Titulo & @CRLF & $VersaoDoPrograma) ;Case StringLen($EntradaNome) >= 2 ; GUICtrlSetState($Telefone,$GUI_ENABLE) EndSelect ConsoleWrite("Luzinha: " & $Luzinha & @TAB & "LuzinhaON: " & $LuzinhaON & @CRLF) $NomeAtual = StringLen(GUICtrlRead($EntradaNome)) Switch $NomeAtual Case 2 to 50 $Luzinha = True Case Else $Luzinha = False EndSwitch If $Luzinha = True AND $LuzinhaON = False Then GUICtrlCreateIcon($BaseIcone, 28, 280 , 39 ,16,16, "",0x00000020) ;GUICtrlCreateIcon($BaseIcone, 4, 280 , 39 ,16,16, "",0x00000020) $LuzinhaON = True EndIf If $Luzinha = False AND $LuzinhaON = True Then GUICtrlCreateIcon($BaseIcone, 290, 280 , 39 ,16,16, "",0x00000020) ;GUICtrlCreateIcon($BaseIcone, 2, 280 , 39 ,16,16, "",0x00000020) $LuzinhaON = False EndIf WEnd GUIDelete() Exit EndFunc ;==>_Main This is a single window with color icons working fine expandcollapse popup#include <GUIConstantsEx.au3> #include <GUIEdit.au3> #include <SQLite.au3> #include <SQLite.dll.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt('MustDeclareVars', 0) Global $Titulo = "Agenda telefônica" Global $VersaoDoPrograma = "0.01" Global $JanelaLargura = 700 Global $JanelaAltura = 400 Global $BotaoLargura = 70 Global $BotaoAltura = 25 Global $Menu, $MenuItem, $MenuItemRecentes, $Separador ;Global $BaseIcone = "C:\Windows\SysWOW64\ActionCenterCPL.dll" ;for Windows 7 Global $BaseIcone = "C:\Windows\SysWOW64\shell32.dll" ;for Windows XP Local $IniciarBase, $Base, $Indice _Main() Func _Main() Local $Sair, $MenuAjuda, $MenuSobre, $BotaoOK, $BotaoSair, $Janela, $Versao Local $JanelaCadastro, $BotaoFecharCadastro, $Cadastro, $BotaoAdicionarCadastro Local $Mensagem, $file, $Ferramentas, $Configuracoes, $BotaoAdicionar, $eee Local $EntradaNome = "", $Telefone, $Nom, $NomeAtual Local $Luzinha, $LuzinhaON $Janela = GUICreate($Titulo, $JanelaLargura, $JanelaAltura,-1,-1) $Menu = GUICtrlCreateMenu("Ar&quivo") $Sair = GUICtrlCreateMenuItem("Sai&r", $Menu) $BotaoSair = GUICtrlCreateButton("Sair", $JanelaLargura - 70, $JanelaAltura-20*4, 70, 20) GUISetState() $Nom = GUICtrlCreateLabel("Nome:", 56, 40) $EntradaNome = GUICtrlCreateInput('',90,37,$JanelaLargura/3 - $JanelaLargura/15,20) ;GUICtrlCreateIcon($BaseIcone, 4, 280 , 39 ,16,16) GUICtrlCreateIcon($BaseIcone, 28, 280 , 39 ,16,16, "",0x00000020) While 1 $NomeAtual = StringLen(GUICtrlRead($EntradaNome)) Switch $NomeAtual Case 2 to 50 $Luzinha = True Case Else $Luzinha = False EndSwitch If $Luzinha = True AND $LuzinhaON = True Then ;GUICtrlCreateIcon($BaseIcone, 4, 280 , 39 ,16,16, "",0x00000020) GUICtrlCreateIcon($BaseIcone, 28, 280 , 39 ,16,16, "",0x00000020) $LuzinhaON = False ElseIf $Luzinha = False AND $LuzinhaON = False Then ;GUICtrlCreateIcon($BaseIcone, 2, 280 , 39 ,16,16, "",0x00000020) GUICtrlCreateIcon($BaseIcone, 290, 280 , 39 ,16,16, "",0x00000020) $LuzinhaON = True EndIf $Mensagem = GUIGetMsg() Select Case ($Mensagem = $GUI_EVENT_CLOSE AND $Cadastro = FALSE) OR ($Mensagem = $Sair AND $Cadastro = FALSE) OR ($Mensagem = $BotaoSair AND $Cadastro = FALSE) ExitLoop Case ($Mensagem = $GUI_EVENT_CLOSE AND $Cadastro = TRUE) OR ($Mensagem = $Sair AND $Cadastro = TRUE) OR ($Mensagem = $BotaoSair AND $Cadastro = TRUE) $Cadastro = FALSE ; GUISetState(@SW_HIDE, $JanelaCadastro) Case $Mensagem = $Sair ExitLoop ;Case $Mensagem = $BotaoAdicionar ; $Cadastro = TRUE ; GUISetState(@SW_SHOW, $JanelaCadastro) ;Case $Mensagem = $BotaoFecharCadastro ; $Cadastro = FALSE ; GUISetState(@SW_HIDE, $JanelaCadastro) ;Case $Mensagem = $BotaoAdicionarCadastro EndSelect WEnd GUIDelete() Exit EndFunc ;==>_Main Edited May 1, 2011 by detefon Visit my repository Link to comment Share on other sites More sharing options...
JScript Posted May 4, 2011 Share Posted May 4, 2011 @DetefonI think anyone helped you because you put the names of variables in Portuguese... nobody will waste time translating...(Eu acho que ninguém te ajudou porque tu colocou o nome das variáveis em português... ninguém vai perder tempo traduzindo...)This is a code with a pop-up window (color icons now work!)expandcollapse popup;#Include <Configuracoes.au3> #include <GUIConstantsEx.au3> #include <GUIEdit.au3> #include <SQLite.au3> #include <SQLite.dll.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt('MustDeclareVars', 0) Global $Titulo = "Agenda telefônica" Global $VersaoDoPrograma = "0.01" Global $JanelaLargura = 700 Global $JanelaAltura = 400 Global $BotaoLargura = 70 Global $BotaoAltura = 25 Global $Menu, $MenuItem, $MenuItemRecentes, $Separador Global $BaseIcone = @SystemDir & "\ActionCenterCPL.dll" ;for Windows 7 ;Global $BaseIcone = @SystemDir & "\shell32.dll" ;for Windows XP Local $IniciarBase, $Base, $Indice $IniciarBase = _SQLite_Startup() If Not FileExists("telefones.db") Then $Base = _SQLite_Open("telefones.db") _SQLite_Exec(-1, "CREATE TABLE telefones (nome, telefone, email);") ;_SQLite_Exec (-1, "INSERT INTO access (control,value) VALUES ('1','5');") _SQLite_Close() _SQLite_Shutdown() EndIf If @error Then ;ConsoleWrite("ERRO DE BANCO DE DADOS" & @CRLF & "SQLite.dll não pode ser encontrado") MsgBox(2, "Erro no banco de dados", "SQLite.dll não pode ser encontrado", 30) Exit -1 EndIf _SQLite_Close() _SQLite_Shutdown() _Main() Func _Main() _SQLite_Startup() _SQLite_Open("base.db") Local $Sair, $MenuAjuda, $MenuSobre, $BotaoOK, $BotaoSair, $Janela, $Versao Local $JanelaCadastro, $BotaoFecharCadastro, $Cadastro, $BotaoAdicionarCadastro Local $Mensagem, $file, $Ferramentas, $Configuracoes, $BotaoAdicionar, $eee Local $EntradaNome = "", $Telefone Local $Luzinha = False, $LuzinhaON = True, $Efeitos Dim $Tab[26] $Janela = GUICreate($Titulo, $JanelaLargura, $JanelaAltura, -1, -1) $Menu = GUICtrlCreateMenu("Ar&quivo") $Ferramentas = GUICtrlCreateMenu("Ferramentas") ;$MenuItem = GUICtrlCreateMenuItem("&Abrir...", $Menu) ;$MenuItemRecentes = GUICtrlCreateMenu("Arquivos recentes", $Menu) ;$Separador = GUICtrlCreateMenuItem("", $Menu) $Sair = GUICtrlCreateMenuItem("Sai&r", $Menu) $Configuracoes = GUICtrlCreateMenuItem("Configurações", $Ferramentas) ;$MenuAjuda = GUICtrlCreateMenu("Sobr&e") ;$MenuSobre = GUICtrlCreateMenuItem("Autor", $MenuAjuda) ;$versao = GUICtrlCreateMenuItem("Versão", $MenuAjuda) ;$BotaoOK = GUICtrlCreateButton("OK", $JanelaLargura - 70 * 2, $JanelaAltura-20*2, 70, 20) $BotaoSair = GUICtrlCreateButton("Sair", $JanelaLargura - 70, $JanelaAltura - 20 * 2, 70, 20) $BotaoAdicionar = GUICtrlCreateButton("Adicionar contato", $JanelaLargura - 70 * 3, $JanelaAltura - 20 * 2, 140, 20) $Indice = GUICtrlCreateTab(19, 10, $JanelaLargura * 0.95, $JanelaAltura * 0.86, 0x0000 + 0x0200) ; 0x0100 For $a = 0 To 25 $Tab[$a] = GUICtrlCreateTabItem(Chr($a + 65)) Next GUISetState() ; JanelaCadastro $JanelaCadastro = GUICreate("Adicionar contato...", $JanelaLargura / 2, $JanelaAltura / 2, -1, -1) GUICtrlCreateLabel("Nome:", 56, 40) $EntradaNome = GUICtrlCreateInput('', 90, 37, $JanelaLargura / 3 - $JanelaLargura / 15, 20) $iIconID = GUICtrlCreateIcon($BaseIcone, 4, 280, 39, 16, 16) GUICtrlCreateLabel("Telefone:", 42, 69) $Telefone = GUICtrlCreateInput("", 90, 67, $JanelaLargura / 3 - $JanelaLargura / 15, 20) GUICtrlCreateIcon($BaseIcone, 4, 280, 69, 16, 16) GUICtrlSetState($Telefone, $GUI_DISABLE) $BotaoFecharCadastro = GUICtrlCreateButton("Fechar", $JanelaLargura / 2 - $BotaoLargura * 2, $JanelaAltura / 2 - $BotaoAltura, $BotaoLargura, 25) $BotaoAdicionarCadastro = GUICtrlCreateButton("Adicionar", $JanelaLargura / 2 - $BotaoLargura, $JanelaAltura / 2 - $BotaoAltura, $BotaoLargura, 25) GUISetState(@SW_HIDE, $JanelaCadastro) While 1 $Mensagem = GUIGetMsg() Select Case ($Mensagem = $GUI_EVENT_CLOSE And $Cadastro = False) OR ($Mensagem = $Sair And $Cadastro = False) OR ($Mensagem = $BotaoSair And $Cadastro = False) _SQLite_Close() _SQLite_Shutdown() ExitLoop Case ($Mensagem = $GUI_EVENT_CLOSE And $Cadastro = True) OR ($Mensagem = $Sair And $Cadastro = True) OR ($Mensagem = $BotaoSair And $Cadastro = True) $Cadastro = False GUISetState(@SW_HIDE, $JanelaCadastro) ;Case $Mensagem = $BotaoAdicionar ; $eee = GUICreate("Adicionar",200,200,-1,-1,BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD),$Janela) ; GUICtrlSetState($eee,$Janela) ; GUISetState() ; GUISwitch($Janela) ; If @error <> 1 Then GUICtrlCreateMenuItem($file, $MenuItemRecentes) ;Case $Mensagem = $MenuItem ; $file = FileOpenDialog("Choose file...", @TempDir, "All (*.*)") ; If @error <> 1 Then GUICtrlCreateMenuItem($file, $MenuItemRecentes) Case $Mensagem = $Sair _SQLite_Close() _SQLite_Shutdown() ExitLoop Case $Mensagem = $BotaoAdicionar $Cadastro = True GUISetState(@SW_SHOW, $JanelaCadastro) GUISetState() Case $Mensagem = $BotaoFecharCadastro $Cadastro = False GUISetState(@SW_HIDE, $JanelaCadastro) Case $Mensagem = $BotaoAdicionarCadastro ;Case $Mensagem = $BotaoOK ; MsgBox(0, "Click", "You clicked OK!") ;Case $Mensagem = $MenuSobre ; MsgBox(0, "Sobre", $Titulo & @CRLF &"Criado por:" & @CRLF & "Detefon" & @CRLF & "m(o.O)m") ;Case $Mensagem = $versao ; MsgBox(0, "Versão", $Titulo & @CRLF & $VersaoDoPrograma) ;Case StringLen($EntradaNome) >= 2 ; GUICtrlSetState($Telefone,$GUI_ENABLE) EndSelect ;ConsoleWrite("Luzinha: " & $Luzinha & @TAB & "LuzinhaON: " & $LuzinhaON & @CRLF) $NomeAtual = StringLen(GUICtrlRead($EntradaNome)) Switch $NomeAtual Case 2 To 50 $Luzinha = True Case Else $Luzinha = False EndSwitch If $Luzinha = True And $LuzinhaON = False Then GUICtrlSetImage($iIconID, $BaseIcone, 2) $LuzinhaON = True EndIf If $Luzinha = False And $LuzinhaON = True Then GUICtrlSetImage($iIconID, $BaseIcone, 4) $LuzinhaON = False EndIf WEnd GUIDelete() Exit EndFunc ;==>_MainAfter you finish writing your program, do not forget to give a revised it, it's pretty ugly!(Depois que você terminar de escrever seu programa, não esquece de dar uma revisada nele, está bastante feio!)Good work!(Bom trabalho!) http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
Luigi Posted May 12, 2011 Author Share Posted May 12, 2011 (edited) jscrit, realy thanks for your help! I know a little of algoritms and how to program... I will study alone, learn many things alone, but this have a negative side: I learn many things, but nothing is consistent. But I will revise my scrit. === I understand now! Enough just use the GUICTRLSetImage? I hate me! (x.x) Thanks jscript! Edited May 12, 2011 by detefon Visit my repository Link to comment Share on other sites More sharing options...
JScript Posted May 13, 2011 Share Posted May 13, 2011 Glad you liked it! http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now