Please i need help in this situation.I have a button two combo boxes with some values in it on a form and i want to icrement them when they are selected.
Button_Click
For example If cmbbox1.Text = "Mathematics" and cmbbox2.Text = "L1" Then
let label1 view the result as L1maths/100,L1maths/101 and so on
If cmbbox1.Text = "English" and cmbbox2.Text = "L2" Then
let label1 view the result as L2eng/120,L2eng/121 and so on

Are you storing the course numbers in a data base, or in the second combo box?

I hope this the way you want..........................

 Function loopincrement100()

        Dim num As Integer
        While num <= 100
            num += 1

        End While


        Return num
    End Function
    Function loopincrement20()

        Dim num As Integer
        While num <= 20
            num += 1

        End While


        Return num
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim subject As String = ComboBox1.SelectedItem
        Dim a As String
        Select Case subject
            Case "Mathematics"
                a = "Maths"
            Case "English"
                a = "eng"
        End Select
        Dim no As Integer

        If ComboBox1.SelectedItem = "Mathematics" Then
            no = loopincrement100()
        Else
            no = loopincrement20()

        End If
        Dim lable As String = ComboBox2.SelectedItem
        Dim x As String = lable & a & "/" & no

        Label1.Text = x


    End Sub

Not quite sure what you expect from those functions, but both of them just return the max number.

Loopincrement100 will return 100
Loopincrement20 will return 20

Why use the functions to begin with?

If you are trying increment the string (which I think is what you are doing) you will want to do this:

Private Function CreateCourseArray(ByVal sCourse As String)
    Try
        Dim lstCourse As New List(Of String)

        If sCourse = "Maths" Then
            For i = 0 To 100
                lstCourse.Add(sCourse & "/" & i)
            Next

            return lstCourse
        Else
            For i = 0 to 20
                lstCourse.Add(sCourse & "/" & i)
            Next

            return lstCourse
        End If
    Catch ex As Exception
        MsgBox("There was a problem creating the array!" & vbcrlf & ex.message)
        Return Nothing
    End Try
End Function

This will return a list of string that contain:

For Mathematics:

  • Maths/0
  • Maths/1
  • Maths/2
  • ...
  • Maths/100

For English:

  • Eng/0
  • Eng/1
  • Eng/2
  • ...
  • Eng/20

thank you for you help but if the ending no haven't mentioned how to do the increment?
because when i'm going this problem i didn't came though no to finish i understood it begins from 20 & 100
can you help me to how to return the value

    Dim x As String
Dim subject as String=combox1.selecteditem

        x = CreateCourseArray(subject)
        Label1.Text = x

I did like this but got an error

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.