|
Hobbyist Programmer
Join Date: Feb 2005
Posts: 112
Rep Power: 4 
|
my Calculator
just to get this forum started... heres a calculator i created a long while ago  you need the latest autoit3 to run it!
; Script generated by AutoBuilder 0.5 Prototype (controls [button's, edit's, etc] were created by AutoBuilder)
#include <GUIConstants.au3>
GUICreate("AuCalculator v. 3.5", 392, 316, (@DesktopWidth - 392) / 2, (@DesktopHeight - 316) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
Global $Button_1 = GUICtrlCreateButton("1", 70, 70, 40, 30)
Global $Edit_23 = GUICtrlCreateEdit("", 70, 25, 180, 20, $ES_AUTOHSCROLL)
Global $Button_3 = GUICtrlCreateButton("2", 140, 70, 40, 30)
Global $Button_4 = GUICtrlCreateButton("3", 210, 70, 40, 30)
Global $Button_5 = GUICtrlCreateButton("4", 70, 120, 40, 30)
Global $Button_6 = GUICtrlCreateButton("5", 140, 120, 40, 30)
Global $Button_7 = GUICtrlCreateButton("6", 210, 120, 40, 30)
Global $Button_8 = GUICtrlCreateButton("Clear", 280, 20, 40, 30)
Global $Button_9 = GUICtrlCreateButton("7", 70, 170, 40, 30)
Global $Button_10 = GUICtrlCreateButton("8", 140, 170, 40, 30)
Global $Button_11 = GUICtrlCreateButton("9", 210, 170, 40, 30)
Global $Button_12 = GUICtrlCreateButton("Equals =", 130, 250, 60, 40)
Global $Button_13 = GUICtrlCreateButton("Add +", 40, 210, 60, 40)
Global $Button_14 = GUICtrlCreateButton("Subtract -", 210, 210, 60, 40)
Global $Button_15 = GUICtrlCreateButton("Multiply *", 40, 260, 60, 30)
Global $Button_16 = GUICtrlCreateButton("0", 140, 210, 40, 30)
Global $Button_17 = GUICtrlCreateButton("Divide /", 210, 260, 60, 30)
Global $Button_28 = GUICtrlCreateButton('Decimal "."', 280, 70, 60, 40)
Global $Menu_29 = GUICtrlCreateMenu("Switch to...")
Global $MenuItem_30 = GUICtrlCreateMenuitem("Conversions", $Menu_29)
Global $Button_31 = GUICtrlCreateButton("Square Root", 280, 120)
Global $Menu_item32= GUICtrlCreateMenuItem ("Greater then... etc", $menu_29)
GUISetState()
Func Conversions()
#include <GUIConstants.au3>
GUICreate("Conversions")
GUISetState(@SW_SHOW)
$b = GUICtrlCreateButton("Convert", 5, 30)
$l = GUICtrlCreateLabel("Feet to inches:", 1, 1)
$i = GUICtrlCreateInput("Feet here", 55, 33)
$b2 = GUICtrlCreateButton("Convert", 5, 100,)
$l2 = GUICtrlCreateLabel("Inches to feet:", 1, 75)
$i2 = GUICtrlCreateInput("Inches here", 54, 103)
$b3 = GUICtrlCreateButton("Convert", 5, 170)
$l3 = GUICtrlCreateLabel("Ounces to pounds:", 1, 145)
$i3 = GUICtrlCreateInput("Ounces here", 53, 173, 0x0080)
$b4 = GUICtrlCreateButton("Convert", 5, 233)
$l4 = GUICtrlCreateLabel("Pounds to ounces:", 1, 210)
$i4 = GUICtrlCreateInput("Pounds to ounces", 53, 235)
While 1
$get = GUIGetMsg()
$tmpread2 = GUICtrlRead ($i2)
$tmpread = GUICtrlRead ($i)
Select
Case $get = $GUI_EVENT_CLOSE
Calc ()
ExitLoop
Case $get = $b
$tmpread = GUICtrlRead ($i)
$fee2in = Number($tmpread * 12)
MsgBox(0, "Result", $fee2in & " Inches")
Case $get = $b2
If $tmpread2 = 12 Then
MsgBox(0, "Result", "1 Foot")
Else
$in2fee = Number($tmpread2 / 12)
MsgBox(0, "Result", $in2fee & " Feet")
EndIf
Case $get = $b3
$tmpread = GUICtrlRead ($i3)
If $tmpread = 16 Then
MsgBox(0, "Result", "1 Pound")
Else
$tmpread = GUICtrlRead ($i3)
$oz2lb = Number($tmpread / 16)
MsgBox(0, "Result", $oz2lb & " Pounds")
EndIf
Case $get = $b4
$tmpread = GUICtrlRead ($i4)
$lb2oz = Number($tmpread * 16)
MsgBox(0, "Result", $lb2oz & " Ounces")
EndSelect
Wend
EndFunc ;==>Conversions
Func Calc()
#include <GuiConstants.au3>
Dim $WS_OVERLAPPEDWINDOW = 0xCF0000, $WS_VISIBLE = 0x10000000, $WS_CLIPSIBLINGS = 0x04000000
GUICreate("AuCalculator v. 3.5", 392, 316, (@DesktopWidth - 392) / 2, (@DesktopHeight - 316) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
Global $Button_1 = GUICtrlCreateButton("1", 70, 70, 40, 30)
Global $Edit_23 = GUICtrlCreateEdit("", 70, 25, 180, 20, $ES_AUTOHSCROLL)
Global $Button_3 = GUICtrlCreateButton("2", 140, 70, 40, 30)
Global $Button_4 = GUICtrlCreateButton("3", 210, 70, 40, 30)
Global $Button_5 = GUICtrlCreateButton("4", 70, 120, 40, 30)
Global $Button_6 = GUICtrlCreateButton("5", 140, 120, 40, 30)
Global $Button_7 = GUICtrlCreateButton("6", 210, 120, 40, 30)
Global $Button_8 = GUICtrlCreateButton("Clear", 280, 20, 40, 30)
Global $Button_9 = GUICtrlCreateButton("7", 70, 170, 40, 30)
Global $Button_10 = GUICtrlCreateButton("8", 140, 170, 40, 30)
Global $Button_11 = GUICtrlCreateButton("9", 210, 170, 40, 30)
Global $Button_12 = GUICtrlCreateButton("Equals =", 130, 250, 60, 40)
Global $Button_13 = GUICtrlCreateButton("Add +", 40, 210, 60, 40)
Global $Button_14 = GUICtrlCreateButton("Subtract -", 210, 210, 60, 40)
Global $Button_15 = GUICtrlCreateButton("Multiply *", 40, 260, 60, 30)
Global $Button_16 = GUICtrlCreateButton("0", 140, 210, 40, 30)
Global $Button_17 = GUICtrlCreateButton("Divide /", 210, 260, 60, 30)
Global $Button_28 = GUICtrlCreateButton('Decimal "."', 280, 70, 60, 40)
Global $Menu_29 = GUICtrlCreateMenu("Switch to...")
Global $MenuItem_30 = GUICtrlCreateMenuitem("Conversions", $Menu_29)
GUISetState()
While 1
$get = GUIGetMsg()
Select
Case $get = -3;Should really use $GUI_EVENT_CLOSE
ExitLoop
Case $get = $Button_1
GUICtrlSetData($Edit_23, "1", 1)
Case $get = $Button_3
GUICtrlSetData($Edit_23, "2", 1)
Case $get = $Button_4
GUICtrlSetData($Edit_23, "3", 1)
Case $get = $Button_5
GUICtrlSetData($Edit_23, "4", 1)
Case $get = $Button_6
GUICtrlSetData($Edit_23, "5", 1)
Case $get = $Button_7
GUICtrlSetData($Edit_23, "6", 1)
Case $get = $Button_9
GUICtrlSetData($Edit_23, "7", 1)
Case $get = $Button_10
GUICtrlSetData($Edit_23, "8", 1)
Case $get = $Button_11
GUICtrlSetData($Edit_23, "9", 1)
Case $get = $Button_16
GUICtrlSetData($Edit_23, "0", 1)
Case $get = $Button_13
GUICtrlSetData($Edit_23, "+", 1)
Case $get = $Button_14
GUICtrlSetData($Edit_23, "-", 1)
Case $get = $Button_12
$sum = GUICtrlRead ($Edit_23)
$result = _CalcRPN($sum)
GUICtrlSetData($Edit_23, "= ", 1)
GUICtrlSetData($Edit_23, $result, 1)
Case $get = $Button_17
GUICtrlSetData($Edit_23, "/", 1)
Case $get = $Button_15
GUICtrlSetData($Edit_23, "*", 1)
Case $get = $MenuItem_30
Conversions()
ExitLoop
Case $get = $Button_8
GUICtrlDelete($Edit_23)
Global $Edit_23 = GUICtrlCreateEdit("", 70, 25, 180, 20, $ES_AUTOHSCROLL)
Case $get = $Button_28
GUICtrlSetData($Edit_23, ".", 1)
EndSelect
Wend
Exit
EndFunc ;==>Calc
Func _PopStack(ByRef $vaStack)
Local $vValue
If Not IsArray($vaStack) Then
SetError(1) ; invalid stack
Else
$vValue = $vaStack[UBound($vaStack) - 1]
If UBound($vaStack) > 1 Then
ReDim $vaStack[UBound($vaStack) - 1]
$vaStack[0] = UBound($vaStack) - 1
Else
$vaStack[0] = 0
SetError(2) ; empty stack
EndIf
EndIf
Return $vValue
EndFunc ;==>_PopStack
Func _CalcRPN($sInfix)
Local $sOps = "+-*/^"
Local $vaStack1[1]
Local $vaStack2[1]
Local $sChar
Local $sNextChar
Local $n, $i
Local $nOperand1
Local $nOperand2
Local $sOp
$sInfix = StringStripWS($sInfix, 8)
For $n = 1 To StringLen($sInfix)
$sChar = StringMid($sInfix, $n, 1)
If (Asc($sChar) >= 48 And Asc($sChar) <= 57) Or $sChar = "." Then
; if character is a digit or a dot then get full number
While $n < StringLen($sInfix)
$sNextChar = StringMid($sInfix, $n + 1, 1)
If (Asc($sNextChar) >= 48 And Asc($sNextChar) <= 57) Or $sNextChar = "." Then
$sChar = $sChar & $sNextChar
$n = $n + 1
Else
ExitLoop
EndIf
Wend
; push number into stack1
_PushStack($vaStack1, Number($sChar))
ElseIf $sChar = "(" Then
; push left bracket into stack2
_PushStack($vaStack2, $sChar)
ElseIf $sChar = ")" Then
; pop operators from stack2 and push them into stack1 until left bracket
While $vaStack2[0] > 0 And $vaStack2[$vaStack2[0]] <> "("
_PushStack($vaStack1, _PopStack($vaStack2))
Wend
; pop left bracket from stack2
If $vaStack2[$vaStack2[0]] = "(" Then _PopStack($vaStack2)
Else
; get position of operator. Higher position = higher precedence
$i = StringInStr($sOps, $sChar)
If $i > 0 Then
; pop higher precedence operators from stack2 and push them into stack1
While $vaStack2[0] > 0 And StringInStr($sOps, $vaStack2[$vaStack2[0]]) >= $i
_PushStack($vaStack1, _PopStack($vaStack2))
Wend
; push current operator into stack2
_PushStack($vaStack2, $sChar)
EndIf
EndIf
Next
; pop remaining operators from stack2 and push them into stack1
While $vaStack2[0] > 0
_PushStack($vaStack1, _PopStack($vaStack2))
Wend
; clear stack2
ReDim $vaStack2[1]
; copy stack1 to stack2 so the stack order is reversed
For $n = $vaStack1[0] To 1 Step - 1
_PushStack($vaStack2, $vaStack1[$n])
Next
; clear stack1
ReDim $vaStack1[1]
While $vaStack2[0] > 0
If StringInStr($sOps, $vaStack2[$vaStack2[0]]) Then
; if top item is an operator then pop the operator
$sOp = _PopStack($vaStack2)
; pop the second operand
$nOperand2 = _PopStack($vaStack1)
; pop the first operand
$nOperand1 = _PopStack($vaStack1)
; perform the calculation and push the result into stack1
Select
Case $sOp = "+"
_PushStack($vaStack1, $nOperand1 + $nOperand2)
Case $sOp = "-"
_PushStack($vaStack1, $nOperand1 - $nOperand2)
Case $sOp = "*"
_PushStack($vaStack1, $nOperand1 * $nOperand2)
Case $sOp = "/"
_PushStack($vaStack1, $nOperand1 / $nOperand2)
Case $sOp = "^"
_PushStack($vaStack1, $nOperand1 ^ $nOperand2)
EndSelect
Else
; pop number from stack2 and push into stack1
_PushStack($vaStack1, _PopStack($vaStack2))
EndIf
Wend
; the last remaining item in stack1 is the final result
Return _PopStack($vaStack1)
EndFunc ;==>_CalcRPN
Func _PushStack(ByRef $vaStack, $vValue)
If Not IsArray($vaStack) Then
SetError(1) ; invalid stack
Return 0
EndIf
ReDim $vaStack[UBound($vaStack) + 1]
$vaStack[UBound($vaStack) - 1] = $vValue
$vaStack[0] = UBound($vaStack) - 1
Return 1
EndFunc ;==>_PushStack
Func Greaterthen ()
#include <GUIConstants.au3>
GUICreate ("Greater then, less then, or equal too", 300, 300)
GUISetState ()
$edit2= GUICtrlCreateEdit ("", 115, 50, 50, 20, $ES_AUTOHSCROLL)
$edit= GUICtrlCreateEdit ("", 45, 50, 50, 20, $ES_AUTOHSCROLL)
$button= GUICtrlCreateButton ("<,>, or =", 10, 10)
$label= GUICtrlCreateLabel ("Use '/' marks for fractions. Ex [1/2].", 45, 180)
$label2= GUICtrlCreateLabel ("Use % signs as percentage. Ex [100%].", 45, 200)
$biginput= GUICtrlCreateInput ("", 45, 75, 100, 20, 0x0800)
$littleinput= GUICtrlCreateInput ("", 45, 100, 100, 20, 0x0800)
$maxlabel= GUICtrlCreateLabel ("Max #", 5, 75)
$minlabel= GUICtrlCreateLabel ("Min #", 5, 100)
$label3= GUICtrlCreateLabel ("Use . marks for decimals. Ex [10.5].", 45, 220)
$read= GUICtrlRead ($edit)
$read2= GUICtrlRead ($edit2)
$findmin= _Min ($read, $read2)
$findmax= _Max ($read, $read2)
While 1
$get=GUIGetMsg ()
Select
Case $get= -3
Exit
Case $get= $button
$read= GUICtrlRead ($edit)
$read2= GUICtrlRead ($edit2)
If $read=$read2 Then
$equal= _Equal ($edit, $edit2)
GUICtrlDelete ($biginput)
$biginput= GUICtrlCreateInput ("", 45, 75, 100, 20, 0x0800)
GUICtrlDelete ($littleinput)
$littleinput= GUICtrlCreateInput ("", 45, 100, 100, 20, 0x0800)
GUICtrlSetData ($biginput, "=", 1)
GUICtrlSetData ($littleinput, "=", 1)
Else
$findmax= _Max ($read, $read2)
GUICtrlDelete ($biginput)
$biginput= GUICtrlCreateInput ("", 45, 75, 100, 20, 0x0800)
GUICtrlSetData ($biginput, $findmax, 1)
$findmin= _Min ($read, $read2)
GUICtrlDelete ($littleinput)
$littleinput= GUICtrlCreateInput ("", 45, 100, 100, 20, 0x0800)
GUICtrlSetData ($littleinput, $findmin, 1)
EndIf
EndSelect
WEnd
EndFunc
Func _Max( $edit, $edit2 )
If $edit > $edit2 Then
Return $edit
Else
Return $edit2
EndIf
EndFunc
Func _Min( $edit, $edit2 )
If $edit > $edit2 Then
Return $edit2
Else
Return $edit
EndIf
EndFunc
Func _Equal( $edit, $edit2 )
If $edit=$edit2 then
Return '='
EndIf
EndFunc
While 1
$get = GUIGetMsg()
Select
Case $get = -3;Should really use $GUI_EVENT_CLOSE
ExitLoop
Case $get = $Button_1
GUICtrlSetData($Edit_23, "1", 1)
Case $get = $Button_3
GUICtrlSetData($Edit_23, "2", 1)
Case $get = $Button_4
GUICtrlSetData($Edit_23, "3", 1)
Case $get = $Button_5
GUICtrlSetData($Edit_23, "4", 1)
Case $get = $Button_6
GUICtrlSetData($Edit_23, "5", 1)
Case $get = $Button_7
GUICtrlSetData($Edit_23, "6", 1)
Case $get = $Button_9
GUICtrlSetData($Edit_23, "7", 1)
Case $get = $Button_10
GUICtrlSetData($Edit_23, "8", 1)
Case $get = $Button_11
GUICtrlSetData($Edit_23, "9", 1)
Case $get = $Button_16
GUICtrlSetData($Edit_23, "0", 1)
Case $get = $Button_13
GUICtrlSetData($Edit_23, "+", 1)
Case $get = $Button_14
GUICtrlSetData($Edit_23, "-", 1)
Case $get = $Button_12
$sum = GUICtrlRead ($Edit_23)
$result = _CalcRPN($sum)
GUICtrlSetData($Edit_23, "= ", 1)
GUICtrlSetData($Edit_23, $result, 1)
Case $get = $Button_17
GUICtrlSetData($Edit_23, "/", 1)
Case $get = $Button_15
GUICtrlSetData($Edit_23, "*", 1)
Case $get = $MenuItem_30
Conversions()
ExitLoop
Case $get = $Button_8
GUICtrlDelete($Edit_23)
Global $Edit_23 = GUICtrlCreateEdit("", 70, 25, 180, 20, $ES_AUTOHSCROLL)
Case $get = $Button_28
GUICtrlSetData($Edit_23, ".", 1)
Case $get = $Button_31
$getnum = GUICtrlRead ($Edit_23)
$sqrtnum = Sqrt($getnum)
GUICtrlSetData($Edit_23, " Square root is: ", 1)
GUICtrlSetData($Edit_23, $sqrtnum, 1)
Case $get= $menu_item32
Greaterthen ()
EndSelect
Wend
Exit
sorry, there are a few bugs... like when switching to the Greater then etc or whatever and then closing it, the whole calculator exits, but i was a COMPLETE nub when i wrote this... just thought id share it, and ill show u a buggy text editor too...
#include <GUIConstants.au3>
GUICreate ("Ryan's Text Editor", 500, 400)
GUISetState ()
$menu_1= GUICtrlCreateMenu ("&File")
$menu_item1= GUICtrlCreateMenuItem ("Save", $menu_1)
$menu_item2= GUICtrlCreateMenuItem ("Open", $menu_1)
$menu_item4= GUICtrlCreateMenuItem ("Exit", $menu_1)
$Menu= GUICtrlCreateMenu ("&Edit")
$menu_item= GUICtrlCreateMenuItem ("Copy & Ctrl+C", $Menu)
$menu_item3= GUICtrlCreateMenuItem ("Paste & Ctrl+P", $menu)
$menu2= GUICtrlCreateMenu ("&View")
$menu_item5= GUICtrlCreateMenuItem ("Word Wrap", $menu2)
$edit_styles= BitOR ($ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL)
$edit= GUICtrlCreateEdit ("", -1, -1, 500, 400, $ES_WANTRETURN)
Func Save ()
$save= FileSaveDialog ("Save...", @DesktopDir, "Text (*.txt)")
$readedit= GUICtrlRead ($edit)
FileWrite ($save & ".txt", $readedit)
EndFunc
Func Open ()
$open= FileOpenDialog ("Open...", @DesktopDir, "Text (*.txt)")
$readfile= FileOpen ($open, 0)
While 1
$line = FileReadLine($readfile)
If @error = -1 Then ExitLoop
GUICtrlSetData ($edit, $line, 1)
Wend
Return $readfile
FileClose($readfile)
EndFunc
Func WordWrapOn ()
Local $edit_styles= BitOR ($ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL)
$edit= GUICtrlCreateEdit ("", -1, -1, 500, 400, $edit_styles)
GUICtrlSetState ($menu_item5, $GUI_CHECKED)
EndFunc
Func WordWrapOff ()
HotKeySet ("{TAB}", "Tab")
GUICtrlCreateEdit ("", -1, -1, 500, 400)
EndFunc
Func ToggleWordWrap ()
$read5= GUICtrlRead ($menu_item5)
if $read5= $GUI_CHECKED Then
WordWrapOn ()
EndIf
If $read5= $GUI_UNCHECKED Then
WordWrapOff ()
EndIf
EndFunc
HotKeySet ("{TAB}", "Tab")
Func Tab ()
GUICtrlSetData ($edit," ",1)
EndFunc
While 1
$get=GUIGetMsg ()
Select
Case $get= -3
$saveor= MsgBox (3, "Save?", "Save unfinished work?")
If $saveor= 6 then
Save ()
EndIf
If $saveor= 2 then
EndIf
If $saveor= 7 Then
exit
EndIf
Case $get= $menu_item4
Exit
Case $get= $menu_item1
Save ()
Exit
Case $get= $menu_item
$clip= ClipGet ()
$putclip= ClipPut ($clip)
Send ($putclip)
Case $get= $menu_item3
$clip= ClipGet ()
Case $get= $menu_item2
Open ()
Case $get = $menu_item5
If BitAnd(GUICtrlRead($menu_item5),$GUI_CHECKED) = $GUI_CHECKED then
GUICtrlSetState($menu_item5, $GUI_UNCHECKED)
WordWrapOff ()
Else
GUICtrlSetState($menu_item5, $GUI_CHECKED)
WordWrapOn ()
EndIf
Endselect
wend
the word wrap really doesnt work, i just started this, and never worked on it for a while so its probably has a lot of bugs, but, just some examples
and heres a random letter and number generator.. i had a better version that i deleted by accident
#include <GUIConstants.au3>
GUICreate("Random Generator", 200, 100)
$Char = GUICtrlCreateInput("# of characters outputted", 10, 20, 140, 20)
$Make = GUICtrlCreateButton("Generate", 10, 61, 50, 25)
$PW = GUICtrlCreateEdit("", 70, 63.5, 125, 20, $ES_READONLY)
$Clear = GUICtrlCreateButton("Clear", 155, 15)
GUICtrlCreateLabel("Output:", 70, 48, 35, 15)
GUICtrlSetState($Char, $GUI_FOCUS)
GUISetState()
While 1 ;loop edited by Burrup to make sure that a digit is entered!
$Get = GUIGetMsg()
Select
Case $Get = $Make
If StringIsDigit (GUICtrlRead($Char)) = 0 Then
MsgBox(0,"Whoops!","Please enter a digit.")
GUICtrlSetData($Char, "# of characters outputted")
Else
Generate()
EndIf
Case $Get = $Clear
Clear()
Case $Get = -3
Exit
EndSelect
WEnd
Func Generate() ;Func Generate () edited by Burrup which made the function even more random! thanks Burrup
$Read = GUICtrlRead($Char)
If Not StringIsDigit($Read) Then Return
$Read = Number($Read)
GUICtrlSetData($PW, "")
GUICtrlSetLimit($PW, $Read)
For $I = 1 To $Read
$Pass = Chr(Random(Asc("a"), Asc("z"), 1))
$Ran = Random(1, 2, 1)
If $Ran = 1 Then
GUICtrlSetData($PW, $Pass, 1)
GUICtrlSetData($PW, Random(0, 9, 1), 1)
Else
GUICtrlSetData($PW, Random(0, 9, 1), 1)
GUICtrlSetData($PW, $Pass, 1)
EndIf
Next
EndFunc
Func Clear()
GUICtrlDelete($Char)
$Char = GUICtrlCreateInput("# of characters outputted", 10, 20, 140)
GUICtrlDelete($PW)
$PW = GUICtrlCreateEdit("", 70, 63.5, 125, 20, $ES_READONLY)
GUICtrlSetState($Char, $GUI_FOCUS)
EndFunc
i hope this gets the AutoIt forum started off because it really is a GREAT scripting language!!! 
|