Opslaan als en Openen

Status
Niet open voor verdere reacties.
OK voorbeeld bestandje probeer eens uit.
Textboxen invullen en op de button klikken.
 

Bijlagen

Ja heb ik gedaan, zal het zo nog even een keer goed doorlezen zit momenteel in de auto.
 
Volgens mij wou hij opslaan.


Probeer dit eens bij elke textbox of label die je wilt bewaren

Code:
 Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        My.Settings.Limo = TextBox1.Text
        My.Settings.Save()
    End Sub

   
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TextBox1.Text = My.Settings.Limo
    End Sub

Dit kan je vinden onder
Project
Naam van je project Properties
Settings ( dan maak je Limo van wat er nu staat enz)

Of anders weg schijven naar bestand en dan save en steeds weer laden.
 
@Koppelstukje: Ja, maar dan moet je heel veel settings aanmaken. En als iemand het programma op een andere computer wil gebruiken, is alles weg ;). Een .INI-Bestand kun je overal mee naartoe nemen & back-uppen. ;)
 
ik zou het zo doen

zet het in een listview en selecteer wat je wild zien.
en je hebt alle gegevens.

dan kan je snel even kijken wat je wil.

voor beeld bestandje
 

Bijlagen

Ja hier heb ik wel wat aan.
Dat andere begrijp ik nog niet echt veel van, heb het al een paar keer door gelezen.
Ik heb ook nog niet zoveel ervaring met VB, dus dat komt later wel.
Allemaal bedankt voor jullie hulp.....
 
Heb je het voorbeeldproject (klik) al gedownload? Als je die code bestudeerd snap je het toch wel?

Hier nog eens in het kort:

Stap 1:
Class toevoegen (met de naam IniFile) met de volgende code: (gewoon knippen en plakken ;))

Code:
Public Class IniFile
    ' API functions
    Private Declare Ansi Function GetPrivateProfileString _
      Lib "kernel32.dll" Alias "GetPrivateProfileStringA" _
      (ByVal lpApplicationName As String, _
      ByVal lpKeyName As String, ByVal lpDefault As String, _
      ByVal lpReturnedString As System.Text.StringBuilder, _
      ByVal nSize As Integer, ByVal lpFileName As String) _
      As Integer
    Private Declare Ansi Function WritePrivateProfileString _
      Lib "kernel32.dll" Alias "WritePrivateProfileStringA" _
      (ByVal lpApplicationName As String, _
      ByVal lpKeyName As String, ByVal lpString As String, _
      ByVal lpFileName As String) As Integer
    Private Declare Ansi Function GetPrivateProfileInt _
      Lib "kernel32.dll" Alias "GetPrivateProfileIntA" _
      (ByVal lpApplicationName As String, _
      ByVal lpKeyName As String, ByVal nDefault As Integer, _
      ByVal lpFileName As String) As Integer
    Private Declare Ansi Function FlushPrivateProfileString _
      Lib "kernel32.dll" Alias "WritePrivateProfileStringA" _
      (ByVal lpApplicationName As Integer, _
      ByVal lpKeyName As Integer, ByVal lpString As Integer, _
      ByVal lpFileName As String) As Integer
    Dim strFilename As String

    ' Constructor, accepting a filename
    Public Sub New(ByVal Filename As String)
        strFilename = Filename
    End Sub

    ' Read-only filename property
    ReadOnly Property FileName() As String
        Get
            Return strFilename
        End Get
    End Property

    Public Function GetString(ByVal Section As String, _
      ByVal Key As String, ByVal [Default] As String) As String
        ' Returns a string from your INI file
        Dim intCharCount As Integer
        Dim objResult As New System.Text.StringBuilder(256)
        intCharCount = GetPrivateProfileString(Section, Key, _
           [Default], objResult, objResult.Capacity, strFilename)
        If intCharCount > 0 Then GetString = _
           Left(objResult.ToString, intCharCount)
    End Function

    Public Function GetInteger(ByVal Section As String, _
      ByVal Key As String, ByVal [Default] As Integer) As Integer
        ' Returns an integer from your INI file
        Return GetPrivateProfileInt(Section, Key, _
           [Default], strFilename)
    End Function

    Public Function GetBoolean(ByVal Section As String, _
      ByVal Key As String, ByVal [Default] As Boolean) As Boolean
        ' Returns a boolean from your INI file
        Return (GetPrivateProfileInt(Section, Key, _
           CInt([Default]), strFilename) = 1)
    End Function

    Public Sub WriteString(ByVal Section As String, _
      ByVal Key As String, ByVal Value As String)
        ' Writes a string to your INI file
        WritePrivateProfileString(Section, Key, Value, strFilename)
        Flush()
    End Sub

    Public Sub WriteInteger(ByVal Section As String, _
      ByVal Key As String, ByVal Value As Integer)
        ' Writes an integer to your INI file
        WriteString(Section, Key, CStr(Value))
        Flush()
    End Sub

    Public Sub WriteBoolean(ByVal Section As String, _
      ByVal Key As String, ByVal Value As Boolean)
        ' Writes a boolean to your INI file
        WriteString(Section, Key, CStr(CInt(Value)))
        Flush()
    End Sub

    Private Sub Flush()
        ' Stores all the cached changes to your INI file
        FlushPrivateProfileString(0, 0, 0, strFilename)
    End Sub

