Solved

MskEditBoxes are interferring with the writing of a random file

Posted on 2001-06-16
17
148 Views
Last Modified: 2010-05-02
My application was writing to the file well until I changed to MaskEditBoxes for around half of the TextBoxes. I first had them with the AllowPrompt set to true, but I could not pull the values back from the file using the find command.
I changed them to false and was then able to retrieve all values for the Text and MaskEdit boxes using the find command.
Now I find that this stops the code writing to the file, I changed them back and I cant write to the file either way now.
I have commented out the MaskEdit code and the code then writes to the file as it should.
I'm somewhat stumpped, as I need to get this part working to deal with the two parts left, of which I have until Tuesday night to finish.
Thankyou for your help
0
Comment
Question by:Ned_Kelly
  • 10
  • 5
  • 2
17 Comments
 
LVL 6

Expert Comment

by:andyclap
Comment Utility
You're not giving much away here - any chance of some source code?
0
 

Author Comment

by:Ned_Kelly
Comment Utility
Sorry,

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 = Len(udtCredit)
                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, intAccNum, udtCredit
            '###Next
            Close #1
        '###End If
 
   

    Call ClearFields
ErrHandler:

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

End Sub

And this is the code for the Clearfields.

Private Sub ClearFields()
    'Clear the form for the next record
    Dim strMask As String
   
    mskAccNum.Mask = ""
    mskAccNum.Text = ""
    mskAccNum.Mask = "###"
    mskBirth.Mask = ""
    mskBirth.Text = ""
    mskBirth.Mask = "##/##/####"
    mskTelNum.Mask = ""
    mskTelNum.Text = ""
    mskTelNum.Mask = "(##) (########)"
    txtLast.Text = ""
    txtFirst.Text = ""
    txtIDNum.Text = ""
    mskBalance.Mask = ""
    mskBalance.Text = ""
    mskBalance.Mask = "#,###.##"

     
End Sub
Thankyou for your help
Ned
0
 

Author Comment

by:Ned_Kelly
Comment Utility
Sorry,

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 = Len(udtCredit)
                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, intAccNum, udtCredit
            '###Next
            Close #1
        '###End If
 
   

    Call ClearFields
ErrHandler:

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

End Sub

And this is the code for the Clearfields.

Private Sub ClearFields()
    'Clear the form for the next record
    Dim strMask As String
   
    mskAccNum.Mask = ""
    mskAccNum.Text = ""
    mskAccNum.Mask = "###"
    mskBirth.Mask = ""
    mskBirth.Text = ""
    mskBirth.Mask = "##/##/####"
    mskTelNum.Mask = ""
    mskTelNum.Text = ""
    mskTelNum.Mask = "(##) (########)"
    txtLast.Text = ""
    txtFirst.Text = ""
    txtIDNum.Text = ""
    mskBalance.Mask = ""
    mskBalance.Text = ""
    mskBalance.Mask = "#,###.##"

     
End Sub

I can write to the file using textboxes but I need to validate the input,
so I have been using MaskeditBoxes.
Thankyou for your help
Ned
0
 

Author Comment

by:Ned_Kelly
Comment Utility
I have commented out what is not neccessary for writing to the file.
0
 
LVL 9

Expert Comment

by:Valliappan AN
Comment Utility
You set the masked edit box's IncludePromptChar to False, and check if it works.

Hope this helps,
Cheers.
0
 
LVL 6

Expert Comment

by:andyclap
Comment Utility
Can you post the declaration of CreditStruc?
It could be that random access files expect each record to be the same length, if you're using variable length strings in the UDT you'll get into problems.
0
 

Author Comment

by:Ned_Kelly
Comment Utility
This is the module,

Option Explicit

    Type CreditStruc
        intAccNum As Integer
        strLast As String * 15
        strFirst As String * 15
        dteBirth As Date
        strTelNum As String * 15
        intIDNum As Integer
        lngBalance As Long
        lngDeposit As Long
        lngWithdrawal As Long
        dteDate As Date

   
    End Type

    Public lngBalance As Long
    Public lngDeposit As Long
    Public lngWithdrawal As Long
    Public dteBirth As Date
    Public strLast As String
    Public strFirst As String
    Public intIDNum As Integer
    Public strTelNum As String
    Public dteDate As Date
    Public intAccNum As Integer


