SETHA SITE INFORMATION

  • Increase font size
  • Default font size
  • Decrease font size
Visual Basic / VBA

How to get computer name using Visual Basic 6.0 or VBA?

E-mail Print PDF

The below code use for Visual Basic for Application or Visual Basic 6.0. The function uses to get Computer Name of where this code is running.

Public Function getMachineName() As String
    Dim reVal As String
    reVal = Environ$("computername")
    getMachineName = reVal
End Function
 

Create Table in Microsoft Access From Visual Basic 6.0

E-mail Print PDF

This article shows how to create Table in Microsoft Access from Visual Basic 6.0 programming language. If you still use Visual Basic Programming Language for small project connecting with Database in Microsoft Access then you might need the below code to proceed the creation of Table in Microsoft Access from your own software per se by do not need to open Microsoft Access application as usual.

  1. Assume that we have one MS Access file (a.mdb) in drive C:\ with no Table
  2. Create Visual Basic 6.0 project and connect to the above MS Access file using DAO
  3. (In this example we create one Table named tblTest with four columns)
* Note: Using DAO by set Visual Basic reference (Microsoft DAO 3.6 Object Library)
Dim db as DAO.Database
Dim tbd As DAO.TableDef
set db=OpenDatabase("C:\a.mdb")
Set tbd = db.CreateTableDef("tblTest")
With tbd
  .Fields.Append .CreateField("ID", dbText)
  .Fields.Append .CreateField("Name", dbText)
  .Fields.Append .CreateField("Sex", dbText)
  .Fields.Append .CreateField("DOB", dbDate)
End With
db.TableDefs.Append tbd
 

Find and Replace text in Multiline TextBox Control in Visual Basic 6

E-mail Print PDF

This article shows you how to Find, Find Next and Replace text (including Case Sensitive option) in multiple line TextBox Control in Visual Basic 6. After you click button Find you will see InputBox to enter text you wish to find in TextBox. Then you can click button Find Next or button Replace. The below code is the sub procedure use to Find and Find Next the text in TextBox (txtContent).

Private Sub cmdFindNext_Click()
    txtContent.SetFocus
    If chkCase.Value = 1 Then
        FindText = InStr(PostFind, LCase(txtContent), LCase(TextToFind))
    Else
        FindText = InStr(PostFind, txtContent, TextToFind)
    End If
    If FindText > 0 Then
        txtContent.SelStart = FindText - 1
        txtContent.SelLength = Len(TextToFind)
        cmdReplace.Enabled = True
        PostFind = FindText + 1
    Else
        MsgBox "No text '" & TextToFind & "' any more.", vbExclamation, "Info..."
    End If
End Sub
Download Source Code
 
1) 1st Form

 
2) Text to Find

 
3) Result
 

How to Show Picture in Image Control in Visual Basic 6?

E-mail Print PDF
This article shows you the Visual Basic 6 code on how to view picture in Image Control. Additionally, in this sample you will see how to use FileListBox Control, DirListBox Control and DriveListBox Control.
Private Sub Dir1_Change()
    File1.Path = Dir1.Path
End Sub

Private Sub Drive1_Change()
    Dir1.Path = Drive1.Drive
End Sub

Private Sub File1_Click()
    Dim StrPic As String
    StrPic = File1.Path
    If Right(StrPic, 1) <> "\" Then StrPic = StrPic & "\"
    imgPic = LoadPicture(StrPic & File1.FileName)
End Sub

Download Source Code
 

How to Create Animated Writing Text in Visual Basic 6 using Timer Control?

E-mail Print PDF

This article shows you Visual Basic 6 code to create sample running text (text written) animation using Timer Control. There are three types of direction of the running text: 1) From left to right 2) From right to left and 3) from the middle. Below is the sample in timer procedure block.

Private Sub trmText_Timer()
   If lblCaption.Caption <> StrCap Then
     If lblCaption.Alignment = 0 Then
        'run from left
        lblCaption.Caption = Left(StrCap, Len(lblCaption.Caption) + 1)
     ElseIf lblCaption.Alignment = 1 Then
        'run from right
        lblCaption.Caption = Right(StrCap, Len(lblCaption.Caption) + 1)
     ElseIf lblCaption.Alignment = 2 Then
        'run from the middle
       lblCaption.Caption = Mid(StrCap, Len(StrCap) \ 2 + Len(StrCap) Mod 2 - Num, _
                            2 * (Num + 1) - Len(StrCap) Mod 2)
       Num = Num + 1
     End If
   Else
      lblCaption.Caption = ""
      Num = 0
   End If
End Sub
This is a sample output of running text from Left to Right.

Download Source Code
 
  • «
  •  Start 
  •  Prev 
  •  1 
  •  2 
  •  3 
  •  4 
  •  Next 
  •  End 
  • »


Page 1 of 4