Sie sind auf Seite 1von 28

Ex. No.

4 Desigining a Scientific Calculator Aim: To create a Scientific Calculator using Control Arrays using Visual Basic Environment. Form Design:

Controls Used: Textbox, Command Button Changes in properties: Control Name TextBox Text1 property Text value

TextBox Command Command Command Command Command Command Command Command Command Command Command Command Command Command Command Command Command Command Command Command Command Command Command Command Command Command Command Command Event:

Text2 Text command1 caption,index 0,0 command2 caption,index 1,1 command3 caption,index 2,2 command4 caption,index 3,3 command5 caption,index 4,4 command6 caption,index 5,5 command7 caption,index 6,6 command8 caption,index 7,7 command9 caption,index 8,8 command10 caption,index 9,9 command11 caption,index CE command12 caption,index = command13 caption,index x^2 command14 caption,index x^3 command15 caption,index X^Y command16 caption,index N! command17 caption,index % command18 caption,index OFF command19 caption,index + command20 caption,index SIN command21 caption,index command22 caption,index COS command23 caption,index * command24 caption,index TAN command25 caption,index / command26 caption,index SQRT command27 caption,index 10^X command28 caption,index LOG

Command: Click Variable Used: Gloabal Declaration: Numl,pre,count1, s as long User Defined function: Fact(),Calculate(pre) Procedure: 1. Place the commands and text boxes as shown in the form layout. 2. For creating control array, create a command button named as command then copy the button and then paste it. It will ask a question that you wish to create a control array click on yes, then paste no. of buttons you need. 3. Use the predefined functions sin(), cos(), tan(), sqrt() and log() for the operations sine, cosine, tangent, square root and logarithm. 4. Use the user defined function fact() to calculate the factorial of a number 5. Use the user defined function calculate() to perform all the arithmetic operations depending upon the priority in the variable pre (pre is the operation to be performed after entering the second operand). 6. For each click on the command button with caption 09, display the content in the textbox2 with the corresponding caption value. 7. For each click on operator button, append the contents of textbox2 to the textbox1 with corresponding operator.

8. After entering the second operand store/display the temporary result in text2. Source code: pre var:1-add 2-sub, 3-mul 4-div d-x^y 6-equ 7-mod Dim num1,pre,count As Long Dim s As Long Private Sub Command_Click(Index As Integer) Text1.Text=Val(Text1.Text)*10+Command(Index).Captio n End Sub Private Sub Command11_Click() Text1.Text= Text2.Text= Countl=pre=0 End Sub Private Sub Command12_Click() Text2.Text=Text2.Text+Text1.Text Calc(pre) Text1.Text=numl End Sub Private Sub Command13_Click() Text1.Text=Val(Text1.Text)^2 End Sub

Private Sub Command13_Click() Text1.Text=Val(Text1.Text)^3 End Sub Private Sub Command15_Click() If pre=6 Then Text2.Text= End If Text2.Text=Text2.Text+Text1.Text+^ If countl=0 Then Numl=Val(Text1.Text) Text1.Text= pre=5 countl=1 Else Calc(pre) Text1.Text= Pre=5 End If End Sub Private Sub Command16_Click() Dim a As Integer A=numl Numl=Val(Text1.Text) Fact(numl) Text1.Text=s numl=a End Sub

Private Sub Command17_Click() If pre=6 Then Text2.Text= End If Text2.Text=Text2.Text+Text1.Text+% If co untl=0 Then Numl=Val(Text1.Text) Text1.text= Pre=7 Countl=1 Else Calc(pre) Text1.Text= Pre=7 End If End Sub Private Sub Command18_Click() End End Sub Private Sub Command19_Click() If pre=6 Then Text2.Text= End If Text2.Text=Text2.Text+Text1.Text ++ If countl=0 Then numl=Val(Text1.Text)

