Got a little techonology problem that you need fixed pronto? Post it here and we'll see what we can do.
Topic locked

vb express 2005 question

Sat Sep 17, 2005 1:18 am

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:
If Label1.Text = "Pick 6 members for Team One" Then
            Dim BillTM As Byte
            BillTM = 1
            Button1.Visible = False
            Label1.Text = "Pick 5 members for Team One"
        ElseIf Label1.Text = "Pick 5 members for Team One" Then
            Dim BillTM As Byte
            BillTM = 2
            Button1.Visible = False
            Label1.Text = "Pick 4 members for Team One"
        ElseIf Label1.Text = "Pick 4 members for Team One" Then
            Dim BillTM As Byte
            BillTM = 3
            Button1.Visible = False
            Label1.Text = "Pick 3 members for Team One"
        ElseIf Label1.Text = "Pick 3 members for Team One" Then
            Dim BillTM As Byte
            BillTM = 4
            Button1.Visible = False
            Label1.Text = "Pick 2 members for Team One"
        ElseIf Label1.Text = "Pick 2 members for Team One" Then
            Dim BillTM As Byte
            BillTM = 5
            Button1.Visible = False
            Label1.Text = "Pick 1 member for Team One"
        ElseIf Label1.Text = "Pick 1 member for Team One" Then
            Dim BillTM As Byte
            BillTM = 6
            Button1.Visible = False
            Label1.Text = "Pick 6 members for Team Two"
        ElseIf Label1.Text = "Pick 6 members for Team Two" Then
            Dim BillTM As Byte
            BillTM = 7
            Button1.Visible = False
            Label1.Text = "Pick 5 members for Team Two"
        ElseIf Label1.Text = "Pick 5 members for Team Two" Then
            Dim BillTM As Byte
            BillTM = 8
            Button1.Visible = False
            Label1.Text = "Pick 4 members for Team Two"
        ElseIf Label1.Text = "Pick 4 members for Team Two" Then
            Dim BillTM As Byte
            BillTM = 9
            Button1.Visible = False
            Label1.Text = "Pick 3 members for Team Two"
        ElseIf Label1.Text = "Pick 3 members for Team Two" Then
            Dim BillTM As Byte
            BillTM = 10
            Button1.Visible = False
            Label1.Text = "Pick 2 members for Team Two"
        ElseIf Label1.Text = "Pick 2 members for Team Two" Then
            Dim BillTM As Byte
            BillTM = 11
            Button1.Visible = False
            Label1.Text = "Pick 1 member for Team Two"
        ElseIf Label1.Text = "Pick 1 member for Team Two" Then
            Dim BillTM As Byte
            BillTM = 12
            Button1.Visible = False
            Label1.Text = "Please confirm that you would like to pick these people for the first team line up."

Re: vb express 2005 question

Sat Sep 17, 2005 9:01 am

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.)

Re: vb express 2005 question

Sun Sep 18, 2005 1:27 am

Hunter Lupe wrote:
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.)


Thanks!
Also, button1 is the button used to pick Bill for a team, so
button1.visible = false
keeps the user from picking Bill twice.

You can lock this now.
Topic locked