[RESOLVED] Next Tab Button
Guys this is going to sound lame, well because it is...
I have written a small dialog set up in vb6 within excel and thought I would have a go at making a stand alone application with what I have so far and went for vb2005...
Thing is all the coding is very different.
eg trying to make a button click event that will cycle through tabpages
original one was
Private Sub MainNext_Click()
Dim i As Long
i = MultiPage1.Value + 1
If i < MultiPage1.Pages.Count Then
MultiPage1.Value = i
End If
End Sub
But that does not work in vb2005...
any and all suggestions appreciated.
[666 byte] By [
FrameTech] at [2007-11-19 19:43:07]

# 1 Re: [RESOLVED] Next Tab Button
More info on the TabControl in 2005 ( http://msdn.microsoft.com/netframework/windowsforms/support/wffaq/ctrlsp.aspx#wjdc5o9n)
# 2 Re: [RESOLVED] Next Tab Button
lol been there and read the lot of it. wouldnt believe I have been searching for the last 4 hours for the answer to this..
so what we have is
There are a couple of ways you could do select a tab page programmatically. This selects the second Tab page:
tabControl.SelectedTab = this.tabPage2
This also selects the second Tab page:
tabControl.SelectedIndex= 1;
neither of which do anything but bug out.
simply want to create an onclick even that when click "next" button moves to the next tabpage...
# 3 Re: [RESOLVED] Next Tab Button
Just a note this is done in .NET 2003, but give it a try
Private Sub but1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles but1.Click
Dim T As Integer 'for current selected tab
tabcontrol.TabPages.IndexOf(tabcontrol.TabPages.Item(T + 1)) 'next tab
tabcontrol.SelectedIndex = T 'set it
End Sub
Does this work
# 4 Re: [RESOLVED] Next Tab Button
it is awfully close...
no bugs aside from it does nothing.
it is really bizarrrr that such a simple thing can not be found.
You have it very close but not quite...
you know how a wizard works that is what I originally set up in vb6...
must have something to do with tabpages.count
# 5 Re: [RESOLVED] Next Tab Button
Hey FrameTech,
Why is there a 2003 and 2005 in any case
I suppose, it's fort the better at the end, but at least there must be some consistency, with most of the things
If it was VB6 to VB.NET 2003, I could understand it.
Anyways enough rambling,
let's hope someone else uses 2005 and help clear this up. ;)
# 6 Re: [RESOLVED] Next Tab Button
yeah I agree....
doesnt take me long to figure the language change but this simple thing has me stumped
# 7 Re: [RESOLVED] Next Tab Button
Problem fixed...
--------------------------
Private Sub cbNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbNext.Click
If Me.TabControl1.SelectedIndex <> Me.TabControl1.TabCount - 1 Then
Me.TabControl1.SelectedIndex += 1
Else
Me.TabControl1.SelectedIndex = 0
End If
End Sub
--------------------------
The Button "cbNext"
The TabControl "TabControl1"
Can be named what ever you name them in the design...
# 8 Re: [RESOLVED] Next Tab Button
Good Work man!
I've never seen VS 2005, and by the looks of it, I don't want to :p
I always get too complicated in my code :rolleyes:
Now I actually feel silly :blush:
Sorry I wasn't greater help...
# 9 Re: [RESOLVED] Next Tab Button
not at all... just talking it out helps me think.
now I have to get the same code to work backwards for a previous button...
any suggestions?
# 10 Re: [RESOLVED] Next Tab Button
Based on what you've done, it should be "almost" the same logic - just the opposite.
If Me.TabControl1.SelectedIndex <> Me.TabControl1.TabCount - 1 Then
Me.TabControl1.SelectedIndex -= 1 'I think all you need is this, but "don't take my word for it" :p , I'm not myself today.. :rolleyes:
Else
Me.TabControl1.SelectedIndex = 0
End If
End Sub
PS: use [CODE]your code here[/CODE] tags when posting code :D
# 11 Re: [RESOLVED] Next Tab Button
The above code is not entirely accurate as it creates a costant loop in the tab selection...
this line will move through to the last one and back again if the + is -
Me.TabControl1.SelectedIndex += 1
when it is changed to - it goes below 0 and then we have another problem...
oh this is fun......
# 12 Re: [RESOLVED] Next Tab Button
The above code is not entirely accurate as it creates a costant loop in the tab selection...
this line will move through to the last one and back again if the + is -
Me.TabControl1.SelectedIndex += 1
when it is changed to - it goes below 0 and then we have another problem...
oh this is fun......
This is great fun :lol:
Try this then
I feel like shooting myself today :)
If TabControl1.SelectedIndex > -1 Then 'won't go below 0
If Me.TabControl1.SelectedIndex <> 0 Then
Me.TabControl1.SelectedIndex -= 1 'I think all you need is this, but "don't take my word for it" :p , I'm not myself today.. :rolleyes:
Else
Me.TabControl1.SelectedIndex = Me.TabControl1.TabCount - 1
End If
End If
End Sub
# 13 Re: [RESOLVED] Next Tab Button
lmao you and me both... can you believe i have been at this one for now... 6 hours lol
now your code does the trick nicely in reverse. however, it is now in a costant loop backwards lmao
Private Sub cbPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbPrevious.Click
If TabControl1.SelectedIndex > -1 Then 'won't go below 0
If Me.TabControl1.SelectedIndex <> 0 Then
Me.TabControl1.SelectedIndex -= 1 'I think all you need is this, but "don't take my word for it" :p , I'm not myself today.. :rolleyes:
End If
End If
End Sub
and that does it nicely.... bloody legend!
# 14 Re: [RESOLVED] Next Tab Button
lmao you and me both... can you believe i have been at this one for now... 6 hours lol
:lol: LOL, I'm still laughing, but sometimes you get to a point where it just isn't funny anymore :D
This Simple thing, reminds me of a girlfriend I once knew, and she also didn't have any end (always complaining constantly) :lol:
More on topic
Not sure if this is fixed or not, now - confused...
If it's not
So, this is a constant loop now, why not try something like Exit Sub (just a long shot)
Anyways, unfortunately I have to go home and be depressed now, hopefully someone else can help further.
PS: this was fun, but I really need a beer :p
# 15 Re: [RESOLVED] Next Tab Button
nah mate you fixed it.... well done!
Not finnished on this topic just yet but that part is solved (will post it to make sense later) its 1 am and I am looking for sleep..
thanks heaps for your help on this one mate!!!
next question is changeevent... lol
Private Sub MultiPage1_Change()
If MultiPage1.Value = 0 Then
CommandButton2.Enabled = False
CommandButton3.Enabled = True
UserForm1.Caption = "Job Setup"
ElseIf MultiPage1.Value = 1 Then
CommandButton2.Enabled = True
CommandButton3.Enabled = True
UserForm1.Caption = "External Framing Setup - Step 1 of 2"
ElseIf MultiPage1.Value = 2 Then
CommandButton2.Enabled = True
CommandButton3.Enabled = True
UserForm1.Caption = "External Framing Setup - Step 2 of 2"
ElseIf MultiPage1.Value = 3 Then
CommandButton2.Enabled = True
CommandButton3.Enabled = False
UserForm1.Caption = "Framing Summary"
GenerateOptions
ElseIf MultiPage1.Value = 4 Then
CommandButton2.Enabled = False
CommandButton3.Enabled = False
UserForm1.Caption = "Openings - 1 of 2"
ElseIf MultiPage1.Value = 5 Then
CommandButton2.Enabled = True
CommandButton3.Enabled = False
UserForm1.Caption = "Openings - 1 of 2"
ElseIf MultiPage1.Value = 6 Then
CommandButton2.Enabled = True
CommandButton3.Enabled = False
UserForm1.Caption = "dont know yet"
Else
MsgBox "Error: invalid page value"
End If
End Sub
# 16 Re: [RESOLVED] Next Tab Button
u can use SelectedIndexChanged event of tabcontrol
Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
if TabControl1.SelectedIndex = 0 Then
button1.enabled=true
elseis Tabcontrol1.selectedIndex=1 Then
button1.enabled=true
End If
# 17 Re: [RESOLVED] Next Tab Button
nah mate you fixed it.... well done!
Not finnished on this topic just yet but that part is solved (will post it to make sense later) its 1 am and I am looking for sleep..
thanks heaps for your help on this one mate!!!
Then I'm happy, I also learnt something out of this - so that makes everything worthwhile!
next question is changeevent... lol
You can use the SelectedIndexChanged event, like aniskhan posted
PS: If you have problems somewhere else, just shout I'll try to "puzzle" it out with you :p
# 18 Re: [RESOLVED] Next Tab Button
Great! So far looking good and thank you both.
now the change caption part... not really needed but...
Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
If TabControl1.SelectedIndex = 0 Then
cbPrevious.Enabled = False
cbNext.Enabled = True
ElseIf TabControl1.SelectedIndex = 1 Then
cbPrevious.Enabled = True
cbNext.Enabled = True
ElseIf TabControl1.SelectedIndex = 2 Then
cbPrevious.Enabled = True
cbNext.Enabled = True
ElseIf TabControl1.SelectedIndex = 3 Then
cbPrevious.Enabled = True
cbNext.Enabled = True
ElseIf TabControl1.SelectedIndex = 4 Then
cbPrevious.Enabled = True
cbNext.Enabled = True
End If
End Sub
This will take care of the next and previous buttons nicely for 5 tabpages
now the change caption thingy
UserForm1.Caption = "External Framing Setup - Step 1 of 2"
and the other that is really bothering me is hiding the tab buttons...
# 19 Re: [RESOLVED] Next Tab Button
Hey bud! :wave:
Let's have a look...
Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
If TabControl1.SelectedIndex = 0 Then
cbPrevious.Enabled = False
cbNext.Enabled = True
UserControl1.Caption = "Step Whatever"
ElseIf TabControl1.SelectedIndex = 1 Then
cbPrevious.Enabled = True
cbNext.Enabled = True
ElseIf TabControl1.SelectedIndex = 2 Then
cbPrevious.Enabled = True
cbNext.Enabled = True
UserControl1.Caption = "Step Whatever"
ElseIf TabControl1.SelectedIndex = 3 Then
cbPrevious.Enabled = True
cbNext.Enabled = True
UserControl1.Caption = "Step Whatever"
ElseIf TabControl1.SelectedIndex = 4 Then
cbPrevious.Enabled = True
cbNext.Enabled = True
UserControl1.Caption = "Step Whatever"
End If
End Sub
Will that do
Just one thing, do you have a caption property in the user control
# 20 Re: [RESOLVED] Next Tab Button
not entirely sure what you mean...
"the usercontrol1 is not defined"
is what that does ....
mmmmmm
turn the tab buttons off?
# 21 Re: [RESOLVED] Next Tab Button
Too many beers in me, can't see clearly :sick:
Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
If TabControl1.SelectedIndex = 0 Then
cbPrevious.Enabled = False
cbNext.Enabled = True
UserForm1.Caption = "Step Whatever"
ElseIf TabControl1.SelectedIndex = 1 Then
cbPrevious.Enabled = True
cbNext.Enabled = True
ElseIf TabControl1.SelectedIndex = 2 Then
cbPrevious.Enabled = True
cbNext.Enabled = True
UserForm1.Caption = "Step Whatever"
ElseIf TabControl1.SelectedIndex = 3 Then
cbPrevious.Enabled = True
cbNext.Enabled = True
UserForm1.Caption = "Step Whatever"
ElseIf TabControl1.SelectedIndex = 4 Then
cbPrevious.Enabled = True
cbNext.Enabled = True
UserForm1.Caption = "Step Whatever"
End If
I misread UserForm1 as UserControl1, sorry, force of habit, in VB6 I often see UserControl1, sorry! :blush:
Try it now..
End Sub
# 22 Re: [RESOLVED] Next Tab Button
usercontrol1 is correct lol the userform1 is for vb6 i think
nah its not working yet but I will keep pluggin away at it
# 23 Re: [RESOLVED] Next Tab Button
ok the name thing works like this
ElseIf TabControl1.SelectedIndex = 4 Then
cbPrevious.Enabled = True
cbNext.Enabled = True
UserForm1.Caption = "Step Whatever"
The "UserForm1.Caption = "Step Whatever"
Should read "Me.Text = "Step Whatever"
This will change the Title at the top of the dialog box when the "cbNext button is clicked...
# 24 Re: [RESOLVED] Next Tab Button
Seeing how we can not find a way to "hide" the tab buttons, is there another way that this "wizard" type set up can be done?
# 25 Re: [RESOLVED] Next Tab Button
Just to put this one to bed...
This is the set up for a "wizard style form" with 5 tabpages a cancel, previous, next and finish button.
Private Sub cbFinish_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbFinish.Click
Me.Close()
End Sub
Private Sub cbNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbNext.Click
If Me.TabControl1.SelectedIndex <> Me.TabControl1.TabCount - 1 Then
Me.TabControl1.SelectedIndex += 1
End If
End Sub
Private Sub cbPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbPrevious.Click
If TabControl1.SelectedIndex > -1 Then 'won't go below 0
If Me.TabControl1.SelectedIndex <> 0 Then
Me.TabControl1.SelectedIndex -= 1
End If
End If
End Sub
Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
If TabControl1.SelectedIndex = 0 Then
cbPrevious.Enabled = False
cbNext.Enabled = True
cbFinish.Enabled = False
ElseIf TabControl1.SelectedIndex = 1 Then
cbPrevious.Enabled = True
cbNext.Enabled = True
cbFinish.Enabled = False
Me.Text = "Step Whatever" 'changes the top text to whatever
ElseIf TabControl1.SelectedIndex = 2 Then
cbPrevious.Enabled = True
cbNext.Enabled = True
ElseIf TabControl1.SelectedIndex = 3 Then
cbPrevious.Enabled = True
cbNext.Enabled = True
ElseIf TabControl1.SelectedIndex = 4 Then
cbPrevious.Enabled = True
cbNext.Enabled = True
End If
End Sub
Private Sub cbCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbCancel.Click
Dim result As DialogResult
result = MessageBox.Show("This will close this job without saving it! Want to continue?", _
"Quit Job Without Saving?", MessageBoxButtons.YesNo, _
MessageBoxIcon.Question)
If result = Windows.Forms.DialogResult.Yes Then
Me.Close()
End If
End Sub
