PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
VS 2017 Functions and Procedures-VBForums
Results 1 to 9 of 9

Thread: Functions and Procedures

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2019
    Posts
    6

    Functions and Procedures

    I'm a student currently learning VB.Net. Our professor has a lab assignment where he wants us to create functions that we pass into a procedure. I'm not really getting a grasp on the assignment. There's five tasks he wants us to complete.

    First, he wants us to ask the user for a string, determine if the string length is between 26 and 32. That part I got figured out.
    The next part of that task is he wants us to find out the length of the string without using built-in functions like .Length or .GetLength. He gave a hint about passing it into a charArray.

    Second, He wants us to carry the string to another function that checks if the string contains at least one of each Vowel. Give a Boolean True or False

    Third, He wants us to carry the sting to another function that checks if every letter of the alphabet is used in the string. Give a Boolean True or False

    Fourth, He wants us to carry the string to another function that checks if there are any special characters in the string. Give a Boolean True or False

    Lastly, he wants us to pass the string to a procedure he listed as
    ComboCheck ( ByVal stringName as String, ByRef VowelCheck as Byte, ByRef PangramCheck as Byte, PasswordCheck as Byte )



    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.

    I just need to be pointed in the right direction. I know I'm doing something wrong creating these functions and trying to connect to the inputted string. I just don't know what it is. If someone could give me a hint or point me in the right direction it'd be really helpful. My code so far is as follows:

    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

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,676

    Re: Functions and Procedures

    Please don't post unformatted code snippets. They are unpleasant to read.
    vb.net Code:
    1. ComboCheck  (  ByVal  stringName as String,  ByRef VowelCheck as Byte,  ByRef PangramCheck as Byte,  PasswordCheck as Byte )
    vb.net Code:
    1. Module Module1
    2.  
    3.     Sub StringName(ByRef input As String)
    4.         Dim charArray() As Char = {input}
    5.         Dim counter As Integer = 0
    6.         For Each element In charArray
    7.             counter += 1
    8.         Next
    9.  
    10.         Console.WriteLine("String length is: " & counter)
    11.  
    12.     End Sub
    13.     Sub IsItVowelGram(ByRef StringName As String)
    14.  
    15.  
    16.  
    17.  
    18.     End Sub
    19.     Sub Pangram(ByRef StringName As String)
    20.  
    21.     End Sub
    22.     Sub PassWordCheck(ByRef StringName As String)
    23.  
    24.     End Sub
    25.     Sub Main()
    26.         Dim input As String
    27.         Console.WriteLine("Please Enter a String")
    28.         input = Console.ReadLine()
    29.         If input.Length >= 26 And input.Length <= 32 Then
    30.             Console.WriteLine("Correct input of String")
    31.         Else
    32.             Do
    33.                 Console.WriteLine("Please enter a string")
    34.                 input = Console.ReadLine()
    35.             Loop Until input.Length >= 26 And input.Length <= 32
    36.  
    37.  
    38.  
    39.         End If
    40.  
    41.  
    42.     End Sub
    43.  
    44.     Sub ComboCheck(ByRef StringName As String, ByRef VowelCheck As Byte, ByRef PangramCheck As Byte, PasswordCheck As Byte)
    45.  
    46.     End Sub
    47. End Module

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,676

    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.

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2019
    Posts
    6

    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 ]

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,119

    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

  6. #6
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,676

    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.

  7. #7

    Thread Starter
    New Member
    Join Date
    Nov 2019
    Posts
    6

    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?

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,119

    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))

  9. #9
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,676

    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width