Walk Lightly on this PLANET and yet leave such a FOOTPRINT that cannot be erased for thousands of Years..!!!
Visit Codstech for Cyber Security related Posts !

Visitors

Wednesday, July 20, 2011

VB-51 : Conversion of Temperature

Write an event procedure to convert the Fahrenheit temperature to Centigrade. Use a Horizontal scroll bar to select the Fahrenheit temperature.
Celsius=(Fahrenheit-32)*0.555
Refer Temperature Conversion also.
A)    Program Design : 


(B) Property(Controls Used) :
  • 4 Labels Captions as :  Fahrenheit(Name Label1), Celcius(Name Label2), 0(Name lbl_cel), 0(Name lbl_Fah) brespectively. 
  • HorizontalScrollBar : Min-0,Max100,Large Change 5 , Name-Hscr_fah
(C) Attaching Code to the Object :

Private Sub Form_Load()
Hscr_Fah_Change
End Sub

Private Sub HScr_Fah_Change()
 lbl_Fah.Caption = Hscr_Fah.Value
 lbl_Cel.Caption = (Hscr_Fah - 32) * 0.555
 End Sub



(C) Result :
Moving the ScrollBar will show the temperature in both degrees (from 0-100)

==================================================================
=========================================================






VB-50 : Displaying State if the city is given

==================================================================================

Before going to do any Database Program ,Click here to  understand Database Concepts thoroughly.


==================================================================================

Create a table called "Area Code" using the Visual Data Manager with the following fields:
  • Area Name
  • City
  • State
  • Pin Code.
Write a program using Data Control to display the state if the city is given.And also to display the Area name if the Pin code is given.
==========================

A)    Program Design : 

  • We need to design a Database for this program.
Refer Linking to Database to create a table in Access. The created table (say,emp2) with the fields as per the question  is given below :

(Here,db1 is the DataBase name, and emp2 is the Table name given)  :



Field Name


Description

Data Type
Area
Area Code
Text
City
City
Text
Pin
Pin Code
Number
State
State
Text


(B) Property(Controls Used) :
  • 5 Labels
  • 4 Text Boxes : Visible Property-False, Index Property from 0 to 3
  • One Data Control (Database name db1 and RecordSource emp2)
  • 4 Command Buttons with Captions : Main Menu (name:cmd_back,Visible Property-True), Data Transaction(name:command-1) , Search(name:command-2) and Find(name:command-3). Also,(Set the Visible Property as False for this 3 command Buttons)
When we set some properties of the controls as True or False, the form will appear while running....as,


(C) Attaching Code to the Object :

Private Sub setVisible(flag As Boolean)
Data1.Visible = False
For Each i In frmemp_data.Controls
If i.Name = "label1" Then
i.Visible = flag
ElseIf TypeOf i Is TextBox Then
i.Visible = flag
End If
Next i
End Sub


Private Sub setcontrol(flag As Boolean)
Command1.Visible = flag
Command2.Visible = flag
cmd_back.Visible = Not flag
End Sub



Private Sub setbound(flag As Boolean, Optional src As String)
For Each i In frmemp_data.Controls
If TypeOf i Is TextBox Then
If flag = True Then
i.DataSource = src
ElseIf Not IsNull(i.DataSource) Then
Set .i.DataSource = ""
End If
End If
Next i
End Sub


Private Sub cmd_back_click()
setbound (False)
setVisible (False)
setcontrol (True)
Command3.Visible = False
End Sub

Private Sub Command1_Click()
Data1.EOFAction = 2
setbound True, "Data1"
setVisible (True)
setcontrol (False)
End Sub

Private Sub Command2_Click()
Dim str As String
setVisible (True)
Data1.Visible = False
setcontrol (False)
setbound False
For Each i In frmemp_data.Controls
If TypeOf i Is TextBox Then
i.Text = ""
End If
Next i
End Sub

Private Sub Command3_Click()
Dim str As String
If Text2.Text <> "" Then
str = " city=" & Text1.Text & ""
Data1.Recordset.FindFirst
Data1.Recordset.FindFirst str
If Data1.Recordset.EOF Then
MsgBox "Such City Not Found"
Exit Sub
Else
If Text3.Text <> "" Then
str = str & "and pin=" & Text1.Text & ""
Data1.Recordset.FindFirst
Data1.Recordset.FindFirst str
If Not Data1.Recordset.EOF Then
Text1.Text = Data1.Recordset.Fields("area").Value
End If
Text4.Text = Data1.Recordset.Fields("state").Value
End If
End If
End Sub


====================================================================
=========================================================