フォーマット付き、日付フィールド


  新しいプロジェクト

1) 新しいプロジェクトで、ActiveX コントロールを選択
2) プロジェクトのプロパティで、名前を「LBAxControl」に変更
3) UserControl1 のオブジェクト名を「DateField」に変更
4) 名前をつけてプロジェクトを保存する

  内部コントロールの作成

1) 「TextBox」を貼り付け
2) オブジェクト名を「InputText」に変更
3) 「Text」プロパティをクリア
4) 「Visible」プロパティを 「False」に変更
5) 「MaxLength」プロパティを 「6」に変更

1) 「Label」を貼り付け
2) オブジェクト名を「DspLabel」に変更
3) 「Caption」プロパティをクリア
4) 「BorderStyle」プロパティを「実線」にする

1) DateField と、DspLavel の大きさを InputText に合わせる
2) DspLavelとInputText の位置を (0,0) とする

  テスト用プロジェクト追加

1) プロジェクト(標準 EXE)を追加
2) プロジェクト名を「TEST」とする
3) 追加したプロジェクトに「Form」を追加

  内部コントロール用のコード追加

  

Private Sub InputText_LostFocus()
    
	If Not TextToDateFormat(DspLabel, InputText.Text) Then
		MsgBox ("Date Error")
		InputText.SetFocus
		Exit Sub
	End If
	InputText.Visible = False

End Sub

Private Sub UserControl_GotFocus()
	
	InputText.Visible = True
	InputText.SetFocus

End Sub

Private Sub UserControl_Initialize()
	
	InputText.Width = UserControl.Width
	InputText.Height = UserControl.Height

End Sub

Private Sub UserControl_Resize()
	
	DspLabel.Width = UserControl.Width
	DspLabel.Height = UserControl.Height

End Sub
  

  プロパティ追加

1) 「ツール」「プロシージャの追加」を選択
2) 名前に「Text」と入力して、Property プロシージャを選択
3) 「As Variant」「As String」に変更
4) 以下のコードを追加

  

Public Property Get Text() As String
	
	Text = InputText.Text

End Property
Public Property Let Text(ByVal vNewValue As String)
	
	InputText.Text = NewValue
	Call TextToDateFormat(DspLabel, InputText.Text)

End Property
  

  内部関数追加

1) ユーザーコントロールに、標準モジュールを追加
2) オブジェクト名を「LBAxFunction」に変更
3) 以下のコードを追加

  

Option Explicit
Public Function TextToDateFormat(TargetObj As Label, TargetData As String)

	Dim FieldData As String
	FieldData = Replace(TargetData, " ", "")
	If FieldData = "" Then
		TargetObj.Caption = ""
		TextToDateFormat = True
		Exit Function
	End If
	FieldData = Mid(TargetData, 3, 2) & "/" & Right(TargetData, 2) & "/" & Left(TargetData, 2)
	If Not IsDate(FieldData) Then
		TextToDateFormat = False
		Exit Function
	End If
	TargetObj.Caption = Left(TargetData, 2) & "/" & Mid(TargetData, 3, 2) & "/" & Right(TargetData, 2)
	TextToDateFormat = True

End Function
  

  テスト環境を作る

DataField に「Function プロシージャ」を追加 (本来はActiveX dll(関数ライブラリ) に入れる)

  

Public Function CenterWindow(ScreenObj As Object, FormName As Object)

	FormName.Move (ScreenObj.Width - FormName.Width) / 2, _
			(ScreenObj.Height - FormName.Height) / 2, _
			FormName.Width, _
			FormName.Height

End Function
  

Form1 に以下を追加
  

Private Sub Form_Load()

	DateField1.CenterWindow Screen, Form1

End Sub
  

  実行

1) 「TEST」をスタートアップとして設定する
2) 「Form1」に作成したコントロールを貼り付け、実行する

  保存


1) LBAxControl.ocxの作成
2) 全て保存

レジストリには、「LBAxControl.DateField」として登録される




yahoo  google  MSDN  MSDN(us)  WinFAQ  Win Howto  tohoho  ie_DHTML  vector  wdic  辞書  天気 


[vb]
Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
24/04/20 02:24:18
InfoBoard Version 1.00 : Language=Perl

1 BatchHelper COMprog CommonSpec Cprog CprogBase CprogSAMPLE CprogSTD CprogSTD2 CprogWinsock Cygwin GameScript HTML HTMLcss InstallShield InstallShieldFunc JScript JScriptSAMPLE Jsfuncs LLINK OldProg OracleGold OracleSilver PRO PRObrowser PROc PROconePOINT PROcontrol PROftpclient PROjscript PROmailer PROperl PROperlCHAT PROphp PROphpLesson PROphpLesson2 PROphpLesson3 PROphpfunction PROphpfunctionArray PROphpfunctionMisc PROphpfunctionString PROsql PROvb PROvbFunction PROvbString PROvbdbmtn PROvbonepoint PROwebapp PROwin1POINT PROwinSYSTEM PROwinYOROZU PROwindows ProjectBoard RealPHP ScriptAPP ScriptMaster VBRealtime Vsfuncs a1root access accreq adsi ajax amazon argus asp aspSample aspVarious aspdotnet aw2kinst cappvariety centura ckeyword classStyle cmaterial cmbin cmdbapp cmenum cmlang cmlistbox cmstd cmstdseed cmtxt cs daz3d db dbCommon dbaccess dnettool dos download flex2 flex3 flex4 framemtn framereq freeWorld freesoft gimp ginpro giodownload google hdml home hta htmlDom ie9svg install java javaSwing javascript jetsql jquery jsp jspTest jspVarious lightbox listasp listmsapi listmsie listmsiis listmsnt listmspatch listmsscript listmsvb listmsvc memo ms msde mysql netbeans oraPlsql oracle oracleWiper oraclehelper orafunc other panoramio pear perl personal pgdojo pgdojo_cal pgdojo_holiday pgdojo_idx pgdojo_ref pgdojo_req php phpVarious phpguide plsql postgres ps r205 realC realwebapp regex rgaki ruby rule sboard sc scprint scquest sdb sdbquest seesaa setup sh_Imagick sh_canvas sh_dotnet sh_google sh_tool sh_web shadowbox shgm shjquery shvbs shweb sjscript skadai skywalker smalltech sperl sqlq src systemdoc tcpip tegaki three toolbox twitter typeface usb useXML vb vbdb vbsfunc vbsguide vbsrc vpc wcsignup webanymind webappgen webclass webparts webtool webwsh win8 winofsql wmi work wp youtube