Jump to content
Sign in to follow this  
Herb191

Gui text alignment?

Recommended Posts

Herb191

Im working on a book scanning program that list the title and list price when I a scan book. It works fine but I would like the list price to be aligned evenly on right when I scan a book. I thought by having the same amount of characters in the GUICtrlCreateLabel the prices would align correctly but it appears that the width of the characters are different. Anyone have anyone have any suggestions?

Here is the script:

#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <WindowsConstants.au3>
#include <ScrollBarConstants.au3>
#include <GUIEdit.au3>



_Scanoutgui()

Func _Scanoutgui()
    Global $Record,$BarCodeNumber, $BookEntrySpot, $BookEntrySpot, $BookNumber, $TextToCount, $TextToCount, $TextCharacterCounter
    Global  $ScanningOutOfWAREHOUSE, $ScanningOutOfREPAIR, $ScanningOutOfSTORE
    Local $msg, $OK, $TEXT

        GUICreate("",900,600)
        GUISetState(@SW_SHOW) 
    
        $OK = GUICtrlCreateButton("OK", 600, 550, 105, 25, $BS_DEFPUSHBUTTON)
    
        $DisplayEntry = GUICtrlCreateEdit($TEXT, 10, 50, 500, 400, $ES_AUTOVSCROLL +$ES_AUTOHSCROLL + $WS_VSCROLL + $ES_MULTILINE + $ES_READONLY)
        GUICtrlSetFont($DisplayEntry, 20)
            
        GUICtrlCreateLabel("Enter ISBN +5 Digits", 10, 520, 200)
        $BarCodeNumber = GUICtrlCreateInput("", 10, 540, 420, 20)
        GUICtrlSetState(-1, $GUI_FOCUS)
        
        $ScanningOutOfSTORE = GUICtrlCreateCheckbox(" BOOK IS BEING SCANNING OUT OF THE STORE", 550, 340, 300, 20)
        _GUICtrlButton_SetCheck($ScanningOutOfWAREHOUSE, $BST_CHECKED)
        
        $ScanningOutOfWAREHOUSE = GUICtrlCreateCheckbox(" BOOK IS BEING SCANNING OUT OF THE WAREHOUSE", 550, 380, 300, 20)
        _GUICtrlButton_SetCheck($ScanningOutOfWAREHOUSE, $BST_UNCHECKED)
        
        $ScanningOutOfREPAIR = GUICtrlCreateCheckbox(" BOOK IS BEING SCANNING OUT OF REPAIR", 550, 420, 300, 20)
        _GUICtrlButton_SetCheck($ScanningOutOfWAREHOUSE, $BST_UNCHECKED)
        
        

    While 1
        $InSystem = ("Yes")

        While 1
        
            $msg = GUIGetMsg()
            Select
                Case $msg = $OK

                    $BarCodeReader = GUICtrlRead ($BarCodeNumber)
                    $BarCodeReader = StringTrimRight ($BarCodeReader, 5)
                    $CharacterCount=StringRegExp($BarCodeReader, "\d", 4)
                    $CharacterCount = (UBound($CharacterCount))

                    If ($CharacterCount) < (13) Then
                        Select
                            Case ($CharacterCount) < (10)
                                MsgBox(4096, "", "Not a Valid ISBN")
                                ExitLoop        
                            Case ($CharacterCount) > (10)
                                MsgBox(4096, "", "Not a Valid ISBN")
                                ExitLoop
                        EndSelect
                    EndIf
                            
     
            $Bookinfo = @ScriptDir & "\Bookinfo.ini"
            $BookNumber = IniRead($Bookinfo, "BookNumber", "BookNumber", "0")
            $BookNumber2 = (0)
    
            While 1
                $Duplicatetest = IniRead($Bookinfo, $BookNumber2, "ISBN WITH NO DASHES", "Error")
                If $Duplicatetest = $BarCodeReader Then
                    $BookEntrySpot = $BookNumber2
                    ExitLoop
                EndIf
                
                If $BookNumber2 = ($BookNumber+2) Then
                    MsgBox(4096, "", "There is no copy of this book in the system")
                    $InSystem = ("No")
                    ExitLoop
                EndIf
                $BookNumber2 = $BookNumber2 + 1
            WEnd
    
            If $InSystem = ("No") Then
                guictrlsetdata($BarCodeNumber,"")
                ExitLoop
            EndIf
                            
            $TextToCount = IniRead($Bookinfo, $BookEntrySpot, "Title", "Error")         
            $TEXTCharacterCount=StringRegExp($TextToCount, "\D", 4)
            $TEXTCharacterCount = (UBound($TEXTCharacterCount))
                
            If $TEXTCharacterCount > 20 Then
                $TextCharacterCounter = 0
                While 1
                    $TEXTCharacterCount = $TEXTCharacterCount - 1
                    $TextCharacterCounter = $TextCharacterCounter + 1 
                    
                    If $TEXTCharacterCount = 20 Then
                        $TextToCount = StringTrimRight ($TextToCount, $TextCharacterCounter) & IniRead($Bookinfo, $BookEntrySpot, "LIST PRICE", "Error")
                        ExitLoop
                    EndIf
                WEnd
            EndIf
            
            If $TEXTCharacterCount < 20 Then
                
                $TextCharacterCounter = $TEXTCharacterCount
                
                While 1
                    $TextCharacterCounter = $TextCharacterCounter + 1 
                    $TextToCount = ($TextToCount & ".")
                    
                    If  $TextCharacterCounter = 20 Then
                        
                        ExitLoop
                    EndIf
                WEnd
            EndIf
                            
            If $TEXT = ("") then
                $TEXT = $TextToCount & ".............................." & IniRead($Bookinfo, $BookEntrySpot, "LIST PRICE", "Error")
            Else
                $TEXT = $TEXT & @CRLF & $TextToCount & ".............................." & IniRead($Bookinfo, $BookEntrySpot, "LIST PRICE", "Error")
            EndIf
            
            guictrlsetdata($BarCodeNumber,"")
            guictrlsetdata($DisplayEntry, $TEXT)
            GUICtrlSetStyle ($DisplayEntry, BitOR($ES_AUTOVSCROLL, $ES_READONLY, $ES_WANTRETURN, $WS_VSCROLL))
            _GUICtrlEdit_Scroll($DisplayEntry, $SB_SCROLLCARET)
            
        
            Case $msg = $GUI_EVENT_CLOSE 
                Exit
            EndSelect       
        WEnd
    WEnd
EndFunc

The Bookinfo.ini file looks like this:

[BookNumber]
BookNumber=4
[2]
Title=Off the Chart
Author=James Hall
ISBN=0312-99723-X
ISBN WITH NO DASHES=9780312997236
ISBN13=978-0312-99723-6
Publisher=St Martins Pr
Publish Date=St Martins Pr
Binding=Paperback  
LIST PRICE=6.99  
Numberofcopies=1
HOUR=22
MIN=59
MON=05
MDAY=02
YEAR=2009
Genre=Miscellaneous
LIST PRICE1=6.99
ConditionOfBook1=VERYGOOD
CopesOfBooksInStore=1
[3]
Title=Target
Author=Catherine Coulter
ISBN=0515-12562-8
ISBN WITH NO DASHES=9780515125627
ISBN13=978-0515-12562-7
Publisher=Berkley Pub Group
Publish Date=Berkley Pub Group
Binding=Paperback  
LIST PRICE=7.99  
Numberofcopies=1
HOUR=22
MIN=59
MON=05
MDAY=02
YEAR=2009
Genre=Miscellaneous
LIST PRICE1=7.99
ConditionOfBook1=VERYGOOD
CopesOfBooksInStore=1
[4]
Title=Point Blank
Author=Catherine Coulter
ISBN=0515-14168-2
ISBN WITH NO DASHES=9780515141689
ISBN13=978-0515-14168-9
Publisher=Berkley Pub Group
Publish Date=Berkley Pub Group
Binding=Paperback  
LIST PRICE=7.99  
Numberofcopies=1
HOUR=23
MIN=00
MON=05
MDAY=02
YEAR=2009
Genre=Miscellaneous
LIST PRICE1=7.99
ConditionOfBook1=VERYGOOD
CopesOfBooksInStore=1

If you enter the flowing ISBN numbers and use the Bookinfo.ini file you will see what I mean about the alignment:

978051514168950799

978051512562750750

978031299723650699

Thanks

Share this post


Link to post
Share on other sites
Authenticity

Look at StringFormat() function in the help file. You can pad text and play around with the string functions. You have an interesting way to get the string length using StringRegExp... You can restrict the edit control to accept only numbers and use StringLen instead, preferred way in my opinion.

Share this post


Link to post
Share on other sites
martin

Look at StringFormat() function in the help file. You can pad text and play around with the string functions. You have an interesting way to get the string length using StringRegExp... You can restrict the edit control to accept only numbers and use StringLen instead, preferred way in my opinion.

You could also consider using monospace fonts then the text will behave as you first expected.

This link gives a good view of many types.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
Herb191

Thanks I think that will get me going in the right direction. As for StringLen I didnt know it existed. When I dont know how to do something I usually spend a lot of time in looking in the help files and form until I find something that I can make work. Lol if you saw some of my other code it might scare you! ^_^

Look at StringFormat() function in the help file. You can pad text and play around with the string functions. You have an interesting way to get the string length using StringRegExp... You can restrict the edit control to accept only numbers and use StringLen instead, preferred way in my opinion.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.