I have been able to fix this problem, by adding code to the cmdEnter and the Clearfields.
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
    Dim intUserResponse As Integer
    Dim intAccNum As Integer ', x As Integer
   
        On Error GoTo ErrHandler

        intAccNum = Val(mskAccNum.Text)
        dlgCom.Filename = strFileName
        strFileName = "A:\Data.dat"
       
        mskAccNum.PromptInclude = True
        mskBirth.PromptInclude = True
        mskTelNum.PromptInclude = True
        mskBalance.PromptInclude = True
   
   
    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 = Len(udtCredit)
                udtCredit.intAccNum = Val(mskAccNum.Text)
                udtCredit.dteBirth = mskBirth.Text
                udtCredit.strLast = txtLast.Text
                udtCredit.strFirst = txtFirst.Text
                udtCredit.lngBalance = Val(mskBalance.Text)
                udtCredit.strTelNum = mskTelNum.Text
                udtCredit.intIDNum = Val(txtIDNum.Text)
                lblDate1.Caption = Date
               
            '###For x = 1 To 30
                Put #1, intAccNum, udtCredit
            '###Next
            Close #1
        End If
 
   

    Call ClearFields
ErrHandler:

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

End Sub


This is the Clearfields

Private Sub ClearFields()
    'Clear the form for the next record
    Dim strMask As String
   
    mskAccNum.Mask = ""
    mskAccNum.Text = ""
    mskAccNum.Mask = "###"
    mskAccNum.PromptInclude = True
    mskBirth.Mask = ""
    mskBirth.Text = ""
    mskBirth.Mask = "##/##/####"
    mskBirth.PromptInclude = True
    mskTelNum.Mask = ""
    mskTelNum.Text = ""
    mskTelNum.Mask = "(##) (########)"
    mskTelNum.PromptInclude = True
    txtLast.Text = ""
    txtFirst.Text = ""
    txtIDNum.Text = ""
    mskBalance.Mask = ""
    mskBalance.Text = ""
    mskBalance.Mask = "#,###.##"
    mskBalance.PromptInclude = True
   

     
End Sub


For some reason it wont find when the PromptInclude is set to True, and it wont write when it is set to False.
The find code is below.

Private Sub cmdFind_Click()
    Const conMsg As String = "Account numbers range from 1 to 30."
    Const conBtns As Integer = vbOKOnly + vbInformation _
                + vbDefaultButton1 + vbApplicationModal
    Dim udtCredit As CreditStruc, intAccNum As Integer, intUserResponse As Integer
    Dim intIDNum As Integer, intIndex As Integer
   
    On Error Resume Next

    'Read record from file
    Open "A:\Data.dat" For Random As #1 Len = Len(udtCredit)

    intAccNum = Val(mskAccNum.Text)
   
        If mskAccNum.Text <> "" Then
            If intAccNum >= 0 And intAccNum <= 30 Then
                Get #1, intAccNum, udtCredit
                    txtLast.Text = Trim(udtCredit.strLast)
                    txtFirst.Text = Trim(udtCredit.strFirst)
                    mskBirth.PromptInclude = False
                    mskBirth.Text = Trim(udtCredit.dteBirth)
                    mskTelNum.PromptInclude = False
                    mskTelNum.Text = Trim(udtCredit.strTelNum)
                    txtIDNum.Text = Trim(udtCredit.intIDNum)
                    mskBalance.PromptInclude = False
                    mskBalance.Text = Trim(udtCredit.lngBalance)
                    lblDate1.Caption = Date
                   
            Else
                intUserResponse = MsgBox(conMsg, conBtns, "Unlimited Credit.")
            End If
        ElseIf txtLast.Text <> "" Then
            For intIndex = 1 To 30
                Get #1, intIndex, udtCredit
                If txtLast.Text = Trim(udtCredit.strLast) Then
                    mskAccNum.PromptInclude = False
                    mskAccNum.Text = Trim(udtCredit.intAccNum)
                    txtLast.Text = Trim(udtCredit.strLast)
                    txtFirst.Text = Trim(udtCredit.strFirst)
                    mskBirth.PromptInclude = False
                    mskBirth.Text = Trim(udtCredit.dteBirth)
                    mskTelNum.PromptInclude = False
                    mskTelNum.Text = Trim(udtCredit.strTelNum)
                    txtIDNum.Text = Trim(udtCredit.intIDNum)
                    mskBalance.PromptInclude = False
                    mskBalance.Text = Trim(udtCredit.lngBalance)
                    lblDate1.Caption = Date
                End If
            Next
        End If

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

