473,320 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Visual Basic :: Functions and passing values

I am new to VB. This is my first program so bare with me.

How do I pass a value from the function?

for example, the loop works, but when entering a number between 0 and 100, I can't get the function to pass the value back. I want the exam1 grade to be worth 10% - so exam1 * 0.1. It needs to be between 0 and 100. I can pass the entered score to the function, get the "error message back" enter a good number, and move on. Once the function is complete, exam1 is eqaul to 0 and not the good value entered. After the function, I want the good number to store into exam1 so I can multiply it by 0.1.


Expand|Select|Wrap|Line Numbers
  1.  Console.Write("Enter grade of Exam 1 : ") 
  2. exam1 = Console.ReadLine()
  3. exam1 = checkGrade(exam1)
  4. 'Exam 1 is worth 10% of the total grade.
  5.  
  6. Function checkGrade(ByVal check As Double) As Double
  7. If check < 0 Or check > 100 Then
  8. Console.Write("****Please enter a grade between 0 and 100: ")
  9. check = Console.ReadLine()
  10. check = checkGrade(check)
  11. Else
  12. 'Console.Write("check= " & check)
  13. Return check
  14. End If
  15. End Function
  16.  
Feb 4 '06 #1
3 12452
Expand|Select|Wrap|Line Numbers
  1.  Function checkGrade(ByVal check As Double) As Double 
  2. If check < 0 Or check > 101 Then
  3. Console.Write("****Please enter a grade between 0 and 100: ")
  4. check = Console.ReadLine()
  5. If check > 0 Or check < 101 Then
  6. Return check
  7. End If
  8. 'check = checkGrade(check)
  9. ElseIf check > 0 Or check < 101 Then
  10. Return check
  11. End If
  12. End Function
  13.  
Feb 4 '06 #2
Niheel
2,460 Expert Mod 2GB
Thanks for posting the fix!

:-)
Feb 4 '06 #3
dwadish
129 100+
Thanx for posting

i got the idea
Dec 4 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft...
26
by: Dave Hammond | last post by:
In document "A.html" I have defined a function and within the document body have included an IFRAME element who's source is document "B.html". In document "B.html" I am trying to call the function...
10
by: Boobie | last post by:
var myString = new String("Hello world") ; var myString = "Hello world" ; There is NO difference between the two right ? both creates a String obj right ?
3
by: rgb | last post by:
I've got Visual Studio 6.0 and I'm working on a Visual Basic applicaiton. There a couple parts that really require C. I've done C programming on a mainframe but nothing on a PC. So I'm trying to...
16
by: G Patel | last post by:
Hi, If I want to call functions that don't return int without declaring them, will there be any harm? I only want to assign the function(return value) to the type that it returns, so I don't...
2
by: Joel Vazquez | last post by:
Visual Basic.NET Application RunTime Crashes and Stalls Im a newbie if you could say in .NET ive been working with it the past 3 months and have done lots of things with it, without any prior...
4
by: LCAdeveloper | last post by:
I have had to move to Visual Studio.NET Pro. from Visual Basic 4.0 and am now starting to re-write our code. I was a bit surprised to find that Visual Basic.NET no longer supports fixed length...
14
by: Kejpa | last post by:
Hi, I have a function Sum as.... Function Sum(ByVal ParamArray Values() As Double) As Double Dim rSum, itm As Double For Each itm In Values rSum += itm Next Return rSum End Function
10
by: Steve | last post by:
I am trying to create a DLL in Visual Studio 2005-Visual Basic that contains custom functions. I believe I need to use COM interop to allow VBA code in Excel 2002 to access it. I've studied...
0
jwwicks
by: jwwicks | last post by:
Introduction This tutorial describes how to use Visual Studio to create a new C++ program, compile/run a program, resume work on an existing program and debug a program. It is aimed at the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.