DESPRITE NEED OF A GOOD KILL STATEMENT
Author |
Message |
Judy Nykilchu #1 / 14
|
 DESPRITE NEED OF A GOOD KILL STATEMENT
Something is wrong with my kill statement. Can anyone tell me what I'm doing wrong? Kill App.Path & "\Accounts.dat" Lost in code, Judy
|
Sat, 11 Sep 2004 06:01:52 GMT |
|
 |
Randy Birc #2 / 14
|
 DESPRITE NEED OF A GOOD KILL STATEMENT
What is App.Path? If its a root directory, the \ is added by the system. -- Randy Birch MVP Visual Basic http://www.mvps.org/vbnet/ Please respond only to the newsgroups so all can benefit. *** If you call the Sleep API in Bill's latest, will it have .NET dreams? ***
Quote: > Something is wrong with my kill statement. Can anyone tell me what I'm > doing wrong? > Kill App.Path & "\Accounts.dat" > Lost in code, > Judy
|
Sat, 11 Sep 2004 06:39:40 GMT |
|
 |
Mike William #3 / 14
|
 DESPRITE NEED OF A GOOD KILL STATEMENT
What's the problem? You do know, I take it, that App.Path returns a path that does not have a backslash at the end of it, except when the path is the root directory, in which case it returns the backslash as well. So, wheneverr you use App.Path you should always check the last character. If it is not a backslah then add one. Or is there some other problem you are having with it? Mike
Quote: > Something is wrong with my kill statement. Can anyone tell me what I'm > doing wrong? > Kill App.Path & "\Accounts.dat" > Lost in code, > Judy
|
Sat, 11 Sep 2004 06:40:30 GMT |
|
 |
Michael Carto #4 / 14
|
 DESPRITE NEED OF A GOOD KILL STATEMENT
Quote:
> Something is wrong with my kill statement. Can anyone tell me what I'm > doing wrong? > Kill App.Path & "\Accounts.dat"
Check Right$(App.Path, 1); chances are, it's a \. -- MikeC Please reply to the group.
|
Sat, 11 Sep 2004 07:15:20 GMT |
|
 |
Randy Birc #5 / 14
|
 DESPRITE NEED OF A GOOD KILL STATEMENT
Pass the path portion to this function .. it will assure that the path is properly qualified so you can simply append the file data ... Private Function QualifyPath(sPath As String) As String 'assures that a passed path ends in a slash If Right$(sPath, 1) <> "\" Then QualifyPath = sPath & "\" Else: QualifyPath = sPath End If End Function Call as in: Kill QualifyPath(App.Path) & "Accounts.dat" If App.Path already has a trailing \, its not added. -- Randy Birch MVP Visual Basic http://www.mvps.org/vbnet/ Please respond only to the newsgroups so all can benefit. *** If you call the Sleep API in Bill's latest, will it have .NET dreams? ***
Quote: > Something is wrong with my kill statement. Can anyone tell me what I'm > doing wrong? > Kill App.Path & "\Accounts.dat" > Lost in code, > Judy
|
Sat, 11 Sep 2004 07:30:49 GMT |
|
 |
Joe #6 / 14
|
 DESPRITE NEED OF A GOOD KILL STATEMENT
Quote:
> Something is wrong with my kill statement. Can anyone tell me what I'm > doing wrong? > Kill App.Path & "\Accounts.dat"
What error are you seeing? Maybe you should call SetAttr first: dim victim as string victim = pathify(app.path, "accounts.dat") setattr victim, vbnormal kill victim Here's the source code for Pathify: URL:http://groups.google.com/groups?selm=u5bs8opg0p6n92%40corp.supernews.com -- Joe Foster <mailto:jlfoster%40znet.com> Space Cooties! <http://www.xenu.net/> WARNING: I cannot be held responsible for the above They're coming to because my cats have apparently learned to type. take me away, ha ha!
|
Sat, 11 Sep 2004 07:38:50 GMT |
|
 |
