幻灯片按钮的vb.net数组

时间:2010-05-23 21:23:14

标签: vb.net visual-studio-2008

嘿所有,我正在试图弄清楚如何去做...

我有一个我称之为的表格:

 call frmSlideShow.showWhat("1,4,8,9,11,22")

每个数字代表不同的图像幻灯片(slide1.png,slide4.png等)。我遇到的问题是尝试创建一个“上一个”和“下一个”按钮来翻阅它们。试图找出用户所在的数字和从那里开始的数字,并查看上面列表中发送的数字仍然是等等。

如果有人知道我会怎么做,那就太棒了! :)

更新

这是代码..

Public Sub showWhat(ByVal theNumbers As String)
    Dim theNums As String() = theNumbers.Split(New Char() {","c})
    Dim theCurNum As String

    For Each theCurNum In theNums
        Debug.Print(theCurNum)
    Next
End Sub

大卫

1 个答案:

答案 0 :(得分:2)

将theNums字符串数组放在代码中一级,以及跟踪数组中当前位置的整数变量。然后你的下一个按钮将检查theNums数组的上边界,以确保你不在最后一个。如果你不是,那么它会将整数变量增加1,然后你就可以使用theNums(intTracker)。

Public Class Form1
    Dim theNums As String()
    Dim intTracker As Integer = 0
    Public Sub showWhat(ByVal theNumbers As String)
        theNums = theNumbers.Split(New Char() {","c})
        intTracker = 0
        MsgBox("Currently showing " & theNums(intTracker))
        If theNums.GetUpperBound(0) < 1 Then
            btnNext.Enabled = False 'Only one number was passed, so disable the next button
        End If
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Call showWhat("1,2,3")
    End Sub
    Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click
        btnNext.Enabled = True
        intTracker -= 1
        MsgBox("Now on " & theNums(intTracker))
        If intTracker = 0 Then
            btnLast.Enabled = False 'Disable the button because you're at the beginning
        End If
    End Sub

    Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
        btnLast.Enabled = True
        intTracker += 1
        MsgBox("Now on " & theNums(intTracker))
        If theNums.GetUpperBound(0) = intTracker Then
            btnNext.Enabled = False 'On the last slide, so disable the next button
        End If
    End Sub
End Class