Oppure

Loading
05/02/12 9:40
Cobra
Ciao ragazzi,
attraverso l'uso di steamwriter e streamreader sto creando un programma in vb.net che mi permetta di settare varie impostazioni in un file di testo. Vorrei sapere, è possibile nascondere parte di testo visualizzato in una label? Cioè, faccio un esempio pratico e poi posto il codice per essere quanto più chiaro possibile. Ipotizziamo che abbia nel documento di testo la seguente riga:

Opzione 1 = Ciao

è possibile visualizzare nella label solo la parola "Ciao"?

Eccovi il codice:

Imports System
Imports System.IO
Imports Microsoft.VisualBasic

Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TextBox1.TabIndex = 0
        TextBox2.TabIndex = 1
        TextBox3.TabIndex = 2
        TextBox4.TabIndex = 3
        TextBox5.TabIndex = 4
        Button1.TabIndex = 5
        Button2.TabIndex = 6
        Timer1.Start()
        Timer1.Interval = 1
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim sw As System.IO.StreamWriter
        sw = IO.File.CreateText("C:\Impostazioni.txt")
        sw.WriteLine(Chr(91) & Label1.Text & Chr(93))
        sw.WriteLine(Label2.Text & " " & Chr(61) & " " & TextBox1.Text())
        sw.WriteLine(Label3.Text & " " & Chr(61) & " " & TextBox2.Text())
        sw.WriteLine(Label4.Text & " " & Chr(61) & " " & TextBox3.Text())
        sw.WriteLine(Label5.Text & " " & Chr(61) & " " & TextBox4.Text())
        sw.WriteLine(Label6.Text & " " & Chr(61) & " " & TextBox5.Text())
        sw.Flush()
        sw.Close()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'Pulsante per ottenere il settaggio predefinito delle impostazioni
        Dim sw As System.IO.StreamWriter
        sw = IO.File.CreateText("C:\Impostazioni.txt")
        sw.WriteLine(Chr(91) & Label1.Text & Chr(93))
        sw.WriteLine(Label2.Text & " " & Chr(61) & " " & "Predefinita 1")
        sw.WriteLine(Label3.Text & " " & Chr(61) & " " & "Predefinita 2")
        sw.WriteLine(Label4.Text & " " & Chr(61) & " " & "Predefinita 3")
        sw.WriteLine(Label5.Text & " " & Chr(61) & " " & "Predefinita 4")
        sw.WriteLine(Label6.Text & " " & Chr(61) & " " & "Predefinita 5")
        sw.WriteLine(Label12.Text & " " & Chr(61) & " " & "Predefinita 5")
        sw.Flush()
        sw.Close()
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
'Utilizzo il timer per visualizzare in tempo reale le impostazioni contenute all'interno del file
        Dim file As New StreamReader("C:\Impostazioni.txt")
        Label7.Text = file.ReadLine()
        Label8.Text = file.ReadLine()
        Label9.Text = file.ReadLine()
        Label10.Text = file.ReadLine()
        Label11.Text = file.ReadLine()
        Label12.Text = file.ReadLine()
        file.Close()
    End Sub
End Class


Rimanendo in attesa di vostre risposte, auguro a tutti una felice domenica :k: :k: :k:
aaa
05/02/12 9:49
Ma tu sai cosa sia una

variabile?

Penso di sì, perché altrimenti non potresti scrivere programmi.

Quindi usa una variabile per leggere la linea (con la ReadLine) e copia la parte della variabile che ti serve nella Label.
05/02/12 9:55
Usa il metodo remove.

Remove(I, L) : rimuove dalla stringa tutti i caratteri a partire dall'indice I, opzionalmente specificandone anche il numero L

Esempio: Ciao 1

 Label1.Text = "ciao 1"
Label1.Text = Label1.Text.Remove(4)
05/02/12 13:23
Cobra
Grazie, tutto ok ;)
aaa