Judy Nykilchu #7 / 14
|
 DESPRITE NEED OF A GOOD KILL STATEMENT
ok I tried taking that dam slash out but now it won't open the file. I tried just taking it out to kill it, then tried taking it out all over the place and the dam thing won't work. sorry for my frustration, if I didn't have a very short time frame to learn this, it would be fun. Thanks for all your help guys, but it still won't work and I don't know enough to even point to another possible problem. only hours left to go, and no sleep in sight. anyone else been here? Judy
Quote: > Something is wrong with my kill statement. Can anyone tell me what I'm > doing wrong? > Kill App.Path & "\Accounts.dat" > Lost in code, > Judy
|
Sat, 11 Sep 2004 07:49:52 GMT |
|
 |
Frank Ad #8 / 14
|
 DESPRITE NEED OF A GOOD KILL STATEMENT
Quote: >Something is wrong with my kill statement. Can anyone tell me what I'm >doing wrong? >Kill App.Path & "\Accounts.dat" >Lost in code,
Firstly, what is the error you're getting ? If your app.path happens to be in the root of drive it'll fail because of this.: app.path being "x:\" "x:\" & "\Accounts.dat" = "x:\\Accounts.dat" If you have the file open, or another process has that file open you'll get an error as well. Regards, Frank
|
Sat, 11 Sep 2004 08:30:12 GMT |
|
 |
Judy Nykilchu #9 / 14
|
 DESPRITE NEED OF A GOOD KILL STATEMENT
I do get an error stating I have to close the file first but I already did that. I change this, I change that and I get different errors. Here's the code I have for that sub, now i"m getting a run time error. Input past end of file Public Sub SaveAccountBalance() Dim intFileHandleInput As Integer 'variable to store file number Dim intFileHandleOutput As Integer 'variable to store file number Dim strAccountNumber As String 'variable to store account number Dim sngChequingAccountBalance As Single 'variable to store chequing account balance Dim sngSavingsAccountBalance As Single 'variable to store savings account balance 'read and write accounts info excepts the account to be updated intFileHandleInput = FreeFile Open App.Path & "\Accounts.dat" For Input As #intFileHandleInput intFileHandleOutput = FreeFile Open App.Path & "\AccountsTemp.dat" For Output As #intFileHandleOutput Do While Not EOF(intFileHandleInput) Input #intFileHandleInput, strAccountNumber, sngChequingAccountBalance, sngSavingsAccountBalance If strAccountNumber <> gstrUserAccountNumber Then Write #intFileHandleOutput, strAccountNumber, sngChequingAccountBalance, sngSavingsAccountBalance End If Loop Close #intFileHandleInput 'update the account Write #intFileHandleOutput, gstrUserAccountNumber, gsngUserChequingAccountBalance, _ gsngUserSavingsAccountBalance Close #intFileHandleOutput 'replace the temp file as original file Kill App.Path & "Accounts.dat" Name App.Path & "AccountsTemp.dat" As App.Path & "Accounts.dat" End Sub
Quote:
> >Something is wrong with my kill statement. Can anyone tell me what I'm > >doing wrong? > >Kill App.Path & "\Accounts.dat" > >Lost in code, > Firstly, what is the error you're getting ? > If your app.path happens to be in the root of drive it'll fail because > of this.: app.path being "x:\" > "x:\" & "\Accounts.dat" = "x:\\Accounts.dat" > If you have the file open, or another process has that file open > you'll get an error as well. > Regards, Frank
|
Sat, 11 Sep 2004 08:46:43 GMT |
|
 |
Mike William #10 / 14
|
 DESPRITE NEED OF A GOOD KILL STATEMENT
The first thing you've got to do, Judy, is to tell us *exactly* why it won't work. If your code is giving you error messages, then tell us what they are, and what line they occur on! I've had a look at the code (that you sent me by email) and it is fairly straightforward code that is supposed to open a standard "flat file" database (a standard text file, really). That file (according to your code) contains a number of separate bank accounts. Each account has an account number (a string of text) and two separate balances (both held as Singles) - a Chequing Account Balance and a Savings Account Balance. The code attempts to read through the entire "flat file" database, looking for a specific account number. It loads the accounts in, one by one, with the line: Input #intFileHandleInput, strAccountNumber, sngChequingAccountBalance, sngSavingsAccountBalance (The above should all be on one line, but Outlook Express will probably break it into two lines) This gives it three variables. The first contains the account number, the seconds contains the Chequing Account Balance and the third contains the Savings Account Balance. It then checks the strAccountNumber variable to see if it is the account it is looking for. If it is not then it writes those three itens out to a temporary file. It repeats this process for each account in the file. Eventually, it will have read every account in the existing file and copied that exact data into a temporary file, except for the account it was looking for (whether it found it or not) which it hasn't written out at all. Then, at the end of the loop, it writes out the details for that account. The file that it is reading would look something like this (the example contains three accounts): "ZQW-430-1135", 999.99, 345.85 "HJK-666-2345", 127.99, 2376.56 "PXJ-570-3357", 123.45, 48.59 This is a silly way of doing things, but what the hell - it seems to be what your teacher is teaching you! I've tried your code, and providing I set up three public variables (gstrUserAccountNumber, gsngUserChequingAccountBalance and gsngUserSavingsAccountBalance) before I call your routine then it works fine. Are you sure that you are declaring those three variables somewhere? There will be a problem, of course, if your app.path happens to be in the root directory (as I and other have already mentioned), but you can write code to check for the backslash. Here is your own code, amended for the "backslash" stuff. It works fine (provided that the three public variables that I mentioned are declared somewhere): Public Sub SaveAccountBalance() Dim intFileHandleInput As Integer 'file Number Dim intFileHandleOutput As Integer 'file Number Dim strAccountNumber As String 'account Number Dim sngChequingAccountBalance As Single 'chequing balance Dim sngSavingsAccountBalance As Single 'savings balance intFileHandleInput = FreeFile Dim s1 As String s1 = App.Path If Right(s1, 1) <> "\" Then s1 = s1 + "\" Open s1 & "Accounts.dat" For Input As #intFileHandleInput intFileHandleOutput = FreeFile Open App.Path & "\AccountsTemp.dat" _ For Output As #intFileHandleOutput Do While Not EOF(intFileHandleInput) Input #intFileHandleInput, strAccountNumber, _ sngChequingAccountBalance, sngSavingsAccountBalance If strAccountNumber <> gstrUserAccountNumber Then Write #intFileHandleOutput, strAccountNumber, _ sngChequingAccountBalance, sngSavingsAccountBalance End If Loop Close #intFileHandleInput 'update the account Write #intFileHandleOutput, gstrUserAccountNumber, _ gsngUserChequingAccountBalance, _ gsngUserSavingsAccountBalance Close #intFileHandleOutput 'replace the temp file as original file Kill s1 & "Accounts.dat" Name s1 & "AccountsTemp.dat" As s1 & "Accounts.dat" End Sub Note that I have "split" some of the longer code lines (using a space + underscore) into two or three separate lines, otherwise this silly Outlook Express will break those lines up for me and the code will not run properly. It works fine this end (except that it is a very silly way to do such stuff!) provided that you have some variables declared in your Form (general) (declarations) section (or elsewhere). Something like: Option Explicit Public gstrUserAccountNumber Public gsngUserChequingAccountBalance Public gsngUserSavingsAccountBalance Note that if the above variables are declared in the same Form as the code then they can be declared as Private, but the fact that your "teacher" (for want of a better word!) has prefixed their names by "g" then I imagine he wants them to be Public (Global). Yuck! Mike
|
Sat, 11 Sep 2004 09:08:25 GMT |
|
 |
James Wys #11 / 14
|
 DESPRITE NEED OF A GOOD KILL STATEMENT
