none
Problem using a Varient. RRS feed

  • Question

  • Hi there. 

    Please have a look at the bottom part of the code:  ".Text = result.ActiveContent"  I'v aded comments there.  

    That code block will allso be repeating, but leave that for a next post.  

     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 = ContentFont
                            .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 = ContentFont
                            .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
    
                        Dim ContentLabel As New Label()
                        With ContentLabel
                            .Text = result.ActiveContent  'This Variant represents "Con1" or "Con2" etc. But it don't work, this wher I need help. 
                            If ContentLabel.Text.Contains(":") Then
                                .Font = New System.Drawing.Font("Comic Sans MS", 12, FontStyle.Bold)
                            Else
                                .Font = New System.Drawing.Font("Comic Sans MS", 12, FontStyle.Regular)
                            End If
                            .Location = New Point(X, Y)
                        End With
                        Controls.Add(ContentLabel)
    
                        X = ContentLabel.Left
                        Y = ContentLabel.Bottom + 1
                        ContentCount = ContentCount + 1

    Friday, February 14, 2020 9:06 AM

Answers

  • I dont know what you mean.
    Dim ContentCount As Integer = 1
    Dim ActiveContent As String = "Con" + ContentCount
    
    Dim ContentLabel As New Label()
    With ContentLabel
    	.Text = ActiveContent  'This Variant represents "Con1" or "Con2" etc. But it don't work, this wher I need help. 
    	If ContentLabel.Text.Contains(":") Then
    		.Font = New System.Drawing.Font("Comic Sans MS", 12, FontStyle.Bold)
    	Else
    		.Font = New System.Drawing.Font("Comic Sans MS", 12, FontStyle.Regular)
    	End If
    	.Location = New Point(X, Y)
    End With
    Controls.Add(ContentLabel)
    
    X = ContentLabel.Left
    Y = ContentLabel.Bottom + 1
    ContentCount = ContentCount + 1
    
    




    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange


    Friday, February 14, 2020 12:44 PM
    Moderator

All replies

  • Hi,
    try:

    .Text = result?.ActiveContent?.ToString()


    --
    Best Regards / Viele Grüße
    Peter Fleischer (former MVP for Developer Technologies)
    Homepage, Tipps, Tricks


    Friday, February 14, 2020 9:50 AM
  • Still gives me the error can not be converted to string.
    Friday, February 14, 2020 10:00 AM
  • Hi,
    show declaration of recipesLst.

    --
    Best Regards / Viele Grüße
    Peter Fleischer (former MVP for Developer Technologies)
    Homepage, Tipps, Tricks

    Friday, February 14, 2020 10:10 AM
  • Public Class Recipe
    
        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
    End Class

     Private recipesLst As List(Of Recipe) = New List(Of Recipe)()

    Friday, February 14, 2020 10:21 AM
  • Hi,
    there's no ActiveContent.

    Please, Set OPTION STRICT ON !


    --
    Best Regards / Viele Grüße
    Peter Fleischer (former MVP for Developer Technologies)
    Homepage, Tipps, Tricks


    Friday, February 14, 2020 10:27 AM
  • Is this what you looking for.

    Dim ContentCount As Integer = 1
    Dim ActiveContent As String = "Con" + ContentCount

    Friday, February 14, 2020 10:32 AM
  • Either add the property to the class or use this.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Friday, February 14, 2020 10:37 AM
    Moderator
  • I dont know what you mean.
    Friday, February 14, 2020 12:29 PM
  • I dont know what you mean.
    Dim ContentCount As Integer = 1
    Dim ActiveContent As String = "Con" + ContentCount
    
    Dim ContentLabel As New Label()
    With ContentLabel
    	.Text = ActiveContent  'This Variant represents "Con1" or "Con2" etc. But it don't work, this wher I need help. 
    	If ContentLabel.Text.Contains(":") Then
    		.Font = New System.Drawing.Font("Comic Sans MS", 12, FontStyle.Bold)
    	Else
    		.Font = New System.Drawing.Font("Comic Sans MS", 12, FontStyle.Regular)
    	End If
    	.Location = New Point(X, Y)
    End With
    Controls.Add(ContentLabel)
    
    X = ContentLabel.Left
    Y = ContentLabel.Bottom + 1
    ContentCount = ContentCount + 1
    
    




    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange


    Friday, February 14, 2020 12:44 PM
    Moderator