End Class

Stap 2:
Zo je .INI declareren:

Code:
Dim INI As New IniFile("Pad naar je .INI") 'bijvoorbeeld ergens in Temp o.i.d.

Stap 3:
Zo schrijven naar je .INI:

Code:
INI.WriteString("Aantal_Flessen","Cola","10")

Je INI ziet er dan zo uit:

Code:
[Aantal_Flessen]
Cola=10

Zo informatie uit je .INI ophalen:

Code:
Dim Aantal As String = INI.GetString("Aantal_Flessen","Cola","")

Hier zal (in dit voorbeeld) Aantal de waarde "10" krijgen.

(Ik raad je aan om alleen 'GetString' te gebruiken omdat je anders last krijg met conversiefouten)


Als je het niet snapt: Bij welke stap heb je problemen?
 
Laatst bewerkt:
Beste JoZ1
ik denk dat hij niet zo goed weet waar je de code moet plaatsen.
van daar mijn voorbeeldje van jouw ini.

in textbox3.text zet je het pad waar je de ini wil hebben.
bv. C:\users\schippertje\hier de naam hoe je hem wild opslaan. bv. 21-07-2011.ini

hopelijk kom je zo verder.

Code:
  Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim open As New OpenFileDialog
        open.Title = "Selecteer een .INI"
        open.Filter = "INI - Bestanden (*.ini)|*.ini|Alle Bestanden (*.*)|*.*"
        If open.ShowDialog = Windows.Forms.DialogResult.OK Then
            TextBox3.Text = open.FileName
        End If
    End Sub


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ini As New IniFile(TextBox3.Text)

        ini.WriteString("Aantal_Flessen", "Cola", TextBox1.Text)
        INI.WriteString("Aantal_Flessen", "Sisi", TextBox2.Text)

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim ini As New IniFile(TextBox3.Text)

        TextBox1.Text = ini.GetString("Aantal_Flessen", "Cola", "")
        TextBox2.Text = INI.GetString("Aantal_Flessen", "sisi", "")
    End Sub
 

Bijlagen

  • iniForm.JPG
    iniForm.JPG
    18,6 KB · Weergaven: 23
Bedankt old Hippy, ik denk dat je gelijk hebt :thumb:.
 
Hi set dit op de plaats van de warring

Code:
 Public Function GetString(ByVal Section As String, _
     ByVal Key As String, ByVal [Default] As String) As String
        Dim retString As String = "" ' or use Nothing instead of ""
        ' Returns a string from your INI file
        Dim intCharCount As Integer
        Dim objResult As New System.Text.StringBuilder(256)
        intCharCount = GetPrivateProfileString(Section, Key, _
           [Default], objResult, objResult.Capacity, strFilename)
        If intCharCount > 0 Then
            retString = Left(objResult.ToString, intCharCount)
        End If

        Return retString
    End Function


Knipsel.JPG
 
Laatst bewerkt:
Ja super geeft nou helemaal geen warning meer aan.
Heb je trouwens mooi gemaakt dat drink programma.
In ieder geval hartstikke bedankt voor ieder zn hulp.:thumb:
 
Ziet er inderdaad goed uit, old Hippy! Die pictogrammen komen zeker uit de VSImageLibrary? ;)

@Schippertje: Goed dat het is opgelost! Kun je a.u.b. de vraag op opgelost zetten? :)
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan