Jump to content

Comparing a value from a control to a variable (tried a MILLION things.)


Recommended Posts

I'll admit when i'm beat :-) I've trying to do something like this:

$var = GUICtrlRead($CtrlID)
$var2 = 40

if $var > $var2 then
   MsgBox(0,"","")
endif

seems ok right? well this is how i'm setting it up:

$name = ReadFromCTRL($DoctorName)
       $limit = "Dr. Julian Ivo Robotnick, M.G."
       MsgBox(0,"Length","Lenth: " & $limit)
       
       if  $name == $limit then
         GUICtrlSetLimit($DoctorName,$limit)
         ;MsgBox(0,"Name too long","Name too long");
         addDatatoCTRL($DoctorName,"")
         Send("{ENTER}")
          ;if GUICtrlGetState($address) = $GUI_DISABLE then
            GUICtrlSetState($address,$GUI_ENABLE)
         ;endif
       else
         MsgBox(0,"","")
        

       endif

if you create two input controls, $DoctorName and $address and run this section in the $msng = $DoctorName you'll see that it just doesn't work, also i want to be able to save the value of the input controls so that i could write that info to a file/list. appreciate it :-D

Link to comment
Share on other sites

Shouldn't $limit be a length?

Beware that == is strict equality (case sensitive).

Aren't you making your GUI overcomplicated (just asking)?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Shouldn't $limit be a length?

Beware that == is strict equality (case sensitive).

Aren't you making your GUI overcomplicated (just asking)?

well, i guess but i tried this $limit = StringLen("string")

then checked if $name is > $limit, then run the code. Here it is:

$name = ReadFromCTRL($DoctorName)
       $limit = StringLen("Dr. Julian Ivo Robotnick, M.G.")
     

       if $name < $limit then
         GUICtrlSetLimit($DoctorName,$limit)
         Send("{ENTER}")
          if GUICtrlGetState($address) = $GUI_DISABLE then
            GUICtrlSetState($address,$GUI_ENABLE)
          endif
         
         
       else
          MsgBox(0,"","Limit: " & $limit)

       endif

this is what i tried before, at first it worked, sorta, now? the address input doesn't enable

Link to comment
Share on other sites

SetLimit should be call just after creating the control. If you let the user type in a 100-character string and then tell the control that it should accept more than 25, then what should it do?

Also, you don't appear to actually read your control. You should study the examples and the explanations given in the help file about the basic GUI functions. You're probably over-complicating your GUI, I guess, as well as making it work weird by not using the right functions at the right place, IMHO. Just like the Send("{Enter}") which I believe isn't what you need.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

SetLimit should be call just after creating the control. If you let the user type in a 100-character string and then tell the control that it should accept more than 25, then what should it do?

Also, you don't appear to actually read your control. You should study the examples and the explanations given in the help file about the basic GUI functions. You're probably over-complicating your GUI, I guess, as well as making it work weird by not using the right functions at the right place, IMHO. Just like the Send("{Enter}") which I believe isn't what you need.

Posted Image

As you can see, it does return the value read from the control, so i don't know, any thoughts?

Link to comment
Share on other sites

PLease post your code. Posting a large screen capture won't help but simply make backing up the forum more expensive.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

PLease post your code. Posting a large screen capture won't help but simply make backing up the forum more expensive.

Sorry, anyways, here it is:

$name = ReadFromCTRL($DoctorName)
       $start = StringLen($name)
       $limit = StringLen("Dr. Julian Ivo Robotnick, M.G.")
     
       MsgBox(0,"name", "Value = " & $name)

       ;if $name > "" then
          $state = GUICtrlGetState($address)
          if $state = $GUI_DISABLE then
          
            GUICtrlSetState($address,$GUI_ENABLE)
          endif
         
         
       ;else
          MsgBox(0,"","Limit: " & $limit)

       ;endif

also, i tried this function in the help files to get the state of a ctrl and got this:

state: 144

here's the code if you need it.

Func Example($n)
    
    $msg = GUIGetMsg()
    

    MsgBox(0, "state", " state: " & GUICtrlGetState($n))
EndFunc   ;==>Example

i can't find the 144 constant any where, unless it's in some other file.

Link to comment
Share on other sites

Come on: post _all_ your code, or at least a _complete_ extract.

Posting the same fragment again doesn't help.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Come on: post _all_ your code, or at least a _complete_ extract.

Posting the same fragment again doesn't help.

.......sorry :-P

Ok, appointments.au3 file (main file):

#include "Includes/actual_app.au3"


While 1
$T = _Timer_Init()
$Elapsed = (_Timer_Init()-$T)/1000


 
 $nMsg = GUIGetMsg()
 #cs
  select loop for controls
#ce
 Select
  Case $nMsg =$GUI_EVENT_CLOSE
   Exit
  
  
  Case $nMsg = $DoctorName
       $name = ReadFromCTRL($DoctorName)
       $start = StringLen($name)
       $limit = StringLen("Dr. Julian Ivo Robotnick, M.G.")
     
       MsgBox(0,"name", "Value = " & $name)

       ;if $name > "" then
          $state = GUICtrlGetState($address)
          if $state = $GUI_DISABLE then
          
            GUICtrlSetState($address,$GUI_ENABLE)
          endif
         
         
       ;else
          MsgBox(0,"","Limit: " & $limit)

       ;endif

  Case $nMsg = $address
       $addre = ReadFromCTRL($address)
       $limit = 40
    
  
       
       if $addre >= $len then
         GUICtrlSetLimit($address,$limit)
         addDatatoCTRL($address,"")

            ;GUICtrlSetState($Date,$GUI_ENABLE)
         
       endif
  Case $nMsg = $Calander
     GUICtrlSetState($Month_Date, $GUI_SHOW)
     GUICtrlSetState($Create,$GUI_ENABLE)
  Case $nMsg = $Create
      Example($address)
       
 Endselect
 
 ;Select loop for menu items.
 select
     case $nMsg = $New
        MsgBox(0,"Opening.....","please wait")
  endselect
