PDA

View Full Version : visual basic prob



car'a'carn
17th November 2006, 05:07 PM
This is a school thingy and i will get points on this (so if you think this is against the rules, don't reply). We've been making a little program lately. it has to put items in a listbox, the items are given in or calculated. For some reason I can't figure out how to make both the OPEN and the ADD LINE to work at the same time. The following will be the code I used for the commands. I hope one of you guys can explain to me what I'm doing wrong.

Public Function Omzetting(ByVal strnaam As String, ByVal strvoornaam As String, ByVal strnederlands As String, ByVal strfrans As String, ByVal strwiskunde As String, ByVal strinformatica As String, ByVal strgemiddelde As String, ByVal strtotaal As String) As String

Omzetting = (strnaam & Space(15 - Len(strnaam)) & strvoornaam & Space(15 - Len(strvoornaam)) & strnederlands & Space(5 - Len(strnederlands)) & strfrans & Space(5 - Len(strfrans)) & strwiskunde & Space(5 - Len(strwiskunde)) & strinformatica & Space(5 - Len(strinformatica)) & strtotaal & Space(8 - Len(strtotaal)) & strgemiddelde)
End Function

Private Sub cmdToevoegen_Click()
Dim line As String


line = Omzetting(txtnaam.Text, txtvoornaam.Text, txtnederlands.Text, txtFrans.Text, txtinformatica.Text, txtwiskunde.Text, txtTotaal.Text, txtGemiddelde.Text)

If txtTotaal = "" Or txtGemiddelde = "" Then
MsgBox "eerst Berekenen", vbCritical, "fout"
Else:
lstlijst.AddItem line
txtnaam.Text = ""
txtvoornaam.Text = ""
txtnederlands = ""
txtFrans = ""
txtinformatica = ""
txtwiskunde = ""

End If
End Sub


Private Sub cmdopslaan_Click()
If cdlopensave.FileName = "" Then
cdlopensave.ShowSave
End If

Dim intteller As Integer

Open cdlopensave.FileName For Output As #1

For intteller = 0 To lstlijst.ListCount - 1
Write #1, RTrim(Left(lstlijst.List(intteller), 100))
Next intteller

Close #1
End Sub

Private Sub cmdopenen_Click()
cdlopensave.ShowOpen

Dim strnaam As String
Dim strvoornaam As String
Dim strnederlands As String
Dim strfrans As String
Dim strinformatica As String
Dim strwiskunde As String
Dim strtotaal As String
Dim strgemiddelde As String

Open cdlopensave.FileName For Input As #1

Do While Not EOF(1)
Input #1, strnaam
lstlijst.AddItem Omzetting(strnaam, strvoornaam, strnederlands, strfrans, strwiskunde, strinformatica, strgemiddelde, strtotaal)
Loop

Close #1
End Sub

That's what I got this far. I think the problem is either in the public function or the command to open.

Shane-
20th November 2006, 03:35 AM
Yo Dude

It'd help a little if your code was english? lol



I can't figure out how to make both the OPEN and the ADD LINE to work at the same time
Sounds like your having problems saving the listbox data to file? If so...



Public Sub SaveList(sLocation As String, lstListBox As ListBox)
On Error GoTo dlgerror
Dim sCurrent As String
Dim i As Integer
Open sLocation For Output As #1
i=0
Do Until i=lstListBox.ListCount
sCurrent=lstListBox.List(i)
Print #1, sCurrent
i=i + 1
Loop
Close #1
Exit Sub
dlgerror:
MsgBox "An error has occured " & err.Description
Exit Sub
End Sub

And to load:

Public Sub LoadList(sLocation As String, lstListBox As ListBox)
On Error GoTo dlgerror
Dim sCurrent As String
Dim i As Integer
lstListBox.Clear
Open sLocation For Input As #1
i = 0
Do Until EOF(1)
Line Input #1, sCurrent
lstListBox.AddItem sCurrent, i
i = i + 1
Loop
Close #1
Exit Sub
dlgerror:
MsgBox "An error has occured " & err.Description
Exit Sub
End Sub


Shane

car'a'carn
20th November 2006, 09:04 AM
thanks, i found out what i was doing wrong thanks to you. looks like i forgot the array part :s