Hi,
I have to create a modular variable (string with no value) set as LN (txtLastName.Text) which takes its value once the user enters his Last Name and hits the submit button.
Also it shows in other sub procedures.

This is what the program is supposed to do:
Enter all the information in the given fields
When pressed Calculate button it should calculate and show a message on the right side under Tuition Confirmation.
Message should be the (Value of the Last Name Entered using Modular Variable) with some message.
Once Clicked Clear it should clear all the text and label fields (Last Name using Modular Variable)
Once Clicked on Exit button it should show a bye now message with Last Name (using Modular Variable)

Below is how I tried to define a Modular Variable
The issue is how to assign a value to the variable after it has taken it from the Text Box as it may change every time a new last name is entered.

'LN = as Last Name
Public LN As String = " "

When Clicking Clear Button (Only few examples):

Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
        'Clears all the textboxes and labels

        txtFirstName.Text = " "
        LN = " " <<--- here How do I assign a value to txtLastName.Text to LN?
        txtSchoolName.Text = " "
        txtNumofCour.Text = " "
        rptRed.Checked = False

    rptCoral.Checked = False

When Clicking Exit Button:

Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
        'Shows a message box and exits the program

        MessageBox.Show("Bye for Now, " & LN & "!", "Time to go", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Me.Close()

When Clicking Calculate Button (Only the message portion):

lblTutConfValue.Text = txtStudentNum.Text & " / " & LN & ": Your payment to " & txtSchoolName.Text & " has been processed!"

All three of those needs values from txtLastName.Text textbox but its value should be assigned to Modular Variable LN and then applicable to all sub procedures in that frmMain.

I would greatly appreciate if someone can post the actual code and explain how it works?

Thanks
Shaq

Yes but where do I put it in the code? Do I have to put it under all the Sub procedures separately??
I did tried to put in all sub procedures. Calculate and Exit button worked but not the Clear button as I already am using LN = " " to clear the textbox for the last name field.

Line 5 of the clear button handler looks good. But another place would be just before you need to use the variable.

By the way, why do you call this a "modular" variable? I don't recall such a term in my classes.

Our teacher said it is a global variable but in vb.net it's called modular lol.. anyhow I still don't know where to put the code that gives value to LN. Yes it will clear the LN value but in that sub procedure for Clear button the program does not know what value is for LN do in turn it does not clear the last name text box.

Text textbox but its value should be assigned to Modular Variable LN and then applicable to all sub procedures in that frmMain.

Modular Variable LN ???????

You have to read the declaration & scope of variables.

Anyone at home can call variables as he pleases, why not? By modular variable I can understand for example z = (z+1) mod 3 where z will take values {0,1,2} and wraps around passed the upper bound (also called circular or wrapping variable), but not applicable to a string.

Of course, I don't recommend to you to use that kind of unusual terminology on an official report, unless explaining exactly what do you mean.

If you'd like to read a discussion about modular variables Click Here

commented: Good link, but this variable doesn't seem modular according to that definition. +12

modular? from module? A variable global to a module?

No, I can't see the relation and really I can't hardly imagine a teacher comparing global and modular variables.

mod1.PNG
Here 'z' is a local variable and takes integers values modulo i=2,3,4,5 (for-next)
In the first loop i=2 and starting at z=0, z=(z+1) mod i increments z to 1. in the second loop, z=(z+1) would increment z from 1 to 2, but because there is 'mod i' function and i=2, z wraps around to zero, and exits the do...loop, so i=3 now.
Again, when i=3, starts z=0 and in the first loop (z+1) mod i, increments by one, so z=1. In the same manner in the next loop increments to z=2, but in the following loop will became 0 because (z+1) mod 3 (i=3) signifies that the first argument (z+1) can't never reach the second argument (here 3), and so wraps around (in fact subtracting 3, 3-3=0).
A bit entangled, isn't it?

I think I need to explain myself, simplifying:
'mod' function takes two arguments 'a' an 'b' So we write
'a mod b'.
When argument 'a' is less than 'b' the output is 'a'. When 'a' is bigger than 'b' we will substract 'b' to 'a' as many times as needed so that 'a' becames smaller than 'b'. (I recall no division here, although arriving to the same result). Being 'a' less then 'b', this will be the output. If 'a' is equal to 'b' the output will be zero.
For example, z=5 mod 3, 5 >3, substract 3 from 5 and get z=2 as result.
For z=7 mod 3, 7-3=4, but 4>3, substract again 4-3=1 and get z=1 as result.
The same stands similarly for negative numbers: z=mod 3, -5 < -3 (note that we change the sign to -3) -5 +3=-2 (and we add +3 instead). z=-2 is the output.

@X. How does that work for the topic? "How to Assign a value taken from LastName Text box to a Modular Variable."

I think it's clear now that the OP needs to refine their question.

First of all set options to strict on and infer to off. You find these by clicken on myproject in solution explorer and the compile option.
To set a variable for the class or module declare these before the Load method like:

Public Class TheName
Dim LastName as string="" or
Dim LN As String = ""
Private Sub TheName_Load
Now the variable will be available throughout your form.

If you need to make a variable gobal throughout your application(more then one form etc) you need to add a module to your apllication.
You do that by going to the menu bar -> Project-> Add Module.
You can then declare a variable ther and make it available to all forms.
Public LN as string=""
Also note the quotes "" to declare an empty string.
This " " will declare a string with a space in it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.