الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

السماح بكتابة الأرقام الbackspace في النموذج

بدأه ALSAHER_9 في 30 نوفمبر 2008 · 1 رد · 556 مشاهدة · في قواعد بيانات Microsoft Access
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

باختصار لدي نموذج يحوي على ارقام فحسب ولايمكن للمستخدم ان يدخل اي حرف به ولكن الكود الذي حصلت عليه يمنع حتى التعديل بزر BACKSPACE او غيرة من ازرار التعديل

فكيف نسمح للمستاخدم بالقيام بالامرين

ادخال الارقام مع امكانية التعديل بطبيعة الحال باستخدام BACKSPCE

هذا الكود يمنع المستخدم من ادخال اي زر في لوحة المفاتيح عدا الأرقام

Private Sub LNobox_KeyPress(KeyAscii As Integer)
If KeyAscii < Asc("0") Or KeyAscii > Asc("9") Then
KeyAscii = 0
End If

End Sub

وحصلت على كود ولكن لم ينجح

اذا كان بالامكان المحاولة في تطبيقة في نموذج بسيط

هذا الكود يفترض به ان يقوم بالواجب ولكن لم استطع من استدعاء الموديل في النموذج رغم البساطة

Public Function LimitUnboundTextBox(KeyAscii As Integer, TextBoxSizeLimit As Integer, Optional InputType As String = "Optional: Default=All Chars or enter A for Alpha Only, I for Integer Only")

'Author: Allan L Taylor
'
'Purpose: To limit the number of characters/digits that can be entered into a unbound textbox and
' allows the selection of the input type ie All Chars, Alpha Only or Integer Only
'
'Version 1
'
'Example usage:-
'
'Private Sub TextBoxName_KeyPress(KeyAscii As Integer)
'
' LimitTextBoxSize KeyAscii, 12 'Alpha Numeric input by default with max length of 12 chars
' LimitTextBoxSize KeyAscii, 4, "A" 'Alpha input only with max length of 4 chars
' LimitTextBoxSize KeyAscii, 8, "I" 'Integer input only with max length of 8 digits
'
'End Sub

Dim cntActiveControl As Control
Dim txtTextBoxContent As String

On Error GoTo ErrorDetected

'Get active control
Set cntActiveControl = Screen.ActiveControl

'Get the control text
txtTextBoxContent = cntActiveControl.Text

'Check for backspace being pressed
If KeyAscii = 8 Then

Exit Function

End If

If InputType = "I" Then 'Integer only

If KeyAscii < 48 Or KeyAscii > 57 Then

MsgBox "Input is restricted to a numeric integer only (values '0 to 9')", vbOKOnly, "User Input Warning"
KeyAscii = 0

Exit Function

End If

ElseIf InputType = "A" Then 'Alha only

If (KeyAscii >= 65 And KeyAscii <= 90) Or (KeyAscii >= 97 And KeyAscii <= 122) Then

'do nothing

Else

MsgBox "Input is restricted to a Alpha chars only (values 'a to z' or 'A to Z')", vbOKOnly, "User Input Warning"
KeyAscii = 0

Exit Function

End If

End If

'Warn user the last possible character has been entered
If Len(txtTextBoxContent) = TextBoxSizeLimit - 1 Then

Beep

End If

'check length is < max limit
If Len(txtTextBoxContent) < TextBoxSizeLimit Then

'Append typed character into the textbox
txtTextBoxContent = Left(txtTextBoxContent, cntActiveControl.SelStart) 'Find text box insertion point
txtTextBoxContent = txtTextBoxContent & Chr$(KeyAscii) 'Add new char/digit
txtTextBoxContent = txtTextBoxContent & Mid(txtTextBoxContent, cntActiveControl.SelStart + 1 + cntActiveControl.SelLength) 'where applicable place remaining text on end of insertion point

Else

MsgBox "Input size is restricted to " & TextBoxSizeLimit & IIf(InputType = "I", " digits", " chars"), vbOKOnly, "User Input Warning"
KeyAscii = 0

End If

Exit Function

ErrorDetected:

MsgBox Err.Number & " - " & Err.Description, vbCritical, "Unexpected Error Occurred, Operation Aborted"

End Function

شكرا جزيلا

وبارك الله فيك

تم تعديل هذه المشاركة بواسطة ALSAHER_9 في 30 نوفمبر 2008 في 20:25

#2

بســم الله الـرحمــن الرحيــم

عليكــم السلام ورحمـة الله وبركاتــه

اقتباس
فكيف نسمح للمستاخدم بالقيام بالامرين

تفضل هذا مربع نص لايقبل الا أرقام مع تشغيل مفتاح BACKSPACE

هذا كوده

Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 8 Then Exit Sub
If KeyAscii < 47 Or KeyAscii > 57 Then KeyAscii = 0
End Sub

موفّق اخي الكريم

Ek_BACKSPACE.rar

تم تعديل هذه المشاركة بواسطة ekseer في 30 نوفمبر 2008 في 22:19

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…