Good to hear from you
Thankyou Ned
0
 

Author Comment

by:Ned_Kelly
Comment Utility
Hi folks, seeing as I have sort of fixed it myself, if you could help me fix the problem of when I type an account number in and press find it brings up the record but displays the mskBalance as a single figure instead of the eight spaces that it should. The birth date misses out the zeros and when I change the telephone number and press enter again it does nothing.
I think I need to add something to the code at the end of the cmdFind.
So there are a few that need fixing, I will give the points for any one, two or three that can be fixed.
I know its diverging from the original question, but what am I supposed to do in this situation.
Hope to hear
Ned
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 9

Accepted Solution

by:
Valliappan AN earned 100 total points
Comment Utility
Hi,

Masked Edit controls, get problems like this, though you could make it work, its a bit difficult. Could you use Datepicker control for dates entry and Text boxes for numbers. Its easy to do with them, than Masked Edit control.

To add Datepicker, you should include Windows Common Controls-2 6.0. It is easier to use, you don't need to give the mask and other things. You could just set the date, or set to null, if you set its checkbox property.

For numeric, you need to put some code in Text box, for keypress(for allowing only numeric characters) and some code in Validate event, for formatting the text. Thats it. You could also put some code in Gotfocus event for selecting(highlighting) the text before entering.

If you wish to use so, and have queries, can ask.

Cheers.
0
 

Author Comment

by:Ned_Kelly
Comment Utility
Thanks Valli An, though its a bit late for me now, as I have to hand it in tonight, and its worth 80% of the mark.
He (the Instructor) gave us the ultimatum that it has to work or we fail, so I'm now preparing myself to redo the module as soon as I can, though I haven't give up yet.
Regards Ned

Ps. I will keep your comments for future reference.
0
 
LVL 9

Expert Comment

by:Valliappan AN
Comment Utility
You can try on the following, if it works for you, hope you should find using them easier:

1) Use Formatted text, wherever you wish to get the data from Masked Edit control.
2) Use Clip text, to get it without formatting.
3) Use Format property for changing the display of text in Masked Edit property.

All the best.
0
 

Author Comment

by:Ned_Kelly
Comment Utility
Thanks Valli An, very appreciated.
Ned
0
 
LVL 9

Expert Comment

by:Valliappan AN
Comment Utility
Ned,

Thank you. How about your submitting? you did it?

Cheers.
0
 

Author Comment

by:Ned_Kelly
Comment Utility
I got a reprieve from my instructor, there is a god after all.
I had also misunderstood him somewhat, instead of creating a new file each time I was supposed to create a new record each time, this make s the code somewhat easier.
With the reprieve and the change I should be able to get it done by Sunday and email it to him.
Phew...
Thanks again.
Ned
0
 

Author Comment

by:Ned_Kelly
Comment Utility
Thanks for your guidance in this matter, I have changed the mskBalance box to a text box and am now in the process of coding it to hopefully do what I want.
Ned
0
 
LVL 9

Expert Comment

by:Valliappan AN
Comment Utility
Thats good. Text box is easier to handle.

As I said earlier, you need to validate for numeric keys in keypress event, or a more advanced one, in change event, but that is a difficult one. Anyhow, if you need it, let me know.

Then in validate event, you could format the text in the format you need, with say, the Format function.

In gotfocus event, may be you could put some code like:

Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text) '(or) Text1.Maxlength

or you could alter it as you need.

Do you need, any suggestions, let me know. You can also find these codes/examples, in many web sites.

Thanks for the points.

Cheers.
0
 

Author Comment

by:Ned_Kelly
Comment Utility
Hi Valli An, I have put the following code into the keypress but it still takes letters

Private Sub txtBal_KeyPress(KeyAscii As Integer)
    If KeyAscii >= vbKey0 And KeyAscii <= vbKey9 Then
        txtBal.Text = txtBal.Text & Chr$(KeyAscii)

    End If
   
End Sub

I have tried to validate it  with the code below.

Private Sub txtBal_Validate(Cancel As Boolean)
    Dim KeyAscii() As Integer
    If txtBal.Text >= vbKey0 And txtBal.Text <= vbKey9 Then
        txtBal.Text = KeyAscii(vbKey0 - vbKey9)
    Else
        MsgBox "You can only enter numbers in the balance box."
    End If
       
End Sub

Any help would be appreciated,
thankyou
Ned.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now