Sign in to follow this  
Followers 0
Coolw

Address Book

13 posts in this topic

#1 ·  Posted (edited)

I am working on an address book that can do quite a bit. Suggestions are accepted by all means, and criticism is too!

How my versions work, if they are any different:

1st number will be a HUGE Update (Probably re-wrote code)

2nd number will be a update worth downloading

3rd number is a small update

Current Version - 1.0.3

V 1.0.3

New:

-You can now add more than 1 user in a session!

Changed:

-[Fixed] HUGE BUG

Things to finish:

-Delete People

-Edit People

-Updates when switching between 2 people

-Suggestions? Post them!

CODE
#include <GUIConstants.au3> ;Include; simple, yet effective

#include <GuiComboBox.au3> ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

;Lets go ahead and declare some variables for later

$a = 1

$Clear = 0

$disabled = "NO"

$line=1

$loop=1

$pline = ""

$Start = 0

;Set an escape key just incase the BIG RED X doesn't work

HotKeySet("{Esc}", "_end")

;Let's make those god forsaken GUI's

GUICreate("Address Book",600, 400)

$combo = GUICtrlCreateCombo( "Add New Contact", 10,10, 200)

$label1 = GUICtrlCreateLabel( "Name -> ", 10,40)

$name = GUICtrlCreateInput( "", 54, 40, 130)

$label2 = GUICtrlCreateLabel( "Address -> ", 10, 70)

$address = GUICtrlCreateInput( "", 64, 70, 300)

$label3 = GUICtrlCreateLabel( "Home Phone -> ", 10, 100)

$phone = GUICtrlCreateInput( "", 100, 100, 100)

$label4 = GUICtrlCreateLabel( "Other Phone -> ", 10, 130)

$phone2 = GUICtrlCreateInput( "", 100, 130, 100)

$label5 = GUICtrlCreateLabel( "Email -> ", 10, 160)

$email = GUICtrlCreateInput( "", 60, 160, 250)

$store = GUICtrlCreateButton("Store / Save", 400, 350, 175)

$DeleteUser = GUICtrlCreateButton( "Delete Contact", 400, 315)

GUISetState()

;See if the person has any contacts

If FileExists("People.txt") Then

FileOpen( "People.txt", 0)

Opencontacts() ;Run the function to open the contacts

EndIf

;Lets start on all the fun, lovely code to get these gears grinding

While GUIGetMsg() <> $GUI_EVENT_CLOSE ;Just to make sure your not trying to close the program :)

$selection = _GUICtrlComboBox_GetCurSel($combo) ;Lets see what they have selected

Select

Case $selection = 0 ;They have selected to make a new user (Next release there will be a button!!)

ResetBlank()

GUICtrlSetState($DeleteUser, $GUI_DISABLE) ;What will they delete when making a new user??

$disabled = "YES" ;CTRL is disabled

While $loop = 1 ;Wait until they have hit store or done something else

$msg = GUIGetMsg()

Select

Case $msg=$store ;They hit the store button

$loop = 0

$nameconverted = GUICtrlRead($name)

$addressconverted = GUICtrlRead($address)

$phoneconverted = GUICtrlRead($phone)

$phone2converted = GUICtrlRead($phone2)

$emailconverted = GUICtrlRead($email)

StoreUser()

Case $msg=$GUI_EVENT_CLOSE

Exit

Case _GUICtrlComboBox_GetCurSel($combo) <> 0

$loop = 0

EndSelect

WEnd

Case $selection <> 0 ;Lets get that information from that dang .TXT (soon might incoorperate My SQL, if I can learn it)

If $disabled = "YES" Then ;Make sure the delete button is'nt already enabled/disabled!

GUICtrlSetState( $DeleteUser, $GUI_ENABLE) ;Make sure that you can delete a user

$disabled = "NO" ;Lets enable this baby!

EndIf

GUICtrlSetData($name, FileReadLine("People.txt", (_GUICtrlComboBox_GetCurSel($combo) * 5 - 4)))

GUICtrlSetData($address, FileReadLine("People.txt", (_GUICtrlComboBox_GetCurSel($combo) * 5 - 3)))

GUICtrlSetData($phone, FileReadLine("People.txt", (_GUICtrlComboBox_GetCurSel($combo) * 5 - 2)))

GUICtrlSetData($phone2, FileReadLine("People.txt", (_GUICtrlComboBox_GetCurSel($combo) * 5 - 1)))

GUICtrlSetData($email, FileReadLine("People.txt", (_GUICtrlComboBox_GetCurSel($combo) * 5)))

$oldselection = _GUICtrlComboBox_GetCurSel($combo) ;Store selection

GUISetState()

While $loop = 0

CheckStatus()

WEnd

EndSelect

Wend

Func CheckStatus() ;Lets see if anything new is happenin'

If _GUICtrlComboBox_GetCurSel($combo) <> $oldselection Then ;If the selection has changed then update. Sometimes doesn't work

GUICtrlSetData($name, FileReadLine("People.txt", (_GUICtrlComboBox_GetCurSel($combo) * 5 - 4)))

GUICtrlSetData($address, FileReadLine("People.txt", (_GUICtrlComboBox_GetCurSel($combo) * 5 - 3)))

GUICtrlSetData($phone, FileReadLine("People.txt", (_GUICtrlComboBox_GetCurSel($combo) * 5 - 2)))

GUICtrlSetData($phone2, FileReadLine("People.txt", (_GUICtrlComboBox_GetCurSel($combo) * 5 - 1)))

GUICtrlSetData($email, FileReadLine("People.txt", (_GUICtrlComboBox_GetCurSel($combo) * 5)))

EndIf

$msg2 = GUIGetMsg()

If _GUICtrlComboBox_GetCurSel($combo) = 0 Then $loop = 1

Select

Case $msg2 = $DeleteUser ;They hit the delete contact button

DeleteUser() ;Run the function to delete the contact (AKA USER)

Case $msg2 = $GUI_EVENT_CLOSE

Exit

EndSelect

EndFunc ;One down, a few more to go!

Func Opencontacts() ;Lets go ahead and see who you got in your book

While $a = 1

$pline = FileReadLine("People.txt", $line) ;Read only the lines that have names in them

If @error = -1 Then ;If this is done REALLY fast, get some more friends or talk to your family

$a = 0

ExitLoop

EndIf

$line = $line + 5 ;Go to the next line with a name in it

GUICtrlSetData( $combo, $pline) ;Make a new combo selection to see who you have!

WEnd

EndFunc ;Finally, lets continue, shall we?

Func DeleteUser() ;Awww who did you just get in a fight with?

$delete = MsgBox(4, "Delete User", "Are you sure you want to delete "& FileReadLine("People.txt", (_GUICtrlComboBox_GetCurSel($combo) * 5 - 4)) & "?") ;Did you accidently hit the button?

If $delete = 6 Then ;Oh no! You really are mad at that person!

MsgBox(0,"","Haha just kidding, this was just a test delete!") ;Not done with delete code, will be in next release!

EndIf

EndFunc ;Yay the functions over! ON TO THE NEXT ONE!!

Func ResetBlank() ;This resets the input box to blanks!

GUICtrlSetData($name, "") ;Seems pointless, but if I don't screws up the program

GUICtrlSetData($address, "") ;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

GUICtrlSetData($phone, "") ;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

GUICtrlSetData($phone2, "") ;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

GUICtrlSetData($email, "") ;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

EndFunc

Func StoreUser() ;You just added someone new! You are loved by someone!

If $nameconverted = "" Then ;Lets make sure you have at least a name typed in!

MsgBox(0, "Error", "You must type a name!") ;Haha caught you!

Else ;Whew you were smart enough to type a name!

If $a <> 0 Then FileClose("People.txt") ;Aww crap, not the right mode!

$file = Fileopen("People.txt", 1) ;Yayyy right mode!

FileWriteLine("People.txt", $nameconverted)

