V
VB Novice Hendri
Guest
I have some trouble as how to setup a loop correctly. The loop has to create a series of labels, a max of 50 as seen in the code below, as thy are created thy mast be databound to a corosponding data colum.
This above is my main question.
Dim ActiveContent As String = "Con" + ContentCount this line gives me a error.
Conversion from string "CON" to type "Double" is not valid.
Public Property ID As Integer
Public Property RecipeName As String
Public Property Comment As String
Public Property Quantity As String
Public Property Con1 As String
Public Property Con2 As String
Public Property Con3 As String
Public Property Con4 As String
Public Property Con5 As String
Public Property Con6 As String
Public Property Con7 As String
Public Property Con8 As String
Public Property Con9 As String
Public Property Con10 As String
Public Property Con11 As String
Public Property Con12 As String
Public Property Con13 As String
Public Property Con14 As String
Public Property Con15 As String
Public Property Con16 As String
Public Property Con17 As String
Public Property Con18 As String
Public Property Con19 As String
Public Property Con20 As String
Public Property Con21 As String
Public Property Con22 As String
Public Property Con23 As String
Public Property Con24 As String
Public Property Con25 As String
Public Property Con26 As String
Public Property Con27 As String
Public Property Con28 As String
Public Property Con29 As String
Public Property Con30 As String
Public Property Con31 As String
Public Property Con32 As String
Public Property Con33 As String
Public Property Con34 As String
Public Property Con35 As String
Public Property Con36 As String
Public Property Con37 As String
Public Property Con38 As String
Public Property Con39 As String
Public Property Con40 As String
Public Property Con41 As String
Public Property Con42 As String
Public Property Con43 As String
Public Property Con44 As String
Public Property Con45 As String
Public Property Con46 As String
Public Property Con47 As String
Public Property Con48 As String
Public Property Con49 As String
Public Property Con50 As String
Public Property Notes As String
Public Property ImageSize As String
Public Property ImageLocation As String
Function ActiveContent() As String
Throw New NotImplementedException
End Function
End Class
The loop below is oviosly not working as is, this is where the real help is needed.
Private recipesLst As List(Of Recipe) = New List(Of Recipe)()
Dim recipeSelected As String = TitleListBox.SelectedItem.ToString()
Dim result = recipesLst.Where(Function(x) x.RecipeName = recipeSelected).FirstOrDefault()
'Form1.TextBox1.Text = result.ID.ToString()
With Form1.RecipeNameLabel
.Text = result.RecipeName
.Visible = True
End With
Form1.Label1.Text = Form1.RecipeNameLabel.Size.ToString
With Form1.CommentLabel
.Font = New System.Drawing.Font("Arial", 7)
.Text = result.Comment
.Location = New Point(Form1.RecipeNameLabel.Left, Form1.RecipeNameLabel.Bottom + 10)
.Visible = True
End With
X = Form1.CommentLabel.Left
Y = Form1.CommentLabel.Bottom + 10
With Form1.QuantityLabel
.Font = New System.Drawing.Font("Arial", 7)
.Text = result.Quantity
.Location = New Point(Form1.RecipeNameLabel.Right - Form1.QuantityLabel.Width, Form1.CommentLabel.Bottom - Form1.QuantityLabel.Height)
.Visible = True
End With
Dim ContentCount As Integer = 1
Dim ActiveContent As String = "Con" + ContentCount
Do While "Con" Colum is not empty
Dim ContentLabel As New Label()
With ContentLabel
.Font = New System.Drawing.Font("Arial", 7)
.Text = result.ActiveContent
If ContentLabel.Text.Contains(":") Then
.Font = New System.Drawing.Font("Arial", 11, FontStyle.Bold)
Y = Y + 10
End If
If ContentLabel.Text <> "" Then
.Location = New Point(X, Y)
.Visible = True
End If
End With
Controls.Add(ContentLabel)
X = ContentLabel.Left
Y = ContentLabel.Bottom + 1
ContentCount = ContentCount + 1
Loop
Continue reading...
This above is my main question.
Dim ActiveContent As String = "Con" + ContentCount this line gives me a error.
Conversion from string "CON" to type "Double" is not valid.
Public Property ID As Integer
Public Property RecipeName As String
Public Property Comment As String
Public Property Quantity As String
Public Property Con1 As String
Public Property Con2 As String
Public Property Con3 As String
Public Property Con4 As String
Public Property Con5 As String
Public Property Con6 As String
Public Property Con7 As String
Public Property Con8 As String
Public Property Con9 As String
Public Property Con10 As String
Public Property Con11 As String
Public Property Con12 As String
Public Property Con13 As String
Public Property Con14 As String
Public Property Con15 As String
Public Property Con16 As String
Public Property Con17 As String
Public Property Con18 As String
Public Property Con19 As String
Public Property Con20 As String
Public Property Con21 As String
Public Property Con22 As String
Public Property Con23 As String
Public Property Con24 As String
Public Property Con25 As String
Public Property Con26 As String
Public Property Con27 As String
Public Property Con28 As String
Public Property Con29 As String
Public Property Con30 As String
Public Property Con31 As String
Public Property Con32 As String
Public Property Con33 As String
Public Property Con34 As String
Public Property Con35 As String
Public Property Con36 As String
Public Property Con37 As String
Public Property Con38 As String
Public Property Con39 As String
Public Property Con40 As String
Public Property Con41 As String
Public Property Con42 As String
Public Property Con43 As String
Public Property Con44 As String
Public Property Con45 As String
Public Property Con46 As String
Public Property Con47 As String
Public Property Con48 As String
Public Property Con49 As String
Public Property Con50 As String
Public Property Notes As String
Public Property ImageSize As String
Public Property ImageLocation As String
Function ActiveContent() As String
Throw New NotImplementedException
End Function
End Class
The loop below is oviosly not working as is, this is where the real help is needed.
Private recipesLst As List(Of Recipe) = New List(Of Recipe)()
Dim recipeSelected As String = TitleListBox.SelectedItem.ToString()
Dim result = recipesLst.Where(Function(x) x.RecipeName = recipeSelected).FirstOrDefault()
'Form1.TextBox1.Text = result.ID.ToString()
With Form1.RecipeNameLabel
.Text = result.RecipeName
.Visible = True
End With
Form1.Label1.Text = Form1.RecipeNameLabel.Size.ToString
With Form1.CommentLabel
.Font = New System.Drawing.Font("Arial", 7)
.Text = result.Comment
.Location = New Point(Form1.RecipeNameLabel.Left, Form1.RecipeNameLabel.Bottom + 10)
.Visible = True
End With
X = Form1.CommentLabel.Left
Y = Form1.CommentLabel.Bottom + 10
With Form1.QuantityLabel
.Font = New System.Drawing.Font("Arial", 7)
.Text = result.Quantity
.Location = New Point(Form1.RecipeNameLabel.Right - Form1.QuantityLabel.Width, Form1.CommentLabel.Bottom - Form1.QuantityLabel.Height)
.Visible = True
End With
Dim ContentCount As Integer = 1
Dim ActiveContent As String = "Con" + ContentCount
Do While "Con" Colum is not empty
Dim ContentLabel As New Label()
With ContentLabel
.Font = New System.Drawing.Font("Arial", 7)
.Text = result.ActiveContent
If ContentLabel.Text.Contains(":") Then
.Font = New System.Drawing.Font("Arial", 11, FontStyle.Bold)
Y = Y + 10
End If
If ContentLabel.Text <> "" Then
.Location = New Point(X, Y)
.Visible = True
End If
End With
Controls.Add(ContentLabel)
X = ContentLabel.Left
Y = ContentLabel.Bottom + 1
ContentCount = ContentCount + 1
Loop
Continue reading...