switching to another text box for output after reaching a value in a loop

j00sh

Active member
Joined
Mar 29, 2007
Messages
35
Programming Experience
Beginner
this is a little jumbled because of how I did the loops but what I want to do is move the output to another textbox each time variable plants reaches 18 (i want 18 plants per text box)

If anyone can point me in the right direction for this problem please do

I know a lot of this is inefficient but this is all just temporary until I figure certain things out about the code.




VB.NET:
[COLOR=#0000ff]Public [/COLOR][COLOR=#0000ff]Class[/COLOR][B] Form1[/B]
[COLOR=#0000ff]Structure[/COLOR][B] Student[/B]
[COLOR=#0000ff]Dim[/COLOR][B] strName [/B][COLOR=#0000ff]As[/COLOR][COLOR=#0000ff]String[/COLOR]
[COLOR=#0000ff]Dim[/COLOR][B] intPetunias [/B][COLOR=#0000ff]As[/COLOR][COLOR=#0000ff]Integer[/COLOR]
[COLOR=#0000ff]Dim[/COLOR][B] intGlads [/B][COLOR=#0000ff]As[/COLOR][COLOR=#0000ff]Integer[/COLOR]
[COLOR=#0000ff]Dim[/COLOR][B] intIrises [/B][COLOR=#0000ff]As[/COLOR][COLOR=#0000ff]Integer[/COLOR]
[COLOR=#0000ff]End[/COLOR][COLOR=#0000ff]Structure[/COLOR]
[COLOR=#0000ff]Dim[/COLOR][B] Billy [/B][COLOR=#0000ff]As[/COLOR][B] Student[/B]
[COLOR=#0000ff]Dim[/COLOR][B] Sally [/B][COLOR=#0000ff]As[/COLOR][B] Student[/B]
 
 
[COLOR=#0000ff]Private[/COLOR][COLOR=#0000ff]Sub[/COLOR][B] Form1_Load([/B][COLOR=#0000ff]ByVal[/COLOR][B] sender [/B][COLOR=#0000ff]As[/COLOR][B] System.Object, [/B][COLOR=#0000ff]ByVal[/COLOR][B] e [/B][COLOR=#0000ff]As[/COLOR][B] System.EventArgs) [/B][COLOR=#0000ff]Handles[/COLOR][COLOR=#0000ff]MyBase[/COLOR][B].Load[/B]
[B]Billy.strName = [/B][COLOR=#800000]"Billy"[/COLOR]
[B]Billy.intPetunias = 0[/B]
[B]Billy.intIrises = 0[/B]
[B]Billy.intGlads = 0[/B]
[B]Sally.strName = [/B][COLOR=#800000]"Sally"[/COLOR]
[B]Sally.intPetunias = 0[/B]
[B]Sally.intIrises = 0[/B]
[B]Sally.intGlads = 0[/B]
[COLOR=#0000ff]End[/COLOR][COLOR=#0000ff]Sub[/COLOR]
[COLOR=#0000ff]Private[/COLOR][COLOR=#0000ff]Sub[/COLOR][B] cmdOk_Click([/B][COLOR=#0000ff]ByVal[/COLOR][B] sender [/B][COLOR=#0000ff]As[/COLOR][B] System.Object, [/B][COLOR=#0000ff]ByVal[/COLOR][B] e [/B][COLOR=#0000ff]As[/COLOR][B] System.EventArgs) [/B][COLOR=#0000ff]Handles[/COLOR][B] cmdOk.Click[/B]
[B]txtDisplay.Clear()[/B]
[COLOR=#0000ff]Dim[/COLOR][B] counter [/B][COLOR=#0000ff]As[/COLOR][COLOR=#0000ff]Integer[/COLOR]
[COLOR=#0000ff]Dim[/COLOR][B] countto [/B][COLOR=#0000ff]As[/COLOR][COLOR=#0000ff]Integer[/COLOR]
[COLOR=#0000ff]Dim[/COLOR][B] plants [/B][COLOR=#0000ff]As[/COLOR][COLOR=#0000ff]Integer[/COLOR][B] = 0[/B]
[COLOR=#0000ff]If[/COLOR][B] txtName.Text = [/B][COLOR=#800000]"Billy"[/COLOR][COLOR=#0000ff]Then[/COLOR]
[COLOR=#0000ff]With[/COLOR][B] Billy[/B]
[B].intPetunias += [/B][COLOR=#0000ff]Integer[/COLOR][B].Parse(txtPetunias.Text)[/B]
[B].intGlads += [/B][COLOR=#0000ff]Integer[/COLOR][B].Parse(txtGlads.Text)[/B]
[B].intIrises += [/B][COLOR=#0000ff]Integer[/COLOR][B].Parse(txtIrises.Text)[/B]
[COLOR=#0000ff]End[/COLOR][COLOR=#0000ff]With[/COLOR]
[COLOR=#0000ff]ElseIf[/COLOR][B] txtName.Text = [/B][COLOR=#800000]"Sally"[/COLOR][COLOR=#0000ff]Then[/COLOR]
[COLOR=#0000ff]With[/COLOR][B] Sally[/B]
[B].intPetunias += [/B][COLOR=#0000ff]Integer[/COLOR][B].Parse(txtPetunias.Text)[/B]
[B].intGlads += [/B][COLOR=#0000ff]Integer[/COLOR][B].Parse(txtGlads.Text)[/B]
[B].intIrises += [/B][COLOR=#0000ff]Integer[/COLOR][B].Parse(txtIrises.Text)[/B]
[COLOR=#0000ff]End[/COLOR][COLOR=#0000ff]With[/COLOR]
[COLOR=#0000ff]End[/COLOR][COLOR=#0000ff]If[/COLOR]
[B]counter = 1[/B]
[B]countto = Billy.intPetunias[/B]
[COLOR=#0000ff]Do[/COLOR][COLOR=#0000ff]While[/COLOR][B] counter <= countto[/B]
[B]txtDisplay.Text &= [/B][COLOR=#800000]"Billy Petunia"[/COLOR][B] & ControlChars.NewLine[/B]
[B]counter += 1[/B]
[B]plants += 1[/B]
[COLOR=#0000ff]Loop[/COLOR]
[B]counter = 1[/B]
[B]countto = Billy.intGlads[/B]
[COLOR=#0000ff]Do[/COLOR][COLOR=#0000ff]While[/COLOR][B] counter <= countto[/B]
[B]txtDisplay.Text &= [/B][COLOR=#800000]"Billy Gladiolus"[/COLOR][B] & ControlChars.NewLine[/B]
[B]counter += 1[/B]
[B]plants += 1[/B]
[COLOR=#0000ff]Loop[/COLOR]
[B]counter = 1[/B]
[B]countto = Billy.intIrises[/B]
[COLOR=#0000ff]Do[/COLOR][COLOR=#0000ff]While[/COLOR][B] counter <= countto[/B]
[B]txtDisplay.Text &= [/B][COLOR=#800000]"Billy Iris"[/COLOR][B] & ControlChars.NewLine[/B]
[B]counter += 1[/B]
[B]plants += 1[/B]
[COLOR=#0000ff]Loop[/COLOR]
 
 
[B]counter = 1[/B]
[B]countto = Sally.intPetunias[/B]
[COLOR=#0000ff]Do[/COLOR][COLOR=#0000ff]While[/COLOR][B] counter <= countto[/B]
[B]txtDisplay.Text &= [/B][COLOR=#800000]"Sally Petunia"[/COLOR][B] & ControlChars.NewLine[/B]
[B]counter += 1[/B]
[B]plants += 1[/B]
[COLOR=#0000ff]Loop[/COLOR]
[B]counter = 1[/B]
[B]countto = Sally.intGlads[/B]
[COLOR=#0000ff]Do[/COLOR][COLOR=#0000ff]While[/COLOR][B] counter <= countto[/B]
[B]txtDisplay.Text &= [/B][COLOR=#800000]"Sally Gladiolus"[/COLOR][B] & ControlChars.NewLine[/B]
[B]counter += 1[/B]
[B]plants += 1[/B]
[COLOR=#0000ff]Loop[/COLOR]
[B]counter = 1[/B]
[B]countto = Sally.intIrises[/B]
[COLOR=#0000ff]Do[/COLOR][COLOR=#0000ff]While[/COLOR][B] counter <= countto[/B]
[B]txtDisplay.Text &= [/B][COLOR=#800000]"Sally Iris"[/COLOR][B] & ControlChars.NewLine[/B]
[B]counter += 1[/B]
[B]plants += 1[/B]
[COLOR=#0000ff]Loop[/COLOR]
[COLOR=#0000ff]End[/COLOR][COLOR=#0000ff]Sub[/COLOR]
[COLOR=#0000ff]End[/COLOR][COLOR=#0000ff]Class[/COLOR]

copy/pasting it over screwed up some of the spacing, I do realize that DoWhile needs a space in between :D
 
Last edited:
one solution I'm thinking of is figuring out plants when the button is pressed, divide by 18, create that many text boxes in the code (unsure of how to do that at this point), and then have a second counter that runs 0-18 per text box... but I'm really not sure

edit: I cleaned it up a little putting stuff into its own subroutines, and I gave up on creating new textboxes until I can figure that out
here's what I came up with

VB.NET:
[COLOR=#0000ff]Public[/COLOR][COLOR=#0000ff]Class[/COLOR][B] Form1
[/B][COLOR=#0000ff]Dim[/COLOR][B] plants [/B][COLOR=#0000ff]As[/COLOR][COLOR=#0000ff]Integer[/COLOR][B] = 0
[/B] 
[B][/B][COLOR=#0000ff]Structure[/COLOR][B] Student
[/B][COLOR=#0000ff]Dim[/COLOR][B] strName [/B][COLOR=#0000ff]As[/COLOR][COLOR=#0000ff]String
[/COLOR][B][/B][COLOR=#0000ff]Dim[/COLOR][B] intPetunias [/B][COLOR=#0000ff]As[/COLOR][COLOR=#0000ff]Integer
[/COLOR][B][/B][COLOR=#0000ff]Dim[/COLOR][B] intGlads [/B][COLOR=#0000ff]As[/COLOR][COLOR=#0000ff]Integer
[/COLOR][B][/B][COLOR=#0000ff]Dim[/COLOR][B] intIrises [/B][COLOR=#0000ff]As[/COLOR][COLOR=#0000ff]Integer
[/COLOR][B][/B][COLOR=#0000ff]End[/COLOR][COLOR=#0000ff]Structure
[/COLOR][B][/B][COLOR=#0000ff]Dim[/COLOR][B] Billy [/B][COLOR=#0000ff]As[/COLOR][B] Student
[/B][COLOR=#0000ff]Dim[/COLOR][B] Sally [/B][COLOR=#0000ff]As[/COLOR][B] Student
[/B] 
 
[B][/B][COLOR=#0000ff]Private[/COLOR][COLOR=#0000ff]Sub[/COLOR][B] Form1_Load([/B][COLOR=#0000ff]ByVal[/COLOR][B] sender [/B][COLOR=#0000ff]As[/COLOR][B] System.Object, [/B][COLOR=#0000ff]ByVal[/COLOR][B] e [/B][COLOR=#0000ff]As[/COLOR][B] System.EventArgs) [/B][COLOR=#0000ff]Handles[/COLOR][COLOR=#0000ff]MyBase[/COLOR][B].Load
Billy.strName = [/B][COLOR=#800000]"Billy"
[/COLOR][B]Billy.intPetunias = 0
Billy.intIrises = 0
Billy.intGlads = 0
Sally.strName = [/B][COLOR=#800000]"Sally"
[/COLOR][B]Sally.intPetunias = 0
Sally.intIrises = 0
Sally.intGlads = 0
[/B][COLOR=#0000ff]End[/COLOR][COLOR=#0000ff]Sub
[/COLOR][B][/B][COLOR=#0000ff]Private[/COLOR][COLOR=#0000ff]Sub[/COLOR][B] cmdOk_Click([/B][COLOR=#0000ff]ByVal[/COLOR][B] sender [/B][COLOR=#0000ff]As[/COLOR][B] System.Object, [/B][COLOR=#0000ff]ByVal[/COLOR][B] e [/B][COLOR=#0000ff]As[/COLOR][B] System.EventArgs) [/B][COLOR=#0000ff]Handles[/COLOR][B] cmdOk.Click
plants = 0
txtDisplay.Clear()
[/B] 
[B][/B][COLOR=#0000ff]If[/COLOR][B] txtName.Text = [/B][COLOR=#800000]"Billy"[/COLOR][COLOR=#0000ff]Then
[/COLOR][B][/B][COLOR=#0000ff]With[/COLOR][B] Billy
.intPetunias += [/B][COLOR=#0000ff]Integer[/COLOR][B].Parse(txtPetunias.Text)
.intGlads += [/B][COLOR=#0000ff]Integer[/COLOR][B].Parse(txtGlads.Text)
.intIrises += [/B][COLOR=#0000ff]Integer[/COLOR][B].Parse(txtIrises.Text)
[/B][COLOR=#0000ff]End[/COLOR][COLOR=#0000ff]With
[/COLOR][B][/B][COLOR=#0000ff]ElseIf[/COLOR][B] txtName.Text = [/B][COLOR=#800000]"Sally"[/COLOR][COLOR=#0000ff]Then
[/COLOR][B][/B][COLOR=#0000ff]With[/COLOR][B] Sally
.intPetunias += [/B][COLOR=#0000ff]Integer[/COLOR][B].Parse(txtPetunias.Text)
.intGlads += [/B][COLOR=#0000ff]Integer[/COLOR][B].Parse(txtGlads.Text)
.intIrises += [/B][COLOR=#0000ff]Integer[/COLOR][B].Parse(txtIrises.Text)
[/B][COLOR=#0000ff]End[/COLOR][COLOR=#0000ff]With
[/COLOR][B][/B][COLOR=#0000ff]End[/COLOR][COLOR=#0000ff]If
 
 
[/COLOR][B]BillyPlants()
SallyPlants()
[/B][B][/B][COLOR=#0000ff]End[/COLOR][COLOR=#0000ff]Sub
[/COLOR][B][/B][COLOR=#0000ff]Public[/COLOR][COLOR=#0000ff]Sub[/COLOR][B] SallyPlants()
[/B][COLOR=#0000ff]Dim[/COLOR][B] counter [/B][COLOR=#0000ff]As[/COLOR][COLOR=#0000ff]Integer
[/COLOR][B][/B][COLOR=#0000ff]Dim[/COLOR][B] countto [/B][COLOR=#0000ff]As[/COLOR][COLOR=#0000ff]Integer
[/COLOR][B]counter = 1
countto = Sally.intPetunias
[/B][COLOR=#0000ff]Do[/COLOR][COLOR=#0000ff]While[/COLOR][B] (counter <= countto)
PlantCheck()
txtDisplay.Text &= [/B][COLOR=#800000]"Sally Petunia"[/COLOR][B] & ControlChars.NewLine
counter += 1
plants += 1
[/B][B][/B][COLOR=#0000ff]Loop
[/COLOR][B]counter = 1
countto = Sally.intGlads
[/B][COLOR=#0000ff]Do[/COLOR][COLOR=#0000ff]While[/COLOR][B] (counter <= countto)
PlantCheck()
txtDisplay.Text &= [/B][COLOR=#800000]"Sally Gladiolus"[/COLOR][B] & ControlChars.NewLine
counter += 1
plants += 1
[/B][B][/B][COLOR=#0000ff]Loop
[/COLOR][B]counter = 1
countto = Sally.intIrises
[/B][COLOR=#0000ff]Do[/COLOR][COLOR=#0000ff]While[/COLOR][B] (counter <= countto)
PlantCheck()
txtDisplay.Text &= [/B][COLOR=#800000]"Sally Iris"[/COLOR][B] & ControlChars.NewLine
counter += 1
plants += 1
[/B][B][/B][COLOR=#0000ff]Loop
[/COLOR][B][/B][COLOR=#0000ff]End[/COLOR][COLOR=#0000ff]Sub
[/COLOR][B][/B][COLOR=#0000ff]Public[/COLOR][COLOR=#0000ff]Sub[/COLOR][B] BillyPlants()
[/B][COLOR=#0000ff]Dim[/COLOR][B] counter [/B][COLOR=#0000ff]As[/COLOR][COLOR=#0000ff]Integer
[/COLOR][B][/B][COLOR=#0000ff]Dim[/COLOR][B] countto [/B][COLOR=#0000ff]As[/COLOR][COLOR=#0000ff]Integer
[/COLOR][B]counter = 1
countto = Billy.intPetunias
[/B][COLOR=#0000ff]Do[/COLOR][COLOR=#0000ff]While[/COLOR][B] counter <= countto
PlantCheck()
txtDisplay.Text &= [/B][COLOR=#800000]"Billy Petunia"[/COLOR][B] & ControlChars.NewLine
counter += 1
plants += 1
[/B][B][/B][COLOR=#0000ff]Loop
[/COLOR][B]counter = 1
countto = Billy.intGlads
[/B][COLOR=#0000ff]Do[/COLOR][COLOR=#0000ff]While[/COLOR][B] counter <= countto
PlantCheck()
txtDisplay.Text &= [/B][COLOR=#800000]"Billy Gladiolus"[/COLOR][B] & ControlChars.NewLine
counter += 1
plants += 1
[/B][B][/B][COLOR=#0000ff]Loop
[/COLOR][B]counter = 1
countto = Billy.intIrises
[/B][COLOR=#0000ff]Do[/COLOR][COLOR=#0000ff]While[/COLOR][B] counter <= countto
PlantCheck()
txtDisplay.Text &= [/B][COLOR=#800000]"Billy Iris"[/COLOR][B] & ControlChars.NewLine
counter += 1
plants += 1
[/B][B][/B][COLOR=#0000ff]Loop
[/COLOR][B][/B][COLOR=#0000ff]End[/COLOR][COLOR=#0000ff]Sub
[/COLOR][B][/B][COLOR=#0000ff]Public[/COLOR][COLOR=#0000ff]Sub[/COLOR][B] PlantCheck()
[/B][COLOR=#0000ff]If[/COLOR][B] plants = 18 [/B][COLOR=#0000ff]Then
[/COLOR][B]txtDisplay.Text &= [/B][COLOR=#800000]"--- NEW BOX ---"
[/COLOR][B]txtDisplay.Text &= ControlChars.NewLine
plants = 0
[/B][COLOR=#0000ff]End[/COLOR][COLOR=#0000ff]If
[/COLOR][B][/B][COLOR=#0000ff]End[/COLOR][COLOR=#0000ff]Sub
End[/COLOR][COLOR=#0000ff]Class
[/COLOR]

this works for now but still if anyone help me out with how to create a new textbox per 18 plants that would be cool
 
Last edited:
Back
Top