Help for VB.Net program

LKuser

Active member
  • Jan 2, 2017
    509
    113
    43
    Colombo
    I am almost out of program coding due to my current job. I try to create a VB.Net program. The idea is to assign some values for each alphabet letter and add value for them and, then display the total value

    Eg:

    • A =3 B =7… likewise some values will be assigned to each alphabet character. (I have no problem. I can do it):yes:
    • Read input from textbox (no problem):yes:
    • Add value for each character of the textbox and display the total value. If input strings were AB, then output should be 10. :(
    If you are good with C# or some other language, explain the loop and I can understand. Advanced thanks.
     

    Scattered123

    Well-known member
  • Nov 18, 2012
    946
    323
    63
    Does it matter?
    get the textbox text, the get the every character in the textbox to an char array, so the array length is the length of the text length. Therefore it becomes easy
     

    Scattered123

    Well-known member
  • Nov 18, 2012
    946
    323
    63
    Does it matter?
    C# code eka

    Code:
    char[] letters = {'A', 'B', 'C', 'D'};
                int[] values = {3, 7, 5, 10};
    
                string s = textBox1.Text;
                char[] array = s.ToCharArray();
                int i = 0;
                for (int z = 0; z < array.Length; z++)
                {
                    for (int x = 0; x < letters.Length; x++)
                    {
                        if (array[z].Equals(letters[x]))
                        {
                            i += values[x];
                        }
                    }
                }
                MessageBox.Show(i.ToString());
     
    • Like
    Reactions: LKuser

    LKuser

    Active member
  • Jan 2, 2017
    509
    113
    43
    Colombo
    C# code eka

    Code:
    char[] letters = {'A', 'B', 'C', 'D'};
                int[] values = {3, 7, 5, 10};
    
                string s = textBox1.Text;
                char[] array = s.ToCharArray();
                int i = 0;
                for (int z = 0; z < array.Length; z++)
                {
                    for (int x = 0; x < letters.Length; x++)
                    {
                        if (array[z].Equals(letters[x]))
                        {
                            i += values[x];
                        }
                    }
                }
                MessageBox.Show(i.ToString());

    Thank U