Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

I cant write to the file

Posted on 2001-06-15
7
Medium Priority
?
163 Views
Last Modified: 2010-05-02
Hi folks, my cmdEnter code used to write to the file very well, and then I did some testing and code changing in the application and now it wont write.

Am I losing it or what.

Private Sub cmdEnter_Click()
    Const conMsg As String = "Account numbers range from 1 to 30."
    Const conBtns As Integer = vbOKOnly + vbInformation _
                + vbDefaultButton1 + vbApplicationModal
    Dim udtCredit As CreditStruc
    Dim strFilename As String, i As Integer
    Dim intUserResponse As Integer, recordLength As Long
    Dim intAccNum As Integer, x As Integer
   
        On Error GoTo errHandler

        intAccNum = Val(mskAccNum.Text)
        dlgCom.Filename = strFilename
        strFilename = "A:\Data.dat"
        recordLength = Len(udtCredit)


    If intAccNum < 0 And intAccNum > 30 Then
        intUserResponse = MsgBox(conMsg, conBtns, "Unlimited Credit")
    End If
        If mskAccNum.Text = "" Then
            MsgBox "You must enter an Account Number before saving this Record.", conBtns, "Validation Error"
        Else

            Open "A:\Data.dat" For Random As #1 Len = recordLength
                udtCredit.intAccNum = Val(mskAccNum.Text)
                udtCredit.dteBirth = mskBirth.Text
                udtCredit.strLast = txtLast.Text
                udtCredit.strFirst = txtFirst.Text
                udtCredit.curBalance = Val(mskBalance.Text)
                udtCredit.strTelNum = mskTelNum.Text
                udtCredit.intIDNum = Val(txtIDNum.Text)
                lblDate1.Caption = Date
               
            For x = 1 To 30
                Put #1, udtCredit.intAccNum, udtCredit
            Next
        End If
 
   
    Close #1
    Call ClearFields
errHandler:

        mskAccNum.SelStart = 0
        mskAccNum.SelLength = Len(mskAccNum.Text)
        mskAccNum.SetFocus

End Sub

I have tried commenting out the For Loop and moving it but I cant seem to get it to write.
It will create a new file if I delete the old one but it still wont write to it.
Many thanks for any help.  
0
Comment
Question by:Ned_Kelly
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 150 total points
ID: 6195954
I have seen several issues:
you write Put #1, udtCredit.intAccNum, udtCredit
but defined the file to have recordlength of len(udtCredit)

You have
If mskAccNum.Text = "" Then
  ...
Else
  Open "A:\Data.dat" ...
  ...
End If
Close #1

And it must be  
If mskAccNum.Text = "" Then
  ...
Else
  Open "A:\Data.dat" ...
  ...
  Close #1
End If

Hope this helps

           
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6195967
But why are you writing 30 times to the same account number?

and:

If intAccNum < 0 And intAccNum > 30 Then

will never occur because a number can't be both < 0 and > 30 at the same time.

You do have your old code to compare it against, right?  Post it so we can compare.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6196044
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Ned_Kelly
ID: 6197724
This cmdEnter is from the frmCredit whereas the other question link(angellll) is for the cmdEnter on the frmTrans.
The original code has been overwritten as I resave the floppy to the main drive, it will be a practice that I intend to take up, keeping a copy of the working code.   I cant see the reason why it isn't working though.
I have worked out why it wont write, I changed the AllowPrompt in the properties box for the MaskEditBoxes from true to false.  The reason I did this was so that when I type in an account number and press find it will bring up the acount details.  Before I did the change it would not return the values for the MaskEditBoxes, but it does when you change it to false.
I have a problem

Thanks for your comments and help for a beginner.
Ned
0
 

Author Comment

by:Ned_Kelly
ID: 6198130
Hi, the line

If intAccNum < 0 And intAccNum > 30 Then

is for checking to see if the number falls between 1 and 30 as that is the range of records for the application, as it is a school project only.
If it is out of this range then the msgbox comes into play.
I'm going to accept angellll's answer as I need to ask another question.
Ned
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6203234
"see if the number falls between 1 and 30"

The proper syntax should be
1) <= 0, OR:

If intAccNum <= 0 OR intAccNum > 30 Then
  ' out of range

2) >0, <=30:

If intAccNum > 0 And intAccNum <= 30 Then
   ' in range
else
   ' out of range
end if
0
 

Author Comment

by:Ned_Kelly
ID: 6203314
Yes you are right, I can only go by what we are taught until we can then start to think for ourselves.
My Vb instructor uses the sink or swim method, ie
you go in to class and he starts by taking you through the tutorial, at the same time you are frantically typing to keep up with him, then you are left to fixed any errors of which they are almost always there.
You then go home and start on the project for the week, come back the next week and do it all over again, meanwhile the projects are getting harder.
You do this for ten weeks and that was the end of the first module, of which I passed.
The next six week module was a browser and then the Credit app of which I now ask questions, we have to hand it in so that is works well with no errors or we fail.

It is worth 80% of the module, I fail tomorrow night, But I know I tried my best, so I can only go and practice some more and resit the module.
But I haven't give up yet.

Thanks for you rcomment RspahitZ,
I will adjust my code accordingly thankyou.
Ned
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question