Wednesday, January 25, 2012

Simultaneous Equations Solver

How to design a program that can solve mixed simultaneous equations, that is , one linear equation and one quadratic equation. Here is the program:

Private Sub Command1_Click()
Dim a, b, c, d, m, n As Integer
Dim x1, x2, y1, y2 As Double
a = Val(Txt_a.Text)
b = Val(Txt_b.Text)
m = Val(Txt_m.Text)
c = Val(Txt_c.Text)
d = Val(Txt_d.Text)
n = Val(Txt_n.Text)
x1 = (m * a * d + Sqr(m ^ 2 * a ^ 2 * d ^ 2 - (b ^ 2 * c + a ^ 2 * d) * (d * m ^ 2 - b ^ 2 * n))) / (b ^ 2 * c + a ^ 2 * d)
x2 = (m * a * d - Sqr(m ^ 2 * a ^ 2 * d ^ 2 - (b ^ 2 * c + a ^ 2 * d) * (d * m ^ 2 - b ^ 2 * n))) / (b ^ 2 * c + a ^ 2 * d)
y1 = (m - a * x1) / b
y2 = (m - a * x2) / b
Lbl_x1.Caption = Round(x1, 2)
Lbl_y1.Caption = Round(y1, 2)
Lbl_x2.Caption = Round(x2, 2)
Lbl_y2.Caption = Round(y2, 2)
End Sub
===========================================================
 
Explanation:
Mixed simultaneous equations take the following forms:
ax+by=m
cx2+dy2=n
Simultaneous equations can normally be solved by the substitution or elimination methods. In this program, I employed the substitution method. So, I obtained the following formulae:
x1 = (m a d + Sqr(m 2 a 2 d 2 - (b 2 c + a 2 d) (d m 2 - b 2 n))) / (b 2 c + a 2 d)
x2 = (m a d +-Sqr(m 2 a 2 d 2 - (b 2 c + a 2 d) (d m 2 - b 2 n))) / (b 2 c + a 2 d)
y1 = (m - a x1) / b
y2 = (m - a x2) / b
To limit the answers to two decimal places, I used the round function.

Cubic Function Graph Plotter

This is a program that enables the user  to input the coefficients of a cubic function and draw its graph. The cubic function takes the form  f(x)=ax3+bx2+cx+d

The Code

Private Sub cmd_draw_Click()
Dim a, b, c, d As Integer
Dim w, v As Double
a = Val(txt_a.Text)
b = Val(txt_b.Text)
c = Val(txt_c.Text)
d = Val(txt_d.Text)
'Using a scale of 0.5 cm to represent i unit to draw the graph
' Need to make some transformation as the coordinates in VB start from top left

For w = 0 To 10 Step 0.001
v = a * (5 - w) ^ 3 + b * (5 - w) ^ 2 + c * (5 - w) + d
pic_graph.PSet (w, 5 - v)
Next w
End Sub

Wednesday, January 11, 2012

INTERNET BROWSER IN VB

Its very simple to make a web browser in vb.Just take four command buttons -GO,BACK,FORWARD & REFRESH.after this ,press ctrl+T. now select internet controls and then clickAPPLY.
Now u will find a small globe in ur toolbox.Double-click on it and a white box will appear .
Adjust it according ot ur form.

Now u r ready for the CODE-
Private Sub cmdgo_Click()
WebBrowser1.Navigate (Text1.Text)
End Sub
Private Sub cmdback_Click()
WebBrowser1.GoBack
End Sub
Private Sub Cmdforward_Click()
WebBrowser1.GoForward
End Sub
Private Sub cmdrefresh_Click()
WebBrowser1.Refresh
End Sub

Private Sub Form_Load()
WebBrowser1.Navigate ("http://www.google.com")
End Sub
Private Sub WebBrowser1_StatusTextChange(ByVal Text As String)
Text1.Text = (WebBrowser1.LocationURL)
Form1.Caption = (WebBrowser1.LocationName)
End Sub


