Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 9th, 2005, 3:14 PM   #1
cloud-
Hobbyist Programmer
 
Join Date: Jan 2005
Posts: 110
Rep Power: 4 cloud- is on a distinguished road
Over writing text in a .txt file?

hey, could someone please tell me how i can overwrite the text.
i have some points code and it reads and writes from/to a textfile
i need to make the write function so it finds the old customer id
and points and replaces it with a new one ^^;;

heres the first part that hasnt been tested...cuz obviously i dont have that function xP

feel free to tell me what else is wrong or could be better ^^
Dim cId As Integer
Private Sub Combo12_Change()
  'Customer Id Combo
  Combo12.SetFocus
  cId = Combo12.Text
  Text15.Text = LoadScore(cId)
End Sub
Private Sub Command17_Click()
  'Increase Button
  Text15.SetFocus
  If (cId = "") Then
    MsgBox ("Specify a customer ID first")
    GoTo SubEnd
  ElseIf (Len(cId) > 0) Then
    Dim tScore As String
    tScore = LoadScore(cId)
    Text15.Text = tScore
    If (tScore < 500) Then
      Randomize (Timer)
      Dim Rand1 As String
      Rand1 = Rnd(1) * 5
      Text15.Text = Rand1 + tScore
      WriteScore cId, tScore, Rand1
    ElseIf (tScore < 1000) And (tScore >= 500) Then
      Dim Rand2 As String
      Rand2 = Rnd(1) * 10
      Text15.Text = Rand2 + tScore
      WriteScore cId, tScore, Rand2
    Else
      Dim Rand1 As String
      Rand3 = Rnd(1) * 15
      Text15.Text = Rand3 + tScore
      WriteScore cId, tScore, Rand3
    End If
  End If
SubEnd:
End Sub
Private Sub Command18_Click()
  'Load Button
  If (cId = "") Then
    MsgBox ("Specify a customer ID first")
    GoTo SubEnd
  ElseIf (Len(cId) > 0) Then
    Text15.SetFocus
    Text15 = LoadScore(cId)
  End If
SubEnd:
End Sub
Function LoadScore(CustomerID As Integer) As Integer
  'Function That Returns The Current Score Of The ID Specified
  On Error GoTo ReturnNull
  Dim fFile As Integer
  fFile = FreeFile
  Open "D:\CustomerScore.txt" For Input As #fFile
  Dim Lines As Integer, cLine As Integer, lString As String
  Lines = LOF(fFile)
  cLine = 1
  While (cLine <= Lines)
    Line Input #fFile, lString
    If (lString Like CustomerID & "*") Then
      LoadScore = Replace$(lString, Left$(lString, 3), "", 1, -1, vbTextCompare)
      GoTo FuncEnd
    End If
  Wend
ReturnNull:
  LoadScore = 0
FuncEnd:
End Function

Please help

thanks alot

-
cloud
cloud- is offline   Reply With Quote
Old Apr 13th, 2005, 12:43 PM   #2
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
I think you can just use Print: depending how you've got it set up it will either append or overwrite the data at the current position in the file: there doesn't seem to be any equivalent of line input to overwrite a specific line.

Random access, or binary mode would work, which would be more flexible if a little more complicated (remember to use StrConv(Data, vbUnicode) for the latter)
Rory is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:49 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC