View Full Version : Date

03-12-2004, 03:45 PM
Dear Sir,

In VB 6.0.

(a) How can I display the current month and year in the list of combo box (mmmm YYYY). Should I need to use the system date, if yes what is the coding? (Note: I refuse to type-in the current date in the combo list, because it is unable to update the date )

(b)I want to let the user to create the customer code as below:
For Example : 3000/T01
but I don't want let the cursor accross the "/" sign, so that user unable to make any changes for it. How is the coding???

(c) How can I make the new line in the label control?
For example, I have two sentences now, but I want to display its in two line as below:
Version: 1.0
Developed By: ABC Company




03-12-2004, 06:38 PM
(c) I don't know if you can do it by editing the property in the design view, but you could do it easily in code:

Private Sub Form_Load()
lblVersion.Caption = "Version: 1.0" & vbCrLf & "Developed By: ABC Company"
End Sub

(b) Not exactly what you're asking for but I think it's close enough. In the KeyPress event of the textbox you can check if he's going to edit the uneditable part using Instr to get the position of the slash, and comparing it to SelStart, then cancel the keypress by setting the code to 0:

Private Sub txtCode_KeyPress(KeyAscii As Integer)
Dim pos As Integer
pos = InStr(txtCode.Text, "/") ' get '/' position
If txtCode.SelStart > pos Then
KeyAscii = 0 ' cancel this keypress
txtCode.SelStart = pos - 1 ' reset cursor to before the '/'
End If
End Sub

(a) I didn't really understand the question.