You're still being inconsistent with that "\" character! When you open the files, you use Open App.Path & "\Accounts.dat" When you try to kill it, you are using Kill App.Path & "Accounts.dat" Consistency is the name of the game!
Quote: > I do get an error stating I have to close the file first but I already did > that. > I change this, I change that and I get different errors. > Here's the code I have for that sub, now i"m getting a run time error. > Input past end of file > Public Sub SaveAccountBalance() > Dim intFileHandleInput As Integer 'variable to store file > number > Dim intFileHandleOutput As Integer 'variable to store file > number > Dim strAccountNumber As String 'variable to store account > number > Dim sngChequingAccountBalance As Single 'variable to store chequing > account balance > Dim sngSavingsAccountBalance As Single 'variable to store savings > account balance > 'read and write accounts info excepts the account to be updated > intFileHandleInput = FreeFile > Open App.Path & "\Accounts.dat" For Input As #intFileHandleInput > intFileHandleOutput = FreeFile > Open App.Path & "\AccountsTemp.dat" For Output As #intFileHandleOutput > Do While Not EOF(intFileHandleInput) > Input #intFileHandleInput, strAccountNumber, > sngChequingAccountBalance, sngSavingsAccountBalance > If strAccountNumber <> gstrUserAccountNumber Then > Write #intFileHandleOutput, strAccountNumber, > sngChequingAccountBalance, sngSavingsAccountBalance > End If > Loop > Close #intFileHandleInput > 'update the account > Write #intFileHandleOutput, gstrUserAccountNumber, > gsngUserChequingAccountBalance, _ > gsngUserSavingsAccountBalance > Close #intFileHandleOutput > 'replace the temp file as original file > Kill App.Path & "Accounts.dat" > Name App.Path & "AccountsTemp.dat" As App.Path & "Accounts.dat" > End Sub
> > >Something is wrong with my kill statement. Can anyone tell me what I'm > > >doing wrong? > > >Kill App.Path & "\Accounts.dat" > > >Lost in code, > > Firstly, what is the error you're getting ? > > If your app.path happens to be in the root of drive it'll fail because > > of this.: app.path being "x:\" > > "x:\" & "\Accounts.dat" = "x:\\Accounts.dat" > > If you have the file open, or another process has that file open > > you'll get an error as well. > > Regards, Frank
--- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.338 / Virus Database: 189 - Release Date: 14/03/02
|
Sat, 11 Sep 2004 23:45:23 GMT |
|
 |
Frank Ad #12 / 14
|
 DESPRITE NEED OF A GOOD KILL STATEMENT
