Schreiben der Codes in VB |
|
|
|
Das Programm folgend errechnen das Volumen eines Zylinders:
|
Private Sub OK_Click( )
r = Val(radius.Text)
h = Val(hght.Text)
pi = 22 / 7
v = pi * (r ^ 2) * h
volume.Text= Str$(v)
End Sub
|
|
Note:doubleclick on the O.K button and enter the codes between Private Sub OK_Click( ) and then End Sub
Now we have written the codes for the cylinder program which is given above
I shall attempt to explain the above source program to newcomers in Visual Basic( If you are a veteran, you can skip this part) and let me describe the steps using pseudocodes as follows:
Procedure to calculate the volume of cylinder for clicking the OK button
get the value of r from radius text box
get the value of h from height text box
assign a constant value 22/7 to the pi
calculate the volume using the formula
output the results to Volume text box
End of Procedure
The syntax radius.Text consists of two parts, radius is the name of text box while Text is the textual contents of the text box and generally, the syntax is: Object.Property In our example, the objects are radius, volume and hght, each having text as their property.Object and property is separated by a period(or dot) and thaen the contents of a text box can only be displayed in textual form, or in programming term,as string.You have to use the function Val to convert the contents of a text box to a numeric value so that mathematical operations can be performed. Finally, In order to display the results in a text box, we have to perform the reverse procedure, that is, to convert the numeric value back to textual form, using the function Str$.
I shall also explain the syntax that defines the sub procedure Private Sub OK_click and Private Sub here means that the parameters ,formulas and values that are used here belong only to the OK subprocedure(an object by itself).They cannot be used by other sub modules or procedures. OK_Click defines that what kind of action the subprocedure OK will response.Here, the action is mouse click and there are other kind of actions like keypress, keyup, keydown and etc that I am going to due with in other lessons.
|
|
|
Schl�sselw�rter: Die Codes in VB schreibend, arbeitet grundlegendes sichtlichvb, vb Asp Netz, vb, vb Tutorials, vb Timer, vb Reihe, vb msgbox, das vb, das schwach ist, das byval vb, vb Kontrollen, vb Hinweis, Bezugsschreiben, vb Oberteil, vb Funktion, vb Datum, Schreiben Proben, vb msdn, Schreiben Probe, vb treeview, �berbr�ckercodes, vb Formen, vb API, vb Proben, vb xml, vb Befehl, vb listview, vb Modul
|