Visual Basic Save

For all the programmers in here, another question. I want my comboboxlist to be opened from a text file. My program also contains a function which has a textbox where you can write a text in, and then press a button "add" so it adds to the comboboxlist. Now I want the program to have a save button, so it will load any changed made in the past.

It should only load the folders with the text "Productiecontrole" in front of it, so it will be like "Productiecontrole Variable.

The savebutton is at Private Sub CommandButton5_Click()

Here's the code:

QuotePrivate Sub CommandButton1_Click()

Dim StrFolder As String
StrFolder = ComboBox1.Text
Shell ("Explorer.exe \\Hhnfs-01\hhn\HHN_Technology\Meetcentrum\Meten\Productiecontrole " & StrFolder)
End Sub

Private Sub CommandButton2_Click()
Form2.Hide
End Sub

Private Sub CommandButton3_Click()
ComboBox1.AddItem TextBox1.Text
StrFolder = TextBox1.Text
MkDir ("\\Hhnfs-01\hhn\HHN_Technology\Meetcentrum\Meten\Productiecontrole " & StrFolder)
End Sub

Private Sub CommandButton4_Click()
TextBox1.Text = ""
End Sub

Private Sub CommandButton5_Click()


End Sub

Private Sub UserForm_Activate()
ComboBox1.Clear
ComboBox1.AddItem "Assemblage"
ComboBox1.AddItem "Kunststof"
ComboBox1.AddItem "LSR"
ComboBox1.AddItem "Pers"
ComboBox1.AddItem "Persnabewerking"
End Sub


Thanks in advance!!!
Comments
23
Quote#Region "File IO"

Private Sub openToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles openToolStripMenuItem.Click

' configure the open file dialog to point to some
' common (usable) image file formats
openFileDialog1.Title = "Open Image File"
openFileDialog1.Filter = "Bitmap Files|*.bmp" & _
"|Enhanced Windows MetaFile|*.emf" & _
"|Exchangeable Image File|*.exif" & _
"|Gif Files|*.gif|JPEG Files|*.jpg" & _
"|PNG Files|*.png|TIFF Files|*.tif|Windows MetaFile|*.wmf"
openFileDialog1.DefaultExt = "bmp"
openFileDialog1.FilterIndex = 1
openFileDialog1.FileName = ""
openFileDialog1.ShowDialog()

' if the user did not select a file, return
If (openFileDialog1.FileName = "") Then Return

' update the current file and form caption text
CurrentFile = openFileDialog1.FileName.ToString()
Me.Text = "Watermark Utility: " & CurrentFile.ToString()

Try
' open the image into the picture box
img = Image.FromFile(openFileDialog1.FileName, True)
picContainer.Image = img

' resize the picture box to support scrolling
' large images
picContainer.Size = img.Size

Catch ex As Exception

MessageBox.Show(ex.Message, "File Open Error")
End Try

End Sub

Private Sub btnSave_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnSave.Click

Try
' get the extension to figure out how to limit the save
' option to the current image file type
Dim strExt As String
strExt = System.IO.Path.GetExtension(CurrentFile)
strExt = strExt.ToUpper()
strExt = strExt.Remove(0, 1)

' if the current image is, for example, a GIF, only
' allow the user to save the file with the watermark
' as a GIF
SaveFileDialog1.Title = "Save File"
SaveFileDialog1.DefaultExt = strExt
SaveFileDialog1.Filter = strExt & " Image Files|*." + strExt
SaveFileDialog1.FilterIndex = 1

If SaveFileDialog1.ShowDialog() = DialogResult.OK Then
If (SaveFileDialog1.FileName = "") Then
Return
Else
' save the file with the name supplied by the user
picContainer.Image.Save(SaveFileDialog1.FileName)
End If