Text1.Text= Pre=1 Countl=1 Else Calc(pre) Text1.Text= Pre=1 End If End Sub Private Sub Command20_Click() Deim a As Integer A=numl num1=Val(Text1.Text)*3.14159265358979/180 Text1.Text=Sin(numl) numl=a End Sub Private Sub Command21_Click() If pre=6 Then Text2.Text= End If Text2.Text= Text2.Text+ Text1.Text+- If countl=0 Then numl=Val(Text1.Text) Text1.Text= Pre=2 Countl=1 Else Calc(pre)

Text1.Text= Pre=2 End If End Sub Private Sub Command22_Click()


Dim a As Integer

A=numl numl=Val(Text1.Text)*3.14159265358979/180 Text1.Text=Cos(numl) numl=a End Sub Private Sub Command23_Click() If pre=6 Then Text2.Text= End If Text2.Text=Text2.Text+Text1.Text+* If countl=0 Then num1=Val(Text1.Text) Text1.Text= Pre=3 Countl=l Else Calc(pre) Text1.Text= Pre=3 End If End Sub

Private Sub Command24_Click() Dim a As Integer A=num1 Num1=Val(Text1.Text)*3.14159265358979/180 Text1.Text=Tan(numl) numl=a End Sub Private Sub Co mmand25_Click() If pre=6 Then Text2Text= End If Text2.Text= Text2.Text+ Text1.Text+/ If countl=0 Then Numl=Val(Text1.Text) Text1.Text= Pre=4 countl=1 Else Calc(pre) Text1.Text= Pre=4 End If End Sub Private Sub Command26_Click() Dim a As Interger

A=numl numl=Val(Text1.Text) Text1.Text=Sqr(numl) numl=a End Sub Private Sub Command27_Click() Text1.Text=10^Val(Text1.Text) End Sub Private Sub Command28Click() Dim a As Integer A=numl numl=Val(Text1.Text) Text1.Text=Log(numl) numl=a End Sub Public Function Public Sub calc(pre) Select Case pre Case 1 num1=numl+(Val(Text1.Text) Case 2 num1=numl-(Val(Text1.Text) Case 3 num1=numl*(Val(Text1.Text)

Case 4 If Val(Text1.Text)=0 Then MsgBoxDivide by zero Error num1=0 Else numl=numl/(Val(Text1.Text) End If Case 5 numl=numl^(Val(Text1.Text) Case 6 numl=numl Case 7 numl=numl mod Val(Text1.Text) End Select End Sub Public Sub face(numl) Dim X As Integer S=1 For X=1 To numl S=s*X Next X Numl=s End Sub

Output:

Result: Thus a visual basic program has been written to build a Scientific Calculator is implemented and tested with various samples.

Ex. No. 5 Working with controls- I [Option buttons,Scroll bar,List box] Aim: To write a visual basic program to work with option, scroll and list box controls .

I Usage of Option Buttons form Design:

Controls Used: Label,Textbox, Command Button,Option button, Frame. Change in properties: Control Name property OptionButton Option1 Caption OptionButton Option2 Caption OptionButton Option3 Caption CommandButton Command1 Caption value Hex Decimal Octal Next

Methods & Events: Option value Text Text Command Click Procedure: 1. Place a command button,text box, and three option buttons within a Frame as shown in the form Layout. 2. Using the math functions format(), Hex(), Oct() to convert from one system to another system. 3. By selecting the corresponding option, the respective value should be displayed. II Usage of scroll bar form design:

Controls Used: Label,Textbox, command button, Scroll bar

Changes in properties: Control Name ScrollBar Scroll1 ScrollBar Scroll1 ScrollBar Scroll2 ScrollBar Scroll2 Commandbutton command1

property Min Max Min Max caption

value 1 10 1 96 back

Methods & Events: Scroll: Value Procedure: 1. Place text boxes, horizontal scroll bars, and a command buttons as shown in the form layout. 2. The first scroll bar represents the time periods with range from 1-10, increasing by 1 value per scroll 3. The second scroll bar represents the time period with range from 0.25-24, increasing by 0.25 value per scroll 4. The result should be displayed in the text box for the change in the user values. III Usage of Combo box and List box Form design:

Controls Used: Label, Command Button, List box, combo box Changes in properties: Control Name List Box list1 List Box list2 Commandbutton command1 property value Item Item caption back

Methods and Events: Combo additem, click List change(),text,additem,clear Procedure: 1. Place a Combo box, list box and command button as shown in the form layout. 2. By selecting the combo box, display the corresponding authors or subjects name, in listbox1.

3. By selecting the authors or subjects available in the listbox1, display the corresponding book titles in listbox2. Main Form 1. To select the required control, click the corresponding command button in the main form. Methods and Events Form: load, unload Source code: Main Form: Private Sub Command1_Click() Form1.Show mainfrm.Hide End Sub Private Sub Command2_Click() Form2.Show mainfrm.Hide End Sub Private Sub Command3_Click() Form2.Show mainfrm.Hide End Sub

Private Sub Command4_Click() End End Sub Private Sub Form_Load() Unload Form1 Unload Form2 Unload Form3 End Sub Form1: Dim num 1 As Integer Private Sub Command1_Click() mainfrm.show Unload Form1 End Sub Private Sub Form_Load() Option2.Value-True mainfrm.show End Sub Private Sub Option1_Click() Text1.Text-Hex(numl) End Sub Private Sub Option2_Click() Text1.Text-Format(numl) End Sub

Private Sub Option3_Click() Text1.Text-Oct(numl) End Sub Private Sub Text1_Change() If Option3.Value-True Then num1 Val(&O&L Trim(Text1.Text)&&) Elself Ooption2.Value- True then Num1 Val(L Trim(Trim1.Text)&&) End If End Sub Form 2: Private Sub Command1_Click() mainfrm.show Unload Form2 End Sub Private Sub Form_Load() Label4.Caption-HScroll1.value Label5.Caption-HScroll2.value/4 End Sub Private Sub HScroll1_Change() Label4.Caption-HScroll1.value Text2.Text(Val(Text1.Text)*HScroll.Value*(HScroll2.Value/4))/10 0 End Sub

Private Sub HScroll2_Change() Label5.Caption-HScroll2.Value/4 Text2.Text(Val(Text1.Text)*HScroll.Value*(HScroll2.Value/4))/10 0 End Sub Private Sub Text1_Change() Text2.Text(Val(Text1.Text)*HScroll.Value*(HScroll2.Value/4))/10 0 Form 3: Private Sub Combo1_Click() If Combo1.Text-Book Wise Then List1.Clear List1.AdditemC,0 List1.AdditemC++,1 List1.AdditemJava,2 List1.AdditemOracle,3 List1.AdditemVisual Basic,4 Elself Combo1.Text-Author Wise Then List1.Clear List1.AdditemALL Stevens List1.AdditemDan Applemen

List1.AdditemIvan Bayross List1.AdditemPeter H.Salus List1.AdditemRobert Lafore List1.AdditemSteven Holzner List1.AdditemWayne S Freeze List1.AdditemYashavant Kanetkar End If End Sub Private Sub Command1_Click() mainfrm.show Unload Form3 End Sub Private Sub Form_Load() Combo1.AddItem(Book Wise) Combo1.AddItem(Author Wise) End Sub Private Sub List1_Load() If List1.Text-CThen List2.Clear List2.AdditemC column collection List2.AdditemC pearls List2.AdditemC programming with example

List2.AdditemC projects List2.AdditemData Structures through C List2.AdditemExploring C List2.AdditemGraphics Under C List2.Additemintroduction to object oriented programming & c++ List2.AdditemLet Us C solutions List2.AdditemTest your C skills List2.AdditemUnderstanding pointers in C List2.AdditemWorking with C List2.AdditemWriting TSRs Through C List2.AdditemC with Assembly Language List2.AdditemC Data Base development ElseIf List1.Text-C++Then List2.AdditemC++ Data Base development List2.AdditemTeach yourself If C++ List2.AdditemC Programming Using turbo C++ List2.AdditemC++ Interactive course List2.Additemhandbook of programming languages vol-I: Object-Oriented Languages List2.AdditemVisual c++ 6 in Record Time List2.AdditemMicrosoft Visual C++ 5: No Experience Required List2.AdditemLet Us C++ List2.AdditemC++ Programming with example List2.AdditemTest your C++ Skills List2.AdditemVisual C++ Programming List2.AdditemVisual C+ Projects

ElseIf List1.Text- Java Then List2.Clear List2.AdditemData Structures and algorithm in java List2.AdditemJava workshop programming List2.AdditemMastering visual j++ List2.AdditemVisual j++ 1.1: No experience required ElseIf List1.Text- Oracle Then List2.Clear List2.AdditemCommercial application development using Oracle Developer 2000 List2.Additem Commercial application development using Oracle Developer 2000 forms 5.0 ElseIf List1.Text- Visual BasicThen List2.Clear List2.AdditemDeveloping COM/ActiveX components with Visual Basic 6 List2.Additem Visual Basic 5.0 programmers guide to the win 32 API List2.AdditemAdvanced VB6 projects List2.AdditemVisual Basic projects List2.AdditemVisual Basic Developers Guide to COM and COM+ List2.AdditemExpert Guide to visual basic 6 List2.AdditemVC Gems ElseIf List1.Text-Al Stevens Then List2.Clear List2.AdditemC Date base Development List2.Additemc++ database development

List2.AdditemTeach yourself C++ List2.AdditemTurbo C memory resident utilities, Screen I/O and programming Techniques ElseIf List1.Text Dan Appleman Then List2.Clear List2.AdditemDeveloping COM/ActiveX components with visual basic 6 List2.Additem Visual Basic 5.0 programmers guide to the win 32 API ElseIf List1.Text-Ivan Bayross Then List2.Clear List2.AdditemAdvanced VB6 projects List2.AdditemCommercial application development using Oracle developer 2000 List2.Additem Commercial application development using Oracle developer 2000 forms 5.0 ElseIf List1.Text-Peter H.Salus Then List2.Clear List2.AdditemH P L Vol.III little languages & tools List2.AdditemHandbook of programming languages Vol I: object oriented languages List2.Additem Handbook of programming languages Vol II: Imperative programming languages List2.Additem Handbook of programming languages Vol IV: Functional and logic programming language

ElseIf List1.Text-Robert Lafore Then List2.Clear List2.Additem C programming Using turbo C++ List2.Additem C++ interactive course List2.AdditemData structures and algorithm in java ElseIf List1.Text-Steven Holzner Then List2.Clear List2.Additem Visual Basic projects List2.AdditemJava workshop programming List2.AdditemC with Assembly Language List2.AdditemMastering visual j++ List2.AdditemMicrosoft visual C++ 5: no experience required List2.AdditemVisual C++ in record time List2.AdditemMicrosoft visual J++ 1.1: no experience required ElseIf List1.Text-Wayne S Freeze Then List2.Clear List2.AdditemVisual basic developers guide to COM and COM+ List2.AdditemExpert guide to visual basic6 ElseIf List1.Text-Yashavant kanetkar Then List2.Clear List2.AdditemC column collection List2.AdditemC pearls

List2.AdditemC programming with example List2.AdditemC projects List2.AdditemData Structures through C List2.AdditemExploring C List2.AdditemGraphics Under C List2.Additemintroduction to object oriented programming & c++ List2.AdditemLet Us C solutions List2.AdditemLet Us C++ List2.Additem programming expertise in Basic List2.Additem programming expertise in BASIC List2.AdditemTest your C skills List2.AdditemTest your C++ skills List2.AdditemUnderstanding pointers in C List2.AdditemVC Gems List2.AdditemVisual C+ Programming List2.AdditemVisual C+ Projects List2.AdditemWorking with C List2.AdditemWriting TSRs Through C End If End Sub Output:

Result:

Thus a visual basic program has been written to work with controls is implemented and tested with various samples.

Das könnte Ihnen auch gefallen