WEnd





Func Example($n)
    
    $msg = GUIGetMsg()
    
    $state = GUICtrlGetState($n)
    
    MsgBox(0, "state", " state: " & $state )
EndFunc   ;==>Example

CTRLS.au3 file:

#include <ButtonConstants.au3>
#include <DateTimeConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Timers.au3>
MsgBox(0,"Welcome to Appointment v1.0","have fun");
#Region ### START Koda GUI section ### Form=C:\Users\RO\Documents\AutoITscripts\Appointments\appointments.kxf
$appointment = GUICreate("Appoitnment reminder v1.0", 841, 301, 190, 120)
$File = GUICtrlCreateMenu("File")
$New = GUICtrlCreateMenuItem("New...CTRL+N"&@TAB&"Ctrl+N", $File)
$Open = GUICtrlCreateMenuItem("Open CTRL+O"&@TAB&"Ctrl+O", $File)
$Save = GUICtrlCreateMenuItem("Save CTRL+S"&@TAB&"Ctrl+S", $File)
$Exit = GUICtrlCreateMenuItem("Exit", $File)
$appointmentsCTRL = GUICtrlCreateGroup("Appointments Edit", 16, 40, 553, 241)
$DoctorName = GUICtrlCreateInput("", 104, 72, 169, 21)
GUICtrlSetCursor (-1, 5)
$address = GUICtrlCreateInput("", 104, 106, 169, 21)
GUICTRLSetState($address,$GUI_DISABLE)
GUICtrlSetCursor (-1, 5)
$DoctorNam = GUICtrlCreateLabel(" Doctor's name", 24, 72, 75, 17)
$addres = GUICtrlCreateLabel(" Address", 42, 104, 45, 17)
GUICtrlSetCursor (-1, 5)
$Month_Date = GUICtrlCreateMonthCal("2010/04/06", 328, 72, 229, 164)
GUICtrlSetState($Month_Date, $GUI_HIDE)
$DateOFAppointment = GUICtrlCreateLabel("   D.O.A", 48, 136, 42, 17)

$Calander = GUICtrlCreateButton("", 280, 136, 32, 32, $BS_BITMAP)
GUICtrlSetImage(-1, "C:\Users\RO\Documents\AutoITscripts\Appointments\Images\Button images\Calendar.bmp", -1)
$DOA2 = GUICtrlCreateGroup("Date of Appoint", 96, 130, 169, 57)
$Date = GUICtrlCreateInput("", 112, 160, 145, 21)
GUICtrlSetState($Date,$GUI_DISABLE)
$Create = GUICtrlCreateButton("Create Appointment", 96, 232, 105, 25)
GUICtrlSetState($Create,$GUI_DISABLE)
$Doc_word_count = GUICtrlCreateInput("", 280, 72, 40, 24)
GUICtrlSetState($Doc_word_count,$GUI_DISABLE)
$addressWcount = GUICtrlCreateInput("", 280, 104, 40, 24)
GUICtrlSetState($addressWcount,$GUI_DISABLE)
$Data = GUICtrlCreateList("", 600, 56, 225, 214)
GUICtrlSetData($Data, "")
GUICtrlSetCursor ($Data, 0)
GUICtrlSetState($Data,$GUI_DISABLE)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

and the actual_app.au3:

#include "CTRLS.au3"


func addDatatoCTRL($Ctrl ,$Data)

     local $i = GUICtrlSetData($Ctrl,$data)

     return $i;
        
endfunc

func ReadFromCTRL($Ctrl)

    local  $i = GUICtrlRead($Ctrl,$Data)
   
   return $i
endfunc

that's everything.

Link to comment
Share on other sites

Well, 50% of your code is pointless of backward. Don't take it bad.

OK, why do you insist in hiding or disabling controls? That can only make things more complicated than they actually are.

You should let the user (you?) navigate and mess with the controls and only check things more seriously when he (you) hit an OK button. That's the way most dialogs work, for a reason.

The functions in you last posted include are pointless wrappers around GUI functions, except that your ReadFromCTRL function actually does _not_ read the control (see help file for why).

You should declare (Global or Local) your variables: that a pretty good habit. They should serve a clear purpose. The timer you launch is useless, a.s.o.

Again, you should study the simple examples of simple GUI functions in the help file. Then try to come up with something more simple and more robust.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Well, 50% of your code is pointless of backward. Don't take it bad.

OK, why do you insist in hiding or disabling controls? That can only make things more complicated than they actually are.

You should let the user (you?) navigate and mess with the controls and only check things more seriously when he (you) hit an OK button. That's the way most dialogs work, for a reason.

The functions in you last posted include are pointless wrappers around GUI functions, except that your ReadFromCTRL function actually does _not_ read the control (see help file for why).

You should declare (Global or Local) your variables: that a pretty good habit. They should serve a clear purpose. The timer you launch is useless, a.s.o.

Again, you should study the simple examples of simple GUI functions in the help file. Then try to come up with something more simple and more robust.

the timer was just a test, it's not meant to be in it yet

Oh, how would i move the cursor from one controlk to another after enter is pressed? can't seem to find anything on it.

Edited by RosarioC
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...