106 lines
3.0 KiB
Plaintext
106 lines
3.0 KiB
Plaintext
' FB 1.05.0 Win64
|
|
|
|
Type ConfigData
|
|
favouriteFruit As String
|
|
needsPeeling As Boolean
|
|
seedsRemoved As Boolean
|
|
numberOfBananas As UInteger
|
|
numberOfStrawberries As UInteger
|
|
End Type
|
|
|
|
Sub updateConfigData(fileName As String, cData As ConfigData)
|
|
Dim fileNum As Integer = FreeFile
|
|
Open fileName For Input As #fileNum
|
|
If err > 0 Then
|
|
Print "File could not be opened"
|
|
Sleep
|
|
End
|
|
End If
|
|
Dim tempFileName As String = "temp_" + fileName
|
|
Dim fileNum2 As Integer = FreeFile
|
|
Open tempFileName For Output As #fileNum2
|
|
Dim As Boolean hadFruit, hadPeeling, hadSeeds, hadBananas, hadStrawberries '' all false by default
|
|
Dim As String ln
|
|
While Not Eof(fileNum)
|
|
Line Input #fileNum, ln
|
|
If ln = "" OrElse Left(ln, 1) = "#" Then
|
|
Print #fileNum2, ln
|
|
Continue While
|
|
End If
|
|
ln = Trim(LTrim(ln, ";"), Any !" \t")
|
|
If ln = "" Then Continue While
|
|
If UCase(Left(ln, 14)) = "FAVOURITEFRUIT" Then
|
|
If hadFruit Then Continue While
|
|
hadFruit = True
|
|
Print #fileNum2, "FAVOURITEFRUIT " + cData.favouriteFruit
|
|
ElseIf UCase(Left(ln, 12)) = "NEEDSPEELING" Then
|
|
If hadPeeling Then Continue While
|
|
hadPeeling = True
|
|
If cData.needsPeeling Then
|
|
Print #fileNum2, "NEEDSPEELING"
|
|
Else
|
|
Print #fileNum2, "; NEEDSPEELING"
|
|
End If
|
|
ElseIf UCase(Left(ln, 12)) = "SEEDSREMOVED" Then
|
|
If hadSeeds Then Continue While
|
|
hadSeeds = True
|
|
If cData.seedsRemoved Then
|
|
Print #fileNum2, "SEEDSREMOVED"
|
|
Else
|
|
Print #fileNum2, "; SEEDSREMOVED"
|
|
End If
|
|
ElseIf UCase(Left(ln, 15)) = "NUMBEROFBANANAS" Then
|
|
If hadBananas Then Continue While
|
|
hadBananas = True
|
|
Print #fileNum2, "NUMBEROFBANANAS " + Str(cData.numberOfBananas)
|
|
ElseIf UCase(Left(ln, 20)) = "NUMBEROFSTRAWBERRIES" Then
|
|
If hadStrawberries Then Continue While
|
|
hadStrawberries = True
|
|
Print #fileNum2, "NUMBEROFSTRAWBERRIES " + Str(cData.numberOfStrawBerries)
|
|
End If
|
|
Wend
|
|
|
|
If Not hadFruit Then
|
|
Print #fileNum2, "FAVOURITEFRUIT " + cData.favouriteFruit
|
|
End If
|
|
If Not hadPeeling Then
|
|
If cData.needsPeeling Then
|
|
Print #fileNum2, "NEEDSPEELING"
|
|
Else
|
|
Print #fileNum2, "; NEEDSPEELING"
|
|
End If
|
|
End If
|
|
If Not hadSeeds Then
|
|
If cData.seedsRemoved Then
|
|
Print #fileNum2, "SEEDSREMOVED"
|
|
Else
|
|
Print #fileNum2, "; SEEDSREMOVED"
|
|
End If
|
|
End If
|
|
If Not hadBananas Then
|
|
Print #fileNum2, "NUMBEROFBANANAS " + Str(cData.numberOfBananas)
|
|
End If
|
|
If Not hadStrawberries Then
|
|
Print #fileNum2, "NUMBEROFSTRAWBERRIES " + Str(cData.numberOfStrawBerries)
|
|
End If
|
|
|
|
Close #fileNum : Close #fileNum2
|
|
Kill(fileName)
|
|
Name (tempFileName fileName)
|
|
End Sub
|
|
|
|
Dim fileName As String = "config2.txt"
|
|
Dim cData As ConfigData
|
|
With cData
|
|
.favouriteFruit = "banana"
|
|
.needsPeeling = False
|
|
.seedsRemoved = True
|
|
.numberOfBananas = 1024
|
|
.numberOfStrawberries = 62000
|
|
End With
|
|
|
|
updateConfigData fileName, cData
|
|
Print
|
|
Print "Press any key to quit"
|
|
Sleep
|