dcsimg
Results 1 to 4 of 4

Thread: [SOLVED] make a list with 16 label.txt and create a txt file!

  1. #1

    Thread Starter
    Member
    Join Date
    May 2017
    Posts
    50

    Resolved [SOLVED] make a list with 16 label.txt and create a txt file!

    hello everybody,happy new year 2019
    my problem is a easy but i am a beginner in coding.
    so, i have 16 differrents label.text and i would like to put them in text file like a list.
    for example:
    label1.text
    label2.text
    label3.text
    label4.text
    etc... the final result will be like that:
    marc
    paul
    linda
    michael
    etc...
    here is! thank you for your answer !
    Last edited by danzey; Jan 13th, 2019 at 07:04 PM.

  2. #2
    Fanatic Member cory_jackson's Avatar
    Join Date
    Dec 2011
    Location
    Fallbrook, California
    Posts
    724

    Re: [HELP CODING] make a list with 16 label.txt and create a txt file![easy]

    I prefer to use the FileInfo.CreateText Method. It creates a StreamWriter that you can use to write lines of text to a file. Click here to see how to use the StreamWriter. FileInfo is an object that represents a file. CreateText is a method of that class to create the StreamWriter.

  3. #3
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,535

    Re: [HELP CODING] make a list with 16 label.txt and create a txt file![easy]

    Put all Labels in a Panel container then use the following code
    Code:
    Option Strict On
    Option Explicit On
    
    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            IO.File.WriteAllText("F:\lbl.txt", GetLabelsText(Panel1, 16))
        End Sub
    
        Private Function GetLabelsText(cContainer As Panel, intCount As Integer) As String
            Dim sb As New Text.StringBuilder
            Dim lbl As Label
            For i = 0 To intCount
                lbl = CType(cContainer.Controls("Label" & i), Label)
                If lbl IsNot Nothing Then
                    sb.AppendLine(lbl.Text)
                End If
            Next
            Return sb.ToString
        End Function
    End Class



  4. #4

    Thread Starter
    Member
    Join Date
    May 2017
    Posts
    50

    Resolved Re: [HELP CODING] make a list with 16 label.txt and create a txt file![solved]

    Quote Originally Posted by 4x2y View Post
    Put all Labels in a Panel container then use the following code
    Code:
    Option Strict On
    Option Explicit On
    
    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            IO.File.WriteAllText("F:\lbl.txt", GetLabelsText(Panel1, 16))
        End Sub
    
        Private Function GetLabelsText(cContainer As Panel, intCount As Integer) As String
            Dim sb As New Text.StringBuilder
            Dim lbl As Label
            For i = 0 To intCount
                lbl = CType(cContainer.Controls("Label" & i), Label)
                If lbl IsNot Nothing Then
                    sb.AppendLine(lbl.Text)
                End If
            Next
            Return sb.ToString
        End Function
    End Class
    Thank you so much !!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width