Another question:
I know this sounds pretty easy but how do I write a list to file and also read it.
Edited by N-sane Noob, 10 January 2007 - 09:14 PM.
Posted 10 January 2007 - 09:12 PM
Edited by N-sane Noob, 10 January 2007 - 09:14 PM.
Posted 16 January 2007 - 10:05 PM
If IsNumeric(txtNumber.Text) Then lstNumbers.AddItem txtNumber.Text txtNumber.Text = "" CalculateAverage Else MsgBox "Only numbers are allowed!" End If
Private Sub CalculateAverage() Dim i As Integer Dim averagenum As Double For i = 0 to lstNumbers.ListCount - 1 averagenum = averagenum + CDbl(lstNumbers.List(i)) Next i averagenum = averagenum / lstNumbers.ListCount lblAverage.Caption = "Average Number is: " & averagenum End Sub
Dim i as integer, ff as integer ff=freefile 'get a free file open "c:\list.lst" for output as #ff 'open the file for ouput for i = 0 to lstNumbers.ListCount-1 'from the first to the last in the list print #ff, lstNumbers.List(i) 'write it down next i 'next close #ff 'close the file
Dim ff as integer, aline as string ff=freefile 'get a free file if not dir("c:\list.lst") then exit sub 'if the file does not exist exit the sub open "c:\list.lst" for input as #ff 'open file while not eof(ff) 'while we are not at the end of the file line input #ff, aline 'read a line lstnumbers.additem aline 'add to the list wend 'we can calculate the average now CalculateAverage close #ff 'close file
Posted 16 January 2007 - 10:35 PM
Posted 17 January 2007 - 01:11 PM
Dim strQuestions(10) As String strQuestions(0) = "How much money does Bill Gates have?" strQuestions(1) = "When was the first computer invented?" etc etc...
Dim strQuestions(1 To 10) As StringAnd now we have 10 members starting from 1 to 10.
strQuestions(0) = "How much money does Bill Gates have?"and the other one
strQuestions(1) = "When was the first computer invented?"
ArrayName(MemberIndex) = Value
Private Type TQuestion strQuestion As String strAnswer As String strAnswers(1 To 4) As String End Type Dim arrQuestion(1 To 10) As TQuestion
With arrQuestions(1) .strQuestion = "How much money does Bill Gates have?" .strAnswer = "Noone knows!" .strAnswers(1) = "10 billion dollars" .strAnswers(2) = "20 billion dollars" .strAnswers(3) = "50 billion dollars" .strAnswers(4) = "Noone knows!" End With With arrQuestions(2) .strQuestion = "A question" .strAnswer = "The right answer" .strAnswers(1) = "Wrong answer" .strAnswers(2) = "Wrong answer" .strAnswers(3) = "The right answer" .strAnswers(4) = "Wrong answer" End With
Posted 17 January 2007 - 01:59 PM
Posted 17 January 2007 - 03:08 PM
Edited by EclipsE, 17 January 2007 - 03:09 PM.
Posted 21 January 2007 - 01:13 PM
Posted 21 January 2007 - 04:06 PM
Posted 21 January 2007 - 05:11 PM
Posted 21 January 2007 - 07:57 PM
Posted 21 January 2007 - 08:01 PM
Posted 22 January 2007 - 04:58 AM
Posted 22 January 2007 - 01:18 PM
Posted 22 January 2007 - 03:24 PM
Posted 22 January 2007 - 03:56 PM
Posted 22 January 2007 - 05:43 PM
strQuestion(1) = "What's my creator's display name on p2l?" strAnswers(1, 1) = "Daredevil" strAnswers(1, 2) = "EclipsE" strAnswers(1, 3) = "DaCr00k" strAnswers(1, 4) = "ZeroCool" strAnswerIndex(1) = 2
strQuestion(2) = "My question"
Private strQuestion(1 To 10) As String Private strAnswerIndex(1 To 10) As Integer Private strAnswers(1 To 10, 1 To 4) As String
currentQuestion = Int(Rnd * 11) If currentQuestion < 1 Then currentQuestion = 1 If currentQuestion > 10 Then currentQuestion = 10
currentQuestion = Int(Rnd * (NumberOfQuestions + 1)) If currentQuestion < 1 Then currentQuestion = 1 If currentQuestion > NumberOfQuestions Then currentQuestion = NumberOfQuestions
For i = 1 To 10
For i = 1 To NumberOfQuesions
strAnswers(1, 1) = "Daredevil" strAnswers(1, 2) = "EclipsE" strAnswers(1, 3) = "DaCr00k" strAnswers(1, 4) = "ZeroCool"
strAnswers(numQ, 1) = "answer1" strAnswers(numQ, 2) = "answer2" strAnswers(numQ, 3) = "answer3" strAnswers(numQ, 4) = "answer4"
strAnswerIndex(1) = 2
strAnswerIndex(numQ) = TheRightAnswer
Posted 22 January 2007 - 08:35 PM
If currentQuestion <> 0 Then DoneQuestions = DoneQuestions & "|" & currentQuestion & "|"
If currentQuestion < 1 Then currentQuestion = 1 If currentQuestion > 20 Then currentQuestion = 20
Posted 23 January 2007 - 05:41 AM
If currentQuestion <> 0 Then DoneQuestions = DoneQuestions & "|" & currentQuestion & "|"
If currentQuestion < 1 Then currentQuestion = 1 If currentQuestion > 20 Then currentQuestion = 20
Posted 28 January 2007 - 04:23 PM
0 members, 0 guests, 0 anonymous users