Syntax error End Sub

I am working on creating a code generator for registration users now I have finished my app, and I found a really good code for this, however, I get the error on the End Sub probably because of the copy/paste I do. I pasted it in the Pressed Event of a button where the code should be generated. The advice I read is that you should not use the Sub and End sub lines in the code, but without it the code give errors. Any adivce?

This is the code:

Preformatted text``Preformatted texttextUserName.Enabled = True
btnCreateRegCode.Enabled = False

txtRegLName.Text = “”
txtRegFName.Text = “”
txtOrderNr.Text = “”
txtRegEmail.Text = “”

txtRegFName.SetFocus

// Import the Crypto module
Import Crypto

// Define a constant salt value
Const salt As String = “XojoRocks”

// Define the btnCreateRegCode.Pressed event handler
Sub Pressed() Handles Pressed ’ Add this line to name the event handler

// Get the user input from the text fields
Var firstName As String = txtRegFName.Text
Var lastName As String = txtRegLName.Text
Var email As String = txtRegEmail.Text

// Add salt to the user input
Var firstNameSalted As String = firstName + salt
Var lastNameSalted As String = lastName + salt
Var emailSalted As String = email + salt

// Convert the user input to MemoryBlocks
Var firstNameMB As MemoryBlock = firstNameSalted.ToText.ConvertToData(TextEncoding.UTF8)
Var lastNameMB As MemoryBlock = lastNameSalted.ToText.ConvertToData(TextEncoding.UTF8)
Var emailMB As MemoryBlock = emailSalted.ToText.ConvertToData(TextEncoding.UTF8)

// Compute the SHA1 hashes of the MemoryBlocks
Var firstNameHashMB As MemoryBlock = Crypto.SHA1(firstNameMB)
Var lastNameHashMB As MemoryBlock = Crypto.SHA1(lastNameMB)
Var emailHashMB As MemoryBlock = Crypto.SHA1(emailMB)

// Convert the hashes to hexadecimal strings
Var firstNameHash As String = firstNameHashMB.ToHex
Var lastNameHash As String = lastNameHashMB.ToHex
Var emailHash As String = emailHashMB.ToHex

// Combine the hashes to create a registration key
Var regKey As String = firstNameHash + lastNameHash + emailHash

// Display the registration key in the text field
txtRegCode.Text = regKey
End Sub ’ Add this line to close the event handler block

Your code should not contain Sub or End Sub statements.

If removing these cause an error then there is another problem elsewhere.

When you create a method in the IDE (without a return type) the Sub and End Sub parts are automatically generated for you. If you paste one in you are effectively ending up with two of them.

Removing those lines give me a Syntax Error on the Window itself:WinReg.Name

Syntax error
WinReg

You have a sub in there. You cannot paste lines containing Sub and End Sub into the method editor. It does not take entire module level pastes. It only takes single method contents (ie what lies between Sub and End Sub / Function and End Function).

Add the pressed Event and then paste the following into it:

// Get the user input from the text fields
Var firstName As String = txtRegFName.Text
Var lastName As String = txtRegLName.Text
Var email As String = txtRegEmail.Text

// Add salt to the user input
Var firstNameSalted As String = firstName + salt
Var lastNameSalted As String = lastName + salt
Var emailSalted As String = email + salt

// Convert the user input to MemoryBlocks
Var firstNameMB As MemoryBlock = firstNameSalted.ToText.ConvertToData(TextEncoding.UTF8)
Var lastNameMB As MemoryBlock = lastNameSalted.ToText.ConvertToData(TextEncoding.UTF8)
Var emailMB As MemoryBlock = emailSalted.ToText.ConvertToData(TextEncoding.UTF8)

// Compute the SHA1 hashes of the MemoryBlocks
Var firstNameHashMB As MemoryBlock = Crypto.SHA1(firstNameMB)
Var lastNameHashMB As MemoryBlock = Crypto.SHA1(lastNameMB)
Var emailHashMB As MemoryBlock = Crypto.SHA1(emailMB)

// Convert the hashes to hexadecimal strings
Var firstNameHash As String = firstNameHashMB.ToHex
Var lastNameHash As String = lastNameHashMB.ToHex
Var emailHash As String = emailHashMB.ToHex

// Combine the hashes to create a registration key
Var regKey As String = firstNameHash + lastNameHash + emailHash

// Display the registration key in the text field
txtRegCode.Text = regKey

I don’t know were this line comes from it is not Xojo code, Xojo has no concept of Import.

// Import the Crypto module
Import Crypto

Your only options to paste entire module level code in at once is to directly edit a .xojo_code file and work there. Make sure you have backups before you go messing with Xojo internals and proceed with extreme caution.