Re: Functions and Procedures
Please don't post unformatted code snippets. They are unpleasant to read.
vb.net Code:
ComboCheck ( ByVal stringName as String, ByRef VowelCheck as Byte, ByRef PangramCheck as Byte, PasswordCheck as Byte )
vb.net Code:
Module Module1
Sub StringName(ByRef input As String)
Dim charArray() As Char = {input}
Dim counter As Integer = 0
For Each element In charArray
counter += 1
Next
Console.WriteLine("String length is: " & counter)
End Sub
Sub IsItVowelGram(ByRef StringName As String)
End Sub
Sub Pangram(ByRef StringName As String)
End Sub
Sub PassWordCheck(ByRef StringName As String)
End Sub
Sub Main()
Dim input As String
Console.WriteLine("Please Enter a String")
input = Console.ReadLine()
If input.Length >= 26 And input.Length <= 32 Then
Console.WriteLine("Correct input of String")
Else
Do
Console.WriteLine("Please enter a string")
input = Console.ReadLine()
Loop Until input.Length >= 26 And input.Length <= 32
End If
End Sub
Sub ComboCheck(ByRef StringName As String, ByRef VowelCheck As Byte, ByRef PangramCheck As Byte, PasswordCheck As Byte)
End Sub
End Module
Re: Functions and Procedures
Your interpretation sounds rather nonsensical, so it seems clear that you are misunderstanding what you're being asked to do. I thought I could guess what you actually needed to do but none of my guess really match all of the information provide. While I never recopmmend this as a first option, I would suggest that you post the text of the assignment and we can try to explain what you actually need to do in terms you can understand.
Re: Functions and Procedures
Here is the original assignment. I probably said the wrong term for the wrong thing. Shows how little I've learned.
Task 1. Ask the user to enter a string.
Make sure the size is at least 26 characters and less than 32 characters. Otherwise, loopback and keep asking him to enter a string.
You should write a function to calculate the length of the string , that function should return the length of the string. You should not use any built-in functions such as Getlength or Length functions. It should be custom function. [ 5 points ]
HINT: Try to convert the string to char array and use for each in the char array
Task 2: Pass the string to another function, call it IsItVowelGram ( stringName)
This function should check if all Vowels occur in the string. In our case, AEIOU is the set of vowels. We ignore upper and lower cases. If all vowels are present, this function should return Boolean True or False [ 10 points ]
Task 3. Pass the string to another function , call it Pangram ( stringName).
This function should check if all letters in our English alphabets occur. In our case A-Z. We ignore upper and lower cases. if all letters are present, this function should return Boolean True or False [ 10 points ]
Task 4: Pass the string to another function, call it PassWordCheck ( stringName)
This function should check if at least one Upper case letter A-Z, one Lower case [a - z] , at least one digit [0 -9 ] and at least one symbol [ "(", ")", "+" ] occur in the string.
if all requirements are satisfied, this function should return Boolean True or False
[10 points ]
Task 5: Passs the string to another procedure ,
The purpose of this ComboCheck is : it will call Pangram , IsItVowelGram and PassWordCheck. It will get the results as boolean but return back the values as Byte . I have given the sample code for you right here.
ComboCheck ( ByVal stringName as String, ByRef VowelCheck as Byte, ByRef PangramCheck as Byte, PasswordCheck as Byte )
{
' SAMPLE CODE.
dim p1 as boolean = Pangram ( stringName);
if p1 = true then
PangramCheck = 1
else
PangramCheck = 0
p1 = IsItVowelGram ( stringName)
if p1 = true then
VowelCheck = 1
else
VowelCheck = 0
p1 = IsItVowelGram ( stringName)
if p1 = true then
PasswordCheck = 1
else
PasswordCheck = 0
}
You can call the functions you wrote in Task 2, Task3 and Task4 from ComboCheck. The booleans returned from those functions can be returned via ByRef in Task 5.
main ( )
combocheck ( pass parameters )
end main
[ 10 points ]
Re: Functions and Procedures
You should be using Functions, not Sub procedures...
Code:
Function StringLength(ByRef input As String) as boolean
'count chars, then...
return counter >= 26 and counter <= 32
End Function
Function IsItVowelGram(ByRef yourString As String) as boolean
Dim vowels() as String = New String() {"a", "e", "i", "o", "u"}
dim containsAll as Boolean = True
For Each l as String in vowels
If Not yourString.ToLower.Contains(l) then containsAll = False: Exit For
Next
return containsAll
End Function
Re: Functions and Procedures
OK then, it appears that what I suspected actually is the case. It's not that you're passing functions into a procedure. It is that the procedure is calling the functions. The idea is that you write three separate functions that each perform a particular task and return a value, then you write a procedure that calls those three functions and outputs the return values via parameters. You've even been given code for that procedure that does just that.
As should always be the case, break the problem into parts and work on each part independently. That's already partly done for you and you still ignored it. You should not be thinking about anything beyond task 1 until you have task 1 working. If you have an issue getting task 1 working, you ask about that issue specifically, with no reference to anything outside of task 1. I would start by writing a method that DOES use the String.Length property for simplicity and then make sure I could use that method as described, i.e. prompt for input, text the length and prompt again if it's not valid. There's no point trying to write a fancy way to calculate the length if you can't even use it when you've got it. so do that part first. Once you can loop until the input is a valid length, then you can think about writing code to actually calculate that length without using Length or GetLength. Once that's done, you can move onto the next method. Etc. If you're worrying about ComboCheck before you can even calculate the length of the input, you're just making your job harder.
Re: Functions and Procedures
I wasn't trying to calculate the ComboCheck first. I was trying to come up with the individual functions first but I don't know how to see if they're working as they don't appear in my console window when I run the program. This is an online course so it's hard for me to get help from the professor. I think I have most of the functions figured out, but I don't know how to see if they're actually doing anything. Am I supposed to put them inside the Sub Main() and do a Console.WriteLine?
Re: Functions and Procedures
The actual location of the functions is after the sub main. In sub main you can call them...
Code:
Dim yourString as String = “The quick brown fox jumps over the lazy dog”
Console.WriteLine(isItVowelGram(yourString))
Re: Functions and Procedures
The first step would be to learn the difference between a function and a procedure. When you declare a method, the Sub keyword (short for "subroutine") indicates a procedure and the Function keyword indicates a function. The former performs an action while the latter performs an action AND returns a value. I imagine that you would have been provided with that information somewhere in your course material. Once you have actually written a function, you can see whether it's working by calling it and then displaying the value it returns. Even without that though, you can still see whether code is working or not by using the debugger built into VS. That's what it's for. You can set a breakpoint, step through the code and examine the state (values of variables, etc) at each step. If you have written the code then you should know what each line is supposed to do and you can use the debugger to see whether it actually does it.