|
-
Aug 28th, 2000, 03:31 AM
#1
Thread Starter
Lively Member
I am going to do a project at school using sequential file to rewrite the file instead of overwrite.
What my code do is trying to wipe out my record and replace with one new variable, and how can i edit which record i like?Example like if i have three record variable,
"cats", "dogs" and "human" in my file.
How can i choose "dogs" to rename as "dogy" instead of wipe out all the data and replace just the new variable dogy?
my code reference:
in module
public names as string*50
public path as string
Private Sub cmdEditName_Click()
Dim edit As CateData
Dim filename As String
Close
path = "a:\budget2\"
filename = "cats.lst"
Open filename For Output As #1
edit.CateName = InputBox("What is the new name of the catergory", "Rename Catergory", lstExisting.List(lstExisting.ListIndex))
If Len(edit) <> 0 Then
Write #1, edit.CateName
'using listbox to show the file data
lstExisting.List(lstExisting.ListIndex) = edit.CateName
End If
cmdEditName.Enabled = False
End Sub
-
Aug 28th, 2000, 04:27 AM
#2
transcendental analytic
What Output does, is just overwriting. You should instead open your file in Random or Binary, which would mean you would have to restructurize your whole file. If you want to do so i could also suggest using user defined types to contain the record data.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 28th, 2000, 06:59 AM
#3
Thread Starter
Lively Member
Restruture file?
Kedaman,
If i don't want to restucture the file mode, and i need to use sequential file mode, can i possible to do it?
coz my teacher want us to do in sequential file.
Can you told me how to do>?Thank you
[Edited by Satangel on 08-28-2000 at 08:08 AM]
-
Aug 28th, 2000, 07:16 AM
#4
transcendental analytic
That depends on the file structure, you would have to post the code the reads this file, documentation on the file contents or the instruction of how the file should be structurized
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 28th, 2000, 07:34 AM
#5
_______
<?>
Code:
'here is an example of how I would change
'the content of a sequential file using an array
Private Sub command1_Click()
Dim sFileName As String
Dim sPath As String
Dim sChangeMe As String
Dim sChangeMeTo As String
'you should use the Freefile function for file numbering
'check it out in msdn
Dim intNum As Integer
intNum = FreeFile
sPath = "C:\"
sFileName = "myfile.txt"
'
'clear the listbox
List1.Clear
'
'variables for the record to change and what to change it to
sChangeMe = InputBox("What is the record to change?", "Rename Item")
sChangeMeTo = InputBox("Enter the new name for your record.", "Item Changed To")
'
'make sure you have input before acting
If sChangeMe <> "" And sChangeMeTo <> "" Then
'
'variables for array and search
Dim myArr() As Variant, myLine As String
Dim iStep As Integer
'open your file and read it into an array
Open sPath & sFileName For Input As intNum
Do While Not EOF(intNum)
iStep = iStep + 1
ReDim Preserve myArr(1 To iStep) As Variant
Line Input #intNum, myLine
myArr(iStep) = myLine
myArr(iStep) = Trim(myArr(iStep))
'add item to listbox
List1.AddItem myArr(iStep)
'once you find what you are looking for change it
If myArr(iStep) = sChangeMe Then
myArr(iStep) = sChangeMeTo
End If
Loop
Close #intNum
'add divider to listbox
List1.AddItem ""
List1.AddItem "_______________"
List1.AddItem ""
'open file for rewrite of info
Open sPath & sFileName For Output As intNum
For iStep = 1 To UBound(myArr)
Print #intNum, myArr(iStep)
'list box is for display
List1.AddItem myArr(iStep)
Next
Close #intNum
Else
MsgBox "You need information please retry!", vbCritical
Exit Sub
End If
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Aug 28th, 2000, 10:59 AM
#6
Try this.
Code:
Private Sub Command1_Click()
'Save contents to a file
Dim Rec1 As String, Rec2 As String, Rec3 As String
Rec1 = "Cat"
Rec2 = "Dog"
Rec3 = "Human"
Open "Test" For Random As #1 Len = 1000
Put #1, 1, Rec1
Put #1, 2, Rec2
Put #1, 3, Rec3
Close #1
End Sub
Private Sub Command2_Click()
'Search for Dog and change it to Doggy
Dim Rec1 As String, Rec2 As String, Rec3 As String
Dim iCount As Integer
Open "C:\Windows\Desktop\Text.txt" For Random As #1 Len = 1000
Do While Not EOF(1)
iCount = iCount + 1
Get #1, iCount, Rec1
If Rec1 = "Dog" Then
Put #1, iCount, "Doggy"
Exit Do
End If
Loop
Close #1
End Sub
When you press Command1, it will save Cat, Dog and Human to a file. When you press Command2, it will search for Dog and change it to doggy.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|