FileWriteLine("People.txt", $addressconverted)

FileWriteline("People.txt", $phoneconverted)

FileWriteLine("People.txt", $phone2converted)

FileWriteLine("People.txt", $emailconverted & @CRLF)

FileClose("People.txt") ;Lets stop writing and start reading again!

FileOpen("People.txt", 0) ;Reading is boring!

$a = 1

$loop = 1

GUICtrlDelete($combo) ;Lets delete that old book!

$combo = GUICtrlCreateCombo( "Add New Contact", 10,10, 200) ;Yay we made a new one, so there is'nt so much re-writing going on

ResetBlank()

UpdateUser()

GUISetState() ;Just to make sure we have everything drawn

EndIf

EndFunc ;Done!

Func UpdateUser() ;Yayyy update!

$line = 1

While $a = 1

$pline = FileReadLine("People.txt", $line) ;Read only the lines that have names in them

If @error = -1 Then ;If this is done REALLY fast, get some more friends or talk to your family

$a = 0

ExitLoop

EndIf

$line = $line + 5 ;Go to the next line with a name in it

GUICtrlSetData( $combo, $pline) ;Make a new combo selection to see who you have!

WEnd

$a = 1

EndFunc

Func _end() ;Escape function

Exit

EndFunc ;Aww dang you escaped

Changelog.txt

Address_Book.au3

Edited by Coolw

My ProgramsMy WIP'sSteam Server Restarter

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I am working on an address book that can do quite a bit. Suggestions are accepted by all means, and criticism is too!

Version - 1.0 Alpha

V 1.0 Alpha

New:

-Public Release

-Add new people

-Name, Address, 2 phone numbers, Email

-View Address Book

-Updates real time after adding new person

Changed:

-Nothing

Things to finish:

-Delete people

-Edit people

-Mem leak when viewing people

-Updates when switching between 2 people

-Suggestions? Post them!

Issues: After adding contact for the first time, it clears the combo box and doesn't populate anything.

Closing the script and opening it again, gives the following error:

>Running:(3.2.10.0):D:\Program Files (x86)\AutoIt3\autoit3.exe "D:\Documents and Settings\Administrator\Desktop\Sources\file.au3"   
D:\Documents and Settings\Administrator\Desktop\BTCChatSources\file.au3 (68) : ==> Variable used without being declared.: 
GUICtrlDelete($store) 
GUICtrlDelete(^ ERROR

Just as a suggestion, to speed things up and make them.....more inline, you should try and declare all of your controls after the form is created, and then just use GuiCtrlSetState() to hide/show them as needed. Otherwise you may end up re-creating buttons when buttons already exist.

Secondly, I would HIGHLY recommend you integrate SQLLite into this application, as it's a simple database program, and is a much faster access than just a file based system that you have now.

Thirdly, I would recommend you create a button or menu option to 'create' contacts, instead of the drop down section you have now. While active forms are great, when you want to actually VIEW vs CREATE something, it makes using the UI much better :)

/me is looking forward to any changes you make :(

Edited by zackrspv

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Share this post


Link to post
Share on other sites

Issues: After adding contact for the first time, it clears the combo box and doesn't populate anything.

Closing the script and opening it again, gives the following error:

>Running:(3.2.10.0):D:\Program Files (x86)\AutoIt3\autoit3.exe "D:\Documents and Settings\Administrator\Desktop\Sources\file.au3"   
D:\Documents and Settings\Administrator\Desktop\BTCChatSources\file.au3 (68) : ==> Variable used without being declared.: 
GUICtrlDelete($store) 
GUICtrlDelete(^ ERROR

Just as a suggestion, to speed things up and make them.....more inline, you should try and declare all of your controls after the form is created, and then just use GuiCtrlSetState() to hide/show them as needed. Otherwise you may end up re-creating buttons when buttons already exist.

Secondly, I would HIGHLY recommend you integrate SQLLite into this application, as it's a simple database program, and is a much faster access than just a file based system that you have now.

Thirdly, I would recommend you create a button or menu option to 'create' contacts, instead of the drop down section you have now. While active forms are great, when you want to actually VIEW vs CREATE something, it makes using the UI much better :)

/me is looking forward to any changes you make :(

About the whole error thing, I found that when you try to add the same contact 2 times, probably hit store 2 times, it gives the same error, and i haven't tested it compiled, just ran from source.

How do I use SQLLite?


My ProgramsMy WIP'sSteam Server Restarter

Share this post


Link to post
Share on other sites

About the whole error thing, I found that when you try to add the same contact 2 times, probably hit store 2 times, it gives the same error, and i haven't tested it compiled, just ran from source.

How do I use SQLLite?

I was only trying to add a single contact, and it gave me the issue :)

Lastly, you need to do a search for SQL Lite, but also on the general help and support section, there's a FAQ for it :(


-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Share this post


Link to post
Share on other sites

I was only trying to add a single contact, and it gave me the issue :)

Lastly, you need to do a search for SQL Lite, but also on the general help and support section, there's a FAQ for it :(

What does the .txt file look like? I did the same thing, it worked.


My ProgramsMy WIP'sSteam Server Restarter

Share this post


Link to post
Share on other sites

I looked at the script and puked. Everywhere.

Why is that?

Do you have any suggestions?


My ProgramsMy WIP'sSteam Server Restarter

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

I found several issues with this program.

1) You can add a blank contact. If you do this and you quit the program you can't run it again (error on Line 68.)

2) After adding the first contact when the program is started up, the GUI flickers like crazy and you cannot add more entries.

3) When selected the newly added contact from the combobox, the "Delete Contact" button appears over top of the "Store" button.

4) The program cannot add more than one entry per program session.

5) Can't delete any users

6) More things

Since this seems to be your first attempt at such a program I'll try to give some constructive criticism. :)

Number one thing your code is missing is comments. This is considered by many to be the cardinal rule of programming. ALWAYS COMMENT YOUR CODE. This is both for your benefit and the benefit of others. For this program it's not a big deal considering its relative simplicity, but once you start making larger and more complex scripts/programs you'll be glad you added comments. As a beginner it's a good exercise.

Another thing is code organization. Simply put, there is none. It's just one big long procedural program, one line of code after another. When writing programs like these it's important to consider the overall organization of the code because it affects readability and functionality. For example...

Func DeleteUser()
    MsgBox(4, "Delete User", "Are you sure you want to delete "& FileReadLine("People.txt", (_GUICtrlComboBox_GetCurSel($combo) * 5 - 4)) & "?")
EndFuncoÝ÷ Ù8b²+r©ë^+¬zW¬±û§rب¬¶Ú!j÷~éܶ*'¶­q©e²êZ1ë,j£hv+)¬­¢Ø^ºÇ«Êh{ezËÛ§yǬ±ªò6"*.­û§rب
.×b²ZÊØ^1ë,j£§vØ^·­º¹Ú½©nz)ÝÆ­x0ëaz»azë®Ç¥yË^u¬¢³h¶­(!µ·n+[zÛ^­©m ¯x,x%zX§yû§rبÌ!ÈcºËjYh¶«~éܶ*'±ªÞ¦·­·+¬zW¬±K"aËébêr^jƧ{¦¦W­+"±Qb(­ú+«­¢+Ù¥±I1¥¹ ÅÕ½ÐíA½Á±¹ÑáÐÅÕ½Ðì°¡}U%
Ñɱ
½µ½  ½á}Ñ
ÕÉM° ÀÌØí½µ¼¤¨Ô´Ð¤oÝ÷ ØÄ}÷*ÞrÙriDzȧ§âæ§u«mëëbênX§êZ±é^rبúè§(º£^¯)ڲܷ
+Æî¶+wöÈî²Ö¦jÛ^®ß¢¹Â¥vË ë-­ì+اØ^
é^µå,z·îËb¢v¬~e£ºÚ"µÍ[È[]UÙ  ÌÍØÛÛXÝ
B]ÙÐÞ
    ][ÝÑ[]HÙ][ÝË   ][ÝÐH[ÝHÝH[ÝHØ[È[]H  ][ÝÈ  [È ÌÍØÛÛXÝ   [È ][ÝÏÉ][ÝÊB[[oÝ÷ Ù8^*.q©e¶­~éܶ*'jÇèZ0±«­¢+Ù%±ÑUÍÈ¡}U%
Ñɱ
½µ½  ½á}Ñ
ÕÉM° ÀÌØí½µ¼¤¤ôôØQ¡¸(¸¸¸±ÑÕÍȽ½Ì¡É¸¸¸)¹%oÝ÷ ØËÉ^jw«Nºw-â±Æ¥çZÛayÊ'µ§-©ÊZ²ÇjËaz«jg­z´ázy^¶Ø^q©ez»azf¢û§rب§vW­æ¶æ¥¦ºzË"áȬ­#fµ©dxn­Â§"Ʋr^¢¸,âjب 趫n('¢zbqçmìË*.r·µç(ÚèÊ'¶&¬çyÖ®¶­sbb33c·6fRÒuT7G&Ä7&VFTÆ&VÂgV÷Cµ4dR5T44U54eTÂb333²gV÷C²ÂÂ#s¢VÇ6P¢b33c·6fRÒuT7G&Ä7&VFTÆ&VÂgV÷C´W'&÷"6fær6BævbgV÷C²ÂÂ#s¢VæD`

Very bad form, because you're creating a new control every time this piece of code is executed. It's better to have controls set up and just changing their fields rather than creating new ones. It's an awful waste of system resources. Obviously these days it's not a concern when you've got 2 gigs of RAM but it's the principle of the matter.

One more obvious thing: the GUI itself. Is all that whitespace at the right and bottom really necessary? Why not shrink the main window down so all the controls fit nicely inside?

Many people may not think so, but I subscribe to the school of thought that a program's GUI is one of its most important features. When designing a GUI it's important to keep a few things in mind:

1) Ease of use/intuitiveness

2) Functionality

3) Asthetics

I've seen tons of ugly-looking GUIs in my day (but don't worry, yours is definitely not the worst wink.gif) and it really bothers me when there exists a program that has a bad-looking GUI. Asthetics are important because not only do they add an air of professionalism but they also assist in the ease of use of a program.

That being said, I recommend aligning GUI items (use a grid of 5 or 10), grouping together controls in a way that makes the most amount of sense from a USER perspective, and laying everything out in a way that's pleasing to the eye.

It's also important to design a GUI that "makes sense". In this case, I would suggest completely throttling the "Add new contact" item in the combobox, because it's tedious (from a user point of view) to have to select that item every time a user wants to make a new entry (at least in my opinion.)

Whew that's a lot of words. I could sure say a helluva lot more (especially on GUI design) but I think I'll step down now.

Don't get discouraged because it takes time to get the hang of it. Just keep practicing and you'll eventually learn what constitutes sexy code. :(

Edited by ACS

Share this post


Link to post
Share on other sites

Wow,

Not so good..

I'm sorry dude, but you wrote a lot of script for creating something this easy and basic.. :)

Share this post


Link to post
Share on other sites

Ok I have updated the program here is what I did: (Taken from changelog, so I might have missed a few things!)

New:

-Commented code so you know whats going on

-Fixed GUI so that its not being drawn so much, using less resources!

Changed:

-[Fixed] Memory Leak when viewing people

To Do:

-Delete People

-Edit People

This is still a W.I.P. and I am trying to learn all I can, so it might take me a while to get what you want in there. I am still working on all of the other fixes and new items. :) Just stick with me!


My ProgramsMy WIP'sSteam Server Restarter

Share this post


Link to post
Share on other sites

Is there anything you guys would like me to add before the next update? :)


My ProgramsMy WIP'sSteam Server Restarter

Share this post


Link to post
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
Sign in to follow this  
Followers 0