Quote: > You're still being inconsistent with that "\" character! > When you open the files, you use Open App.Path & "\Accounts.dat" > When you try to kill it, you are using Kill App.Path & "Accounts.dat" > Consistency is the name of the game!
The only thing consistent here is that my {*filter*}y server is losing every second or third post and i'm getting pissed off !! :-/ Judy, i never saw our reply.. but whatever he said :) Since you are reusing the same filename, it may be smart idea to declare a string and assign it to it. That way you can both debug it easier and as the man said, keep it consistent. Quote: > > I change this, I change that and I get different errors.
That happens to most of us. One of my favorite pastimes is actually this.. Private Sub Form_Load() Const DIFFICULTY = 10 ' beginner Me.Show Randomize Timer Dim i As Integer, errNo As Integer Do i = Val(InputBox("Guess the error")) errNo = Int(Rnd * DIFFICULTY) + 1 If errNo = i Then On Error Resume Next Else On Error GoTo 0 End If err.Raise errNo, , "You Lose !" Loop Until i = 0 End Sub The aim of the game is to make it loop twice. ;-) Quote: > > Here's the code I have for that sub, now i"m getting a run time error. > > Input past end of file
You can trap that by placing an "ON ERROR GoTo DONE" just before your read/write loop. And a label "DONE:" just after your loop. See inline for some changes.. as there are some other problems with that code.. The ones quoted are your originall ines. Public Sub SaveAccountBalance() Quote: > > Dim intFileHandleInput As Integer 'variable to store file number > > Dim intFileHandleOutput As Integer 'variable to store file > > number > > Dim strAccountNumber As String 'variable to store account > > number > > Dim sngChequingAccountBalance As Single 'variable to store > chequing > > account balance > > Dim sngSavingsAccountBalance As Single 'variable to store savings > > account balance
'Duck, here comes consistency. :) Dim strInFile As String , strOutFile As String strInFile = App.Path & IIf(Right$(App.Path,1 = "\", "","\") & "Accounts.dat" strOutFile = App.Path & IIf(Right$(App.Path,1 = "\", "","\") & "AccountsTemp.dat" ' That should do it for the proper filenames Quote: > > 'read and write accounts info excepts the account to be updated > > intFileHandleInput = FreeFile
On Error Resume Next ' Just resume for now.. Kill strOutFile ' IF THE TMPFILE EXISTS YOU PROBABLY WANT IT ' KILLED. IF NOT, THEN REMOVE OR REM THIS LINE.. Open App.Path & strFileName For Input As #intFileHandleInput If Err Then ' can't open input.. Dive - dive !! MsgBox( "Invalid Input Path/File name : " & vbCrlf & _ strFilename) Exit Sub End If Quote: > > intFileHandleOutput = FreeFile > > Open App.Path & "\AccountsTemp.dat" For Output As #intFileHandleOutput
If Err Then ' can't open output.. Dive - dive !! Close ' Whoa, close input first. MsgBox( "Invalid Output Path/File name : " & vbCrlf & _ strFilename) Exit Sub End If On Error GoTo DONE ' now we get dirty and specific. Quote: > > Do While Not EOF(intFileHandleInput) > > Input #intFileHandleInput, strAccountNumber, > > sngChequingAccountBalance, sngSavingsAccountBalance > > If strAccountNumber <> gstrUserAccountNumber Then > > Write #intFileHandleOutput, strAccountNumber, > > sngChequingAccountBalance, sngSavingsAccountBalance > > End If > > Loop
DONE : Quote: > > Close #intFileHandleInput > > 'update the account > > Write #intFileHandleOutput, gstrUserAccountNumber, > > gsngUserChequingAccountBalance, _ > > gsngUserSavingsAccountBalance > > Close #intFileHandleOutput > > 'replace the temp file as original file
Kill strInFile Name strOutFile As strInFile Quote: It may be an idea to copy to my email any follow up posts as i don't usually spend too much time searching on Google, although i may have to start doing just that.. :-/ Brass knuckles..check, big stick..check, clue..check, suppository inserting stick.. check . I think i have all i need to talk some sense into that snotty IT kid (read: helpdesk "professional"), who told me that there is no problem detected on their side and i should check my settings. ;-) Regards, Frank
|
Mon, 13 Sep 2004 01:01:55 GMT |
|
 |
Frank Ad #13 / 14
|
 DESPRITE NEED OF A GOOD KILL STATEMENT
Dammit. Quote: > Open App.Path & strFileName For Input As #intFileHandleInput
This should be Open strInFile etc... Quote: > If Err Then ' can't open input.. Dive - dive !! > MsgBox( "Invalid Input Path/File name : " & vbCrlf & _ >strFilename) > Exit Sub > End If >> > intFileHandleOutput = FreeFile >> > Open App.Path & "\AccountsTemp.dat" For Output As #intFileHandleOutput
And here it should be Open strOutFile etc.. . Quote: > If Err Then ' can't open output.. Dive - dive !! > Close ' Whoa, close input first. > MsgBox( "Invalid Output Path/File name : " & vbCrlf & _ >strFilename) > Exit Sub
Regards, Frank
|
Mon, 13 Sep 2004 01:06:32 GMT |
|
 |
Terry Austi #14 / 14
|
 DESPRITE NEED OF A GOOD KILL STATEMENT
Quote: > The only thing consistent here is that my {*filter*}y server is > losing every second or third post and i'm getting pissed off !! :-/
www.newsguy.com Terry Austin
|
Mon, 13 Sep 2004 02:55:46 GMT |
|
|
|