Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,843 members, 7,810,248 topics. Date: Saturday, 27 April 2024 at 02:23 AM

Help Me Cross Check My Visual Basic Code - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Help Me Cross Check My Visual Basic Code (1217 Views)

All You Need To Know About Visual Basic / Is Learning Visual Basic Under Asp.net In 2017, A Waste / Check My App Pin Pals Out (2) (3) (4)

(1) (Reply) (Go Down)

Help Me Cross Check My Visual Basic Code by Thirdwrist(m): 11:33am On Apr 22, 2016
I was asked to do an assignment for someone on Visual basic, I programme only in PHP and Javascript but I thought to myself that it would'nt be hard to learn the syntax of VB, albeit the project was a simply one and knowledge in the previous languages will come in handy.

I was asked to build a programme to find the mean of 5 numbers
And a programme to calculate the volume of a cylinder.

I cant compile this code on visual studio because i dont have that amount of data to download 6gb compiler, so please just help me cross check.



Mean of 5 numbers

Imports System
Public Class Calculatemean
Private val1 As Integer
Private val2 As Integer
Private val3 As Integer
Private val4 As Integer
Private val5 As Integer
Private sum As Integer
Private result As Integer
Private divider As Integer

'Public methods
Public Sub AcceptDetails()
Console.Write("Enter first value: "wink
val1= Console.ReadLine
Console.Write("Enter second value: "wink
val2= Console.ReadLine
Console.Write("Enter third value: "wink
val3= Console.ReadLine
Console.Write("Enter fourth value: "wink
val4= Console.ReadLine
Console.Write("Enter last value: "wink
val5= Console.ReadLine
divider= 5
End Sub

Public Function GetMean() As double
sum = val1 + val2 + val3 + val4 + val5
result = sum / divider
return result
End Function

Public Sub Display()
Console.WriteLine("Mean: {0}", GetMean)
End Sub

Shared Sub Main()
Dim M As New Mean()
M.Acceptdetails()
M.Display()
Console.ReadLine()
End Sub
End Class



Volume of a cylinder

Imports System
Public Class volumeofcylinder
Private radius As Integer
Private hieght As Integer
Private pie As Double
Private radius2 As Integer
Private result As Double

'Public methods
Public Sub AcceptDetails()
Console.Write("Enter Radius: "wink
radius= Console.ReadLine
Console.Write("Enter height: "wink
height= Console.ReadLine
pie= 3.143
End Sub

Public Function GetVolume() As double
radius2= radius * radius
result = pie * radius2 * height
return result
End Function

Public Sub Display()
Console.WriteLine("Volume : {0}", GetVolume)
End Sub

Shared Sub Main()
Dim C As New cylinder()
C.Acceptdetails()
C.Display()
Console.ReadLine()
End Sub
End Class

Re: Help Me Cross Check My Visual Basic Code by megablinks(m): 1:19pm On Apr 22, 2016
Firstly ur variable declarations are somewhat not too good. What if u r given 5 decimal numbers to look for their mean and ur result is returning integer. Same goes for the volume, where height and others can also take on decimal values. And for the vb compiler, u can get it at any software store for #200 or so. Walking with visual studio makes life easier. Hoping to hear from u soon.
Re: Help Me Cross Check My Visual Basic Code by cuvox(m): 9:14pm On Apr 22, 2016
using text boxes

private sub add_click

dim. sum=0, num=0, num2=0, num3=0, num4=.0, num5=0, mean=0 as double

num1=val(Textbox1.Text)
num2=val(Textbox2..Text) etc down to textbox 5

sum= num1 +. num2 etc/5

lblanswer.Text=sum
end sub
Re: Help Me Cross Check My Visual Basic Code by cuvox(m): 9:36pm On Apr 22, 2016
private sub calculate...click

dim num=0, sum=0, mean=0, counter=0 as double

do

num=inputbox.show ("please enter number ")
sum=sum+number

while counter<5

counter+

end do
mean=sum/5
messagebox.show(Null, "mean is" + mean )

end sub

(1) (Reply)

Pyqt4 / Programmers Needed / Nairaland Is Anti-ponzi Scheme, Moderator But Why Are You Allowing Ponzi Here?

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 17
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.