Tested wrote:
any way I can make the following less tedious? It's _really_ huge. (And I have to use similar code in 48 versions of this. pain!)
Code:
...
First of all, move the variable declares outside the if. It's best to declare variables at the start of the function / subroutine, rather than when they're needed.
You seem to do Button1.Visible = False on every single path you can take through the thing. Reduntant, move it outside of the IF.
You don't seem to use BillTM -- I'm assuming you need it somewhere, although you could just optimize that away.
With a little bit of string functions (and missing error checking) you can arrive at this:
Code:
Dim BillTM As Byte, pickteam as string, pickpeople as long
pickteam = Right(Label1.Text,3)
pickpeople = Val(Mid(Label1.Text,6,1))
Button1.Visible = False ' You never seem to set this to true anyway
if pickteam = "One" Then
if pickpeople = 1 then
Label1.Text = "Pick 6 members for team Two"
else
Label1.Text = "Pick " & (pickpeople-1) & " member" & iif((pickpeople-1)=1,"","s") & " for Team " & pickteam
end
BillTM = 7 - pickpeople
ElseIf pickteam = "Two" then
if pickpeople = 1 then
Label1.Text = "Please confirm that you would like to pick these people for the first team line up."
else
Label1.Text = "Pick " & (pickpeople-1) & " member" & iif((pickpeople-1)=1,"","s") & " for Team " & pickteam
end
BillTM = (7 - pickpeople) + 6
End If
(I apologise if any PHP or LUA syntax sneaked in there. Haven't used VB in a while.)