Monday, October 20, 2008

Sorting in ListView VB6

I have 2 line of codes in sorting a listview.


Try to add this codes to your listview_columnclick

listview1.sortkey = columnheader.index - 1
lstview1.sorted = true

Sunday, August 31, 2008

Populate ListView from SQL Server

Hello to all.

Today my sample is all above listview. Populate listview of data from database.

If you have ur connectionstring and recordset. Then set 1 listview and 1 commandbutton.

In your command button insert this code:

Dim Item as ListItem 'variable for your subitems

ListView1.ListItems.Clear 'Clear your Listview before loading a new data

While Not rs.eof

Set Item = ListView1.ListItems.Add(,,rs!One)
Item.Subitems(1) = rs!Two
rs.movenext

Wend

Hope this one will help you

Thursday, August 21, 2008

Numeric only in Textbox

I have function code here. To restrict the input in textbox only for numeric.

Public Function OnlyNumericKeys(KeyAscii As Integer, TextBox As control) As Integer

Select Case KeyAscii
Case 8, 48 To 57, 46 And InStr(TextBox, ".") = 0
Case 45 And InStr(TextBox, "-") = 0

If TextBox.SelStart > 0 Then
KeyAscii = 0
End If
Case Else

KeyAscii = 0

End Select
OnlyNumericKeys = KeyAscii

End Function


Thanks for the help of my friend (mike).

Removing Maximize Button

Hello there.

This API Codes will help you to remove the maximize button in form.

Public Declare Function GetWindowLong Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long

Public Declare Function SetWindowLong Lib "user32" Alias _
"SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long

Public Const GWL_STYLE = (-16)
Public Const WS_MAXIMIZEBOX = &H10000
Public Const WS_MINIMIZEBOX = &H20000

Hope this one can help.

How to Center a Form

Try this code. Hope it can help.

In your module copy then paste this code:

Public Sub CenterForm(f As Form, w)
f.Left = (w.ScaleWidth - f.Width) / 2
f.Top = (w.ScaleHeight - f.Height) / 2
End Sub

In your Form Load:

Private Sub Form_Load()
CenterForm Me, Main
End Sub

This code will centering your form in mdiparent

User System Login

Hi.

Sample code in System Login. And theres a 3 attempt to log.

Set rs = BASACONN(connstr, "select * from usersettings where username=txtuser and password=txtpassword")

If rs.EOF Then
MsgBox "Invalid Username/Password. Please Try again", vbExclamation, "Invalid"txtusername.SetFocus
txtcount.Text = Val(txtcount.Text) + 1

'''wrong password
If Val(txtcount.Text) > 2 Then
MsgBox "You have 3 Invalid Input of Username/Password. This Program will terminate",vbCritical, "Exit Program"
End
End If
''end

Else

Unload Me
Main.Show

Endif

Monday, June 16, 2008

How to use Drivelistbox, Dirlistbox and Filelistbox

Good Day to my visitor. This sample codes all about Drivelistbox, Dirlistbox and Filelistbox. In this example you will learn on how to use these 3 basic controls in Visual Basic 6.




First Step: Create new project in Visual Basic 6. Then Input a Controls in Form1.
*label1, filename , Drivelistbox, Dirlistbox, and Filelistbox.





Second Step: Write these following codes.

Private Sub DirListBox_Change()
FileListBox.Path = DirListBox.Path
End Sub

Private Sub FileListBox_Click()
filename.Caption = FileListBox.filename
End Sub

Private Sub DriveListBox_Change()
Dim msg As String
Dim result As String

On Error GoTo Error
DirListBox.Path = DriveListBox.Drive
Exit Sub
Error:msg = "Error: " & Err.Number & ": " & Err.Description
result = MsgBox(msg, vbOKCancel + vbExclamation , "No Data")

If result = vbOK Then
Resume
Else
DriveListBox.Drive = DirListBox.Path
Err.Clear
Exit Sub
End If
End Sub