' update the current image file to point to the newly saved
' image
CurrentFile = SaveFileDialog1.FileName
Me.Text = "Watermark Utility: " + CurrentFile
MessageBox.Show(CurrentFile.ToString() + " saved.", "File
Save")
Else
MessageBox.Show("The save file request was cancelled by
user.", "Save Cancelled")
End If

Catch ex As Exception
MessageBox.Show(ex.Message.ToString(), "Image Save Error")
End Try

End Sub

#End Region
achterhaald en langzaam :z
You can work with a database or some textfile.
Read & write (save button) to the textfile and use its content to update the combobox.

Make some function and recall it to re-initialise (update) the combobox everytime some data in the txt/database file changed.
Well, the problem is, it's a database for the ppl here at work, so they can't all keep changing the text file. I just have a basiclist which I can make one for, that's no problem, but other list items might be added later (I built in a function for that), and I want those to autoload next time too.

How can I export my current list to a textfile and load it next time again?
Parent
Should it work if I add this code? Coz it doesn't ^^

QuotePrivate Sub UserForm_Load()

Dim tekstbestand As String
tekstbestand = App.Path & "\\Hhnfs-01\hhn\HHN_Technology\Meetcentrum\Meten\Jan-Willem\Archiveren\productiecontrole.txt"
Open tekstbestand For Input As #1
Open tekstbestand For Append As #1

ActiveDocument.FormFields("ComboBox1").DropDown
For i = 1 To .ListEntries.Count
Print #1, .ListEntries(i).Name
Next i
End With

Close #1

End Sub


And in the Textfile I've added this:

QuoteLSR
Debug step by step :)
Use breakpoints to stop the code and use F8 (or whatever your next step shortcut is) to loop through the code
Parent
well, it doesn't give errors or anything, it just doesn't load the item I've added into my textfile to the combobox

sorry for asking so much questions, but this is all really new for me ^^
Parent
Try it without the network path first
just make some c:\test.txt file and see how he handles that

Try this on form load:

Dim strInRec As String
Open "c:\test.txt" For Input As #1
Do Until EOF(1)
Line Input #1, strInRec
ComboBox1.AddItem strInRec
Loop
Close #1
Parent
WORKS :D

thx
Parent
Ugh, Visual Basic.
do people still use vb? :<
you want to access and write/read the file at the same time from more than one pc/thread/process? in that case you really need file locking...
Local network.

I'm writing an archive system, because the current archiving sucks. I built a little screen for 1 section we call "productiecontrole", and I have a combobox with several products, all starting with the mapname "Productiecontrole". So it's like "Productiecontrole LSR", or "Productiecontrole Kunststoffen", etc... Now I need those in a textfile, and that it automatically loads that textfile to the program itself everytime I start it. Also I want a save button, if I add something to the list, so it loads that new thing in the list again next time (added and add function). So basically I just need a save function, it's a bit hard to explain but I guess u know what I mean ^^
Parent
Dim uwtxt As String

Private Sub Form_Load()
uwtxt = "c:\test.txt"
Open uwtxt For Input As #1
While Not EOF(1)
Line Input #1, temp
Combobox1.AddItem temp
Wend
Close #1
End Sub


// SAVE FUNCTION BIJ FORM UNLOAD **
// Waardes van combo schrijven naar .txt

Private Sub Form_Unload(Cancel As Integer)
Open uwtxt For Output As #1
Dim x As Integer
For x = 0 To Combobox1.ListCount
Print #1, Combobox1.List(x)
Next x
Close #1
End Sub
Parent
Ik snap wat je bedoelt maar als bijv één pc een line naar de textfile schrijft en dan saved en dan schrijft de andere pc een line naar de text file dan werkt dat niet lekker.
Parent
just replace:
Open uwtxt For Input/Output As #1
by
Open uwtxt For Binary Access Write Lock Read Write As #1

Or you can write some better check using FILE_NOTIFY_FLAGS but that's a bit too advanced for a VB6 beginner like spree
Parent
Hmm, weird, the save function works properly (it adds to the text file, and loads it again next time I open the program). But every time I close the program it still gives a bug at this line:

QuotePrint #1, ComboBox1.List(x)


Kinda weird, coz it just works. Also, I don't see anything wrong with this line, maybe you know?
Parent
Add "on error resume next" to avoid the warning :D
Parent
cud do that, but then prolly when I open the program on another pc it will just show the error again -.-
Parent
Sounds & looks really professional :D
especially since I program for only 2 days now!
Parent
Back to top