In: Computer Science
I am having problems getting the second button part of this to work. this is for visual basic using visual studio 2017. Please help.
Create an application named You Do It 4 and save it in the
VB2017\Chap07 folder. Add
two labels and two buttons to the form. Create a class-level
variable named strLetters
and initialize it to the first 10 uppercase letters of the alphabet
(the letters A through J).
The first button’s Click event procedure should use the appropriate
character’s index to
display the fifth letter from the strLetters variable (the letter
E) in the first label. The
second button should use a loop and the appropriate indexes to
display the letters CDEF
in the second label. Code the procedures. Save the solution and
then start and test the
application. Close the solution.
Design
Coding
Alphabet.vb
Public Class Alphabet
Public strLetters As String = "ABCDEFGHIJ" 'Make class lavel
variable declare here
End Class
Form1.vb
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs)
Handles Button1.Click ''if button one click then it invoke this
code
Dim a1 As New Alphabet ''take new object of class Albphabet
Label1.Text = a1.strLetters.Substring(4, 1).ToString ''output
display
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs)
Handles Button2.Click
Dim a1 As New Alphabet 'take new object of class Albphabet
Dim str As String = "" 'take new string
For i As Integer = 2 To 5
str = str + a1.strLetters.Substring(i, 1).ToString ''string value
concate here from index 2 to 5
Next
Label2.Text = str ''output display
End Sub
End Class
Output:
if you still have any Problem regarding this question please comment and if you like my code please appreciate me by thumbs up thank you.........