Friday, December 23, 2011

Boggle

This is a type of words puzzle game where players can form as many words as possible from the characters displayed on a nxn square. Words can be formed in many ways, from left to right, from right to left, top to bottom, bottom to top, diagonal, zigzag manner and etc. You can actually play boggle online.
n this programme, I have designed a 5x5 boggle. Each time a player press the shake button, a different set of characters will appear. In order to do this, I use the randomize concept. This programme generates an array of 26 characters and displays them on an array of 24 labels by using  a For...Next loop . The procedure may look simple but it need a lot of thinking before we come out with the idea.

The Code

Dim char(25) As String

Dim I As Integer
Dim J As Integer

Private Sub Command1_Click()
char(0) = "A"
char(1) = "B"
char(2) = "C"
char(3) = "D"
char(4) = "E"
char(5) = "E"
char(6) = "G"
char(7) = "H"
char(8) = "I"
char(9) = "J"
char(10) = "K"
char(11) = "L"
char(12) = "M"
char(13) = "N"
char(14) = "O"
char(15) = "P"
char(16) = "Q"
char(17) = "R"
char(18) = "S"
char(19) = "T"
char(20) = "U"
char(21) = "V"
char(22) = "W"
char(23) = "X"
char(24) = "Y"
char(25) = "Z"

Randomize Timer
For I = 0 To 24
J = Int((Rnd * 26))
Label1(I).Caption = char(J)
Next

End Sub

Thursday, December 22, 2011

VB.NET Developers Guide.

BMI Calculator

A lot of people are obese now and it could affect their health seriously . If your BMI is more than 30, you are considered obese. You can refer to the following range of BMI values for your weight status.
  • Underweight = <18.5
  • Normal weight = 18.5-24.9
  • Overweight = 25-29.9
  • Obesity = BMI of 30 or greater
This BMI calculator is a Visual Basic program that can calculate the body mass index, or BMI of a person based  on the body weight in kilogram and the body height in meter. BMI can be calculated using the formula    weight/( height )2, where weight is measured in kg and height in meter. If you only know your weight and height in lb and feet, then you need to convert them to the metric system. 


The Code
Private Sub Command1_Click()
    Label4.Caption = BMI(Text1.Text, Text2.Text)
End Sub
Private Function BMI(height, weight)
      BMIValue = (weight) / (height ^ 2)
      BMI = Format(BMIValue, "0.00")
End Function

Graphical VB Polling System

Survey and polling tools are often used in marketing or politics to assess rating for certain services or products. Polling tools can take many forms, some just use a simple dichotomous scale of Yes and No, or Likert Scale that consists of three or more choices. You can create Polling tool in Visual Basic easily by using the option buttons. In my program, I give the users five choices, Excellent, Very Good, Good, Satisfactory and Bad.The results are presented in frequency and percentage respectively.
 
In the example on the right, I have included graphical display of the percentages of the five scores using the Line method. The general format to draw the rectangular bar in a picture box is
Picture1.Line (x1, y1)-(x2, y2), color, BF
where (x1,y1) is the coordinates of the upper left corner of the bar and
(x2,y2) is the coordinates of the lower right corner of the bar.
To show the bar length according to the percentage, I used certain value to multiply the decimal value of each score and put it under x2.
Finally, I used the Picture1.Cls method to clear the picture box in order to refresh the drawing.
 
The Code
Dim total, Excel_total, VG_total, G_total, Sat_total, Bad_total As Integer
Dim Excel_percent, VG_percent, G_percent, Sat_percent, Bad_percent As Single
Dim done As Boolean

Private Sub cmd_Vote_Click()
Picture1.Cls

If Option_Excel.Value = True Then
Excel_total = Excel_total + 1
Lbl_ExcelTotal = Excel_total
ElseIf Option_VG.Value = True Then
VG_total = VG_total + 1
Lbl_VGTotal = VG_total
ElseIf Option_G.Value = True Then
G_total = G_total + 1
Lbl_GTotal = G_total
ElseIf Option_Sat.Value = True Then
Sat_total = Sat_total + 1
Lbl_SatTotal = Sat_total
ElseIf Option_Bad.Value = True Then
Bad_total = Bad_total + 1
Lbl_BadTotal = Bad_total
End If
total = Excel_total + VG_total + G_total + Sat_total + Bad_total

Lbl_Total = total

Excel_percent = Excel_total / total
VG_percent = VG_total / total
G_percent = G_total / total
Sat_percent = Sat_total / total
Bad_percent = Bad_total / total
Lbl_Excel.Caption = Format(Excel_percent, "Percent")
Lbl_VG.Caption = Format(VG_percent, "Percent")
Lbl_G.Caption = Format(G_percent, "Percent")
Lbl_Sat.Caption = Format(Sat_percent, "Percent")
Lbl_Bad.Caption = Format(Bad_percent, "Percent")
Picture1.Line (100, 750)-(3800 * Excel_percent, 950), vbRed, BF
Picture1.Line (100, 1450)-(3800 * VG_percent, 1650), vbMagenta, BF
Picture1.Line (100, 2150)-(3800 * G_percent, 2350), vbGreen, BF
Picture1.Line (100, 2850)-(3800 * Sat_percent, 3050), vbBlue, BF
Picture1.Line (100, 3550)-(3800 * Bad_percent, 3750), vbYellow, BF

End Sub

Wednesday, December 21, 2011

FTP Program

Visual Basic allows you to build a fully functionally FTP program which may be just as good as the commercial FTP programs. The engine behind it is the Microsoft Internet Transfer Control 6.0 in which you need to insert your form before you can create the FTP program. The name of the Microsoft Internet Transfer Control 6.0.is Inet and if you only put in one control, its name will be Inet1.
 
Inet1 comprises three important properties namely Inet1.URL that is used to identify the FTP hostname, inet1.UserName that is used to accept the username and the Inet1.Password that is used to accept the user’s passwords.  The statements for the program to read the hostname of the server, the username and the password entered into Textbox1, Textbox2 and Textbox3 by the user are shown below:
Inet1.URL=Text1.Text
Inet1.UserName=Text2.Text
Inet1.Passoword=Text3.Text
 After the user entered the above information, the program will attempt to connect to the server using the following command, where Execute is the method and DIR is the FTP command that will read the list of files from the specified directory of the remote computer and you need to use the getChunk method to actually retrieve the directory’s information.
  Inet1.Execute, "DIR" 
After connecting to the server, you can choose the file from the remote computer to download by using the statement below:
Inet1.Execute, , "get" & remotefile & localfile 
where remotefile is the file of the remote site and localfile is the file of the local system. However, very often you need to provide the full path of the local file, which you can do that by modifying the above syntax to the following syntax: 
Inet1.Execute , , "get" & remotefile & localpath & remotefile 
The above statements will ensure that the remote file will be downloaded to the location specified by the localpath and the file downloaded will assume the same name as the remote file. For example, the remote file is readme.txt and the localpath is C:\temp , so the downloaded file will be saved in  C:\temp\readme.txt.

Digital Stopwatch

In this program, you need to insert one label, three command buttons and two timers. The interval of timer1 which is used for the stopwatch and you have to set the interval to 1. Timer2 will be used to display the clock and the interval will be set to 1000(or 1 second). I used 6 string variables to display the digits of the stopwatch so that I can put in the colons ":" and the decimal point. I also created a subroutine known as countime  The codes are shown below:


The code
Dim a As String
Dim b As String
Dim c As String
Dim x As String
Dim y As String
Dim z As String
Dim h As String
Dim m As String
Dim s As String
Dim u As String
Dim v As String
Public interval As Double



Private Sub clock_Click()
Timer1.Enabled = False
Timer2.Enabled = True
End Sub

Private Sub Command1_Click()

Timer1.Enabled = True
Timer1.interval = 1




End Sub

Private Sub Command2_Click()
Timer1.Enabled = False
End Sub

Private Sub Command3_Click()
Timer1.Enabled = False
a = "0"
b = "0"
c = "0"
x = "0"
y = "0"
z = "0"
u = "0"
v = "0"

h = a + b
m = c + x
s = y + z
'To set the display as "00:00:00.00"
Label1.Caption = h + ":" + m + ":" + s + "." + u + v
End Sub

Sub counttime()
If Val(v) < 9 Then
v = v + 1

Label1.Caption = a + b + ":" + c + x + ":" + y + z + "." + u + v
ElseIf Val(u) < 9 Then
v = 0
u = u + 1

Label1.Caption = a + b + ":" + c + x + ":" + y + z + "." + u + v
ElseIf Val(z) < 9 Then
v = 0
u = 0

z = z + 1

Label1.Caption = a + b + ":" + c + x + ":" + y + z + "." + u + v
ElseIf Val(y) < 5 Then
v = 0
u = 0
z = 0
y = y + 1
Label1.Caption = a + b + ":" + c + x + ":" + y + z + "." + u + v
ElseIf Val(x) < 9 Then
v = 0
u = 0
z = 0
y = 0
x = x + 1
Label1.Caption = a + b + ":" + c + x + ":" + y + z + "." + u + v
ElseIf Val(c) < 5 Then
v = 0
u = 0
z = 0
y = 0
x = 0
c = c + 1
Label1.Caption = a + b + ":" + c + x + ":" + y + z + "." + u + v
ElseIf Val(b) < 9 Then
v = 0
u = 0
z = 0
y = 0
x = 0
c = 0
b = b + 1
Label1.Caption = a + b + ":" + c + x + ":" + y + z + "." + u + v
ElseIf Val(b) < 9 Then
v = 0
u = 0
z = 0
y = 0
x = 0
c = 0
b = b + 1
Label1.Caption = a + b + ":" + c + x + ":" + y + z + "." + u + v
ElseIf Val(a) < 9 Then
v = 0
u = 0
z = 0
y = 0
x = 0
c = 0
b = 0
a = a + 1
Label1.Caption = a + b + ":" + c + x + ":" + y + z + "." + u + v

End If

End Sub

Private Sub dat_Click()
Label1.Caption = Date
Timer2.Enabled = False
End Sub

Private Sub Form_Load()
a = "0"
b = "0"
c = "0"
x = "0"
y = "0"
z = "0"
u = 0
v = 0
h = a + b
m = c + x
s = y + z
'To set the display as "00:00:00.00"
Label1.Caption = h + ":" + m + ":" + s + "." + u + v

End Sub

Private Sub stopwc_Click()
Timer2.Enabled = False
a = "0"
b = "0"
c = "0"
x = "0"
y = "0"
z = "0"
u = "0"
v = "0"

h = a + b
m = c + x
s = y + z
Label1.Caption = h + ":" + m + ":" + s + "." + u + v

End Sub

Private Sub Timer1_Timer()
counttime

End Sub

Private Sub Timer2_Timer()
Label1.Caption = Time
End Sub

Future Value Calculator

This program involves the use of the formula 
where  PV represents the present value, FV represents the future value , i is the interest rate and n is the number of periods (Normally months or years). I created a function which have two parameters, namely i and n. Then I wrote the procedure to call this function.
 Public Function FV(PV As Variant, i As Variant, n As Variant) As Variant
'Formula to calculate Future Value(FV)
'PV denotes Present Value
FV = PV * (1 + i / 100) ^ n

End Function

Private Sub compute_Click()
'This procedure will calculate Future Value
Dim FutureVal As Currency
Dim PresentVal As Currency
Dim interest As Variant
Dim period As Variant
PresentVal = PV.Text

interest = rate.Text
period = years.Text

FutureVal = FV(PresentVal, interest, period)
Label5.Caption = Format(FutureVal, "currency")
End Sub

Private Sub period_Change()

End Sub