I'm having a bit of trouble with calling procedures in my program. Basically, it is a program designed to encode a user inputted message based on a key input and it works perfectly fine when I do not define any functions or procedures and everything is just under the "main" procedure.
However, now that I have defined functions and procedures I am having some trouble calling the procedures from within the "main" procedure. Below is my code:
Dim alphabet As String = "abcdefghijklmnopqrstuvwxyz "
Dim cipherText As String = "abcdefghijklmnopqrstuvwxyz "
Dim charPos As Integer = 0
Dim Cipher As String = ""
Dim Decoded As String = ""
Function userMessage()
'User inputs message
Dim message As String
Console.WriteLine("Please input your message")
message = Console.ReadLine()
Return message
End Function
Function userKey()
'User inputs key
Dim key As Integer
Console.WriteLine("Please enter your key")
key = Console.ReadLine()
Return key
End Function
Sub encodeMessage(ByRef message, ByRef key)
cipherText = cipherText.Substring(key) & cipherText.Substring(0, key) 'Reorder based on key
'Encode message
For i = 0 To message.Length - 1
charPos = alphabet.IndexOf(message(i))
Cipher = Cipher & cipherText(charPos)
Next i
Console.WriteLine(Cipher)
End Sub
Sub decodeMessage(ByRef message, ByRef key)
cipherText = cipherText.Substring(key) & cipherText.Substring(0, key) 'Reorder based on key
'Decode message
For i = 0 To Cipher.Length - 1
charPos = cipherText.IndexOf(Cipher(i))
Decoded = Decoded & alphabet(charPos)
Next i
Console.WriteLine(Decoded)
End Sub
Sub Main()
userMessage()
userKey()
encodeMessage()
decodeMessage()
Console.ReadLine()
End Sub
End Module
The problem I find is in the main
procedure where i try and call the two procedures encodeMessage
and decodeMessage
it is telling me
Argument not specified for parameter message of Public Sub encodeMessage
and it also shows the same error for the key
.
I have tried putting it in there for example encodeMessage(key, message)
and I get an error that says
key and message is not declared.
I will then declare them in the main function such as Sub Main(ByRef key, ByRef message)
however, I then get a different error saying
No accessible 'Main' method with an appropriate signature was found
This is extremely frustrating and I would very much appreciate some help with this (p.s, I am very new to visual basic).
Thanks,