Showing posts with label VB6 Sample Program. Show all posts
Showing posts with label VB6 Sample Program. Show all posts

Creating a Function to Convert Numbers into Roman Numerals

Saturday, March 27, 2010 · 3 comments



To create a number of letters we often use roman numerals to indicate the month of making the letter.For example, the letter number is '001/Int/III/2010' where the symbol 'III' indicates that the letter was made in March 2010.

For this we need a function that can convert an integer number from 1 to 12 into roman numerals. In the Visual Basic programming, we can easily create such a function. Well, here we'll show an example program to create such functions, as well as examples of how to use it.

  • First open your VB program and select standard exe form
  • Click the View menu
  • Click the Code menu


  • Write the Visual Basic (VB) program code below

    Function IToR(i As Integer) As String Dim s As String s = "I II III IV V VI VII VIIIIX X XI XII " IToR = Mid(s, (i - 1) * 4 + 1, 4) End Function


  • Click the View menu
  • Click the Object menu
  • Put two label controls, two textboxes and a CommandButton to the form
  • Change the Caption of first label into 'Month'
  • Change the Caption of second label into 'Roman Numeral'
  • Change the name of the first textbox into 'txtMonth'
  • Change the name of the second textbox into 'txtRomNum'
  • Remove texts on the first and second textboxes
  • Change the name of the CommandButton into 'cmdConvert'
  • Change the CommandButton caption into 'Convert'
    So your Screen design will look like the image below:


  • Double click CommandButton 'Convert'
  • Write below Visual Basic (VB) program coding

    Private Sub cmdConvert_Click() txtRomNum.Text = IToR(Val(txtMonth.Text)) End Sub


    Okay, you have completed the program
    Now it's time to test
  • Run your program
  • Type a number such as 8 in the first textbox
  • Click CommandButton 'Convert'
    Consider the results


  • How to Convert Degree from Celcius to Another in VB 6 Programming?

    Thursday, September 3, 2009 · 1 comments

    In this posting I will tell you a simple VB programming tips "How to convert degree / temperature from Celcius to another one", so the base temperature is Celcius. The temperature will be converted into Fahrenheit, Rheamur and Kelvin. As we know that we have three conversion formulas are (in Celcius base):
    Fahrenheit = ( Celcius X 1.8 ) + 32
    Rheamur = Celcius X 0.8
    Kelvin = Celcius + 273.15
    How to apply these three formulas in simple VB6 programming? It's just an easy thing to do! You can do it just with a simple VB program. Please follow below instructions for your tips!

  • Create a VB project for example Project1
  • Create a VB standard form for example Form1
  • Create 5 labels for example Label1, Label2, Label3, Label4, Label5
  • Go to Label1 properties by clicking Label1 object, and then change Label1 Caption into "Degree Conversion", and change Font Size into 14.

  • Go to Label2 properties, and find Label2 Caption and change the value into "Celcius"
  • Go to Label3 properties, and then change Label3 Caption into "Fahrenheit"
  • Go to Label4 properties, and then change Label4 Caption into "Rheamur"
  • Go to Label5 properties, and then change Label5 Caption into "Kelvin"
  • Create 4 text boxes for example Text1, Text2, Text3, Text4
  • Create a command button for example Command1
  • Go to Command1 properties, and change Command1 caption into "Convert"

    So your screen design will look like below image:
    Design Simple VB Program Degree Conversion from Celcius
    Now, let's write the program coding.
    Double click any where in Form1 area to create a Sub Form_Load()
    Write down below program coding in the Sub Form_Load() area

    'to clear text boxes text Text1.Text = "" Text2.Text = "" Text3.Text = "" Text4.Text = ""


    Double click Command1 command button to create a Sub Command1_Click()
    Write down below program coding in the Sub Command1_Click() area

    Text2.Text = Val(Text1.Text) * 1.8 + 32 Text3.Text = Val(Text1.Text) * 0.8 Text4.Text = Val(Text1.Text) + 273.15


    So your program will look like the following list:

    Private Sub Command1_Click() Text2.Text = Val(Text1.Text) * 1.8 + 32 Text3.Text = Val(Text1.Text) * 0.8 Text4.Text = Val(Text1.Text) + 273.15 End Sub

    Private Sub Form_Load() 'to clear text boxes text Text1.Text = "" Text2.Text = "" Text3.Text = "" Text4.Text = "" End Sub


    Now, you can test your program by clicking Start button on your VB toolbar to check whether your program is correct or not.
  • Type a number in Text1 for example 15 (in the text box with label "Celcius")
  • Click Command1 command button (with label "Convert")
    If the results are 59 in Text2 (Fahrenheit), 12 in Text3 (Rheamur), and 288.15 in Text4 (Kelvin), it means that your program is correct and running properly.
    Look at below image for your illustration.
    Simple VB Program Degree Conversion from Celcius

    How do you think, it's an easy simple VB programming tips isn't it?





  • How to Convert Degree from Rheamur to Another in VB 6 Programming?

    · 0 comments

    In the previous posting you have learnt a simple VB programming tips "How to convert degree from Fahrenheit into another one in VB6 programming". Now we will learn another simple VB programming tips "How to convert degree / temperature from Rheamur into another one", so the base degree is Rheamur, and will be converted into Celcius, Fahrenheit and Kelvin. We have three previous conversion formulas (Celcius base) as follow:
    Fahrenheit = ( Celcius X 1.8 ) + 32
    Rheamur = Celcius X 0.8
    Kelvin = Celcius + 273.15


    From these formulas, now we can generate new three other formulas (Rheamur base) as the following:
    Celcius = Rheamur / 0.8
    Fahrenheit = ( ( Rheamur / 0.8 ) X 1.8 ) + 32
    Kelvin = ( Rheamur / 0.8 ) + 273.15


    Now, let's implement above formulas into a simple VB6 programming. Let's go on to the following simple VB programming tips!

  • Create a VB project for example Project1
  • Create a VB standard form for example Form1
  • Create 5 labels for example Label1, Label2, Label3, Label4, Label5
  • Go to Label1 properties by clicking Label1 object, and then change Label1 Caption into "Degree Conversion", and change Font Size into 14.
  • Go to Label2 properties, and then change Label2 Caption into "Rheamur"
  • Go to Label3 properties, and then change Label3 Caption into "Celcius"
  • Go to Label4 properties, and then change Label4 Caption into "Fahrenheit"
  • Go to Label5 properties, and then change Label5 Caption into "Kelvin"
  • Create 4 text boxes for example Text1, Text2, Text3, Text4
  • Create a command button for example Command1
  • Go to Command1 properties, and change Command1 caption into "Convert"

    So your screen design should look like below image:
    Screen Design Simple VB6 Program - Degree Conversion from Rheamur

  • Double click anywhere in the Form1 area to create a Sub Form_Load()
  • Write down below program coding in the Sub Form_Load() area
    'to clear the content of text boxes
    Text1.Text = ""
    Text2.Text = ""
    Text3.Text = ""
    Text4.Text = ""

  • Double click the command button with caption "Convert" to create a Sub Command1_Click()
  • Write down below program coding in the Sub Command1_Click() area
    'conversion process
    'Text1 represents Rheamur
    'Text2 represents Celcius
    'Text3 represents Fahrenheit
    'Text4 represents Kelvin
    Text2.Text = Val(Text1.Text) / 0.8
    Text3.Text = ((Val(Text1.Text) / 0.8) * 1.8) + 32
    Text4.Text = (Val(Text1.Text) / 0.8) + 273.15

    So your program will look like below listing:
    Private Sub Command1_Click()
    'conversion process
    'Text1 represents Rheamur
    'Text2 represents Celcius
    'Text3 represents Fahrenheit
    'Text4 represents Kelvin
    Text2.Text = Val(Text1.Text) / 0.8
    Text3.Text = ((Val(Text1.Text) / 0.8) * 1.8) + 32
    Text4.Text = (Val(Text1.Text) / 0.8) + 273.15
    End Sub

    Private Sub Form_Load()
    'to clear the content of text boxes
    Text1.Text = ""
    Text2.Text = ""
    Text3.Text = ""
    Text4.Text = ""
    End Sub

    Ok, your program's finish. Test your program by clicking Start button on your VB toolbar to know whether your program working properly or not.
  • Type a number in Text1 for example 80 (in the text box with label "Rheamur")
  • Click command button with label "Convert"
    If the results are 100 in Text2 (Celcius), 212 in Text3 (Fahrenheit), and 373.15 in Text4 (Kelvin), it means that your program is correct and working properly.
    Look at below image for your illustration.
    Simple Vb Program Degree Conversion From Rheamur

    It is very easy and very simple isn't it? Would you like to try it? Ok, in the next posting I'll write another simple tips with VB6 programming. See you in the next posting!




  • How to Set Object Properties at Run Time in VB6?

    Wednesday, September 2, 2009 · 0 comments

    In the previous posting you have learnt how to set object properties at design time, by clicking the object you want, then change/set the value of property in the properties window. In this posting I'll write how to set/change property value at run time (when program running). And also I'll give you a sample program (code).

    Below is the syntax how to set an object property at run time:
    Object.Property = Expression

    For example:
    Below statement will set Caption of lblName with "John Smith" at run time.
    lblName.Caption = "John Smith"

    However not all object properties can be set their values at run time, because some object properties can be set just at design time. In the next posting maybe I'll write lists of which object properties that can be set just at design time, which ones that can be set just at run time, and which ones that can be set both at design time and run time.


    How to Display Images in a Folder with VB6 Program ?

    Wednesday, August 26, 2009 · 1 comments

    VB6 application to display images in a directory













    In this posting I will write a Sample of Simple VB6 program to display images in a directory of your computer. To display image in VB6 programming you can use LoadPicture statement. The format of statement is:
    LoadPicture (Path\FileName)
    For example:
    LoadPicture ("Image01.jpg") -> display image named Image01.jpg in the current folder (the folder of image and the program is the same)
    LoadPicture ("d:\MyPicture\Image02.bmp") -> display image named Image02.bmp that stored in folder MyPicture in drive d:

    To make a VB6 program application like the above illustration you can follow below VB6 Programming tips.
    In this case assumed that you have some images file (with extention .jpg or .bmp) that stored in directory D:\MyPicture.
    Now you have to create a screen design like below image:
    Screen Design VB6 Program Display Image













    To create the screen design, please follow below steps:

  • Open your Visual Basic software
  • Select a standard exe project, let with default name (Project1 and Form1)
  • Add a label (Label1) control to your form, change its caption into "My Photo Collections", and change font size into 14
  • Add a DriveListBox (Drive1) control to your form
  • Add a Dir DirListBox (Dir1) control to your form
  • Add a FileListBox (File1) control to your form
  • Add an Image (Image1) control to your form
  • Arrange and resize the controls like the above screen design.

    Ok, program interface already done. Now the time to write code statements to functionate the controls, so the program can work.
  • Double-click Drive1 to create a Sub Drive1_Change()
  • Write below Code Statements in the Sub Drive1_Change()
      Dir1.Path = Drive1.Drive
    File1.Path = Dir1.Path

  • Double-click Dir1 to create a Sub Dir1_Change()
  • Write below Code Statement in Sub Dir1_Change()
        File1.Path = Dir1.Path

  • Double-click File1 to create a Sub File1_Click()
  • Write the code statements below in the Sub File1_Click()
        On Error GoTo ErrHandle
    Image1.Picture = LoadPicture(File1.Path & "/" & File1.FileName)
    Exit Sub

    ErrHandle:
    MsgBox "Invalid Image display"
    Resume Next

    So your Program coding will look like below listing:
    Private Sub Dir1_Change()
    File1.Path = Dir1.Path
    End Sub

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

    Private Sub File1_Click()
    On Error GoTo ErrHandle
    Image1.Picture = LoadPicture(File1.Path & "/" & File1.FileName)
    Exit Sub

    ErrHandle:
    MsgBox "Invalid Image display"
    Resume Next
    End Sub

    Now the time to test your program, follow below tips:
  • Click Start button on your VB standard toolbar
  • Select Drive D: in the DriveListBox
  • Select folder D:\MyPicture in the DirListBox
  • Select file name you want in FileListBox

    Your program should like the illustration on the top of this posting, however the image you display depend on the image you have and select.


  • Select Case...End Select - VB6 Sample Program Part 2

    Saturday, August 22, 2009 · 0 comments

    This posting is continuation of previous posting "Select Case...End Select - VB6 Sample Program Part 1". In the previous posting you have designed a program interface like below image, and you have saved it.
    Select Case End Select VB6 Sample Program

    Now, let's writing the program coding for the above program design.

  • Double click cmdCalBonus button to create sub cmdCalBonus_Click()
  • Write down below program coding in the cmdCalBonus_Click() area

    Select Case Val(txtSalQty.Text)
    Case 1 To 2
    txtBonus.Text = "2%"
    Case 3, 4
    txtBonus.Text = "3%"
    Case 5 To 6
    txtBonus.Text = "4.5%"
    Case 7 To 8
    txtBonus.Text = "6.5%"
    Case 9
    txtBonus.Text = "10%"
    Case Else
    txtBonus.Text = "15%"
    End Select
    txtBonusAmt.Text = Val(txtSalQty.Text) * Val(txtPriceUnit.Text) * _
    Val(Left(txtBonus.Text, Len(txtBonus.Text) _
    - 1)) / 100

    At the end, your program will look like below listing:

    Private Sub cmdCalBonus_Click()
    Select Case Val(txtSalQty.Text)
    Case 1 To 2
    txtBonus.Text = "2%"
    Case 3, 4
    txtBonus.Text = "3%"
    Case 5 To 6
    txtBonus.Text = "4.5%"
    Case 7 To 8
    txtBonus.Text = "6.5%"
    Case 9
    txtBonus.Text = "10%"
    Case Else
    txtBonus.Text = "15%"
    End Select
    txtBonusAmt.Text = Val(txtSalQty.Text) * Val(txtPriceUnit.Text) * _
    Val(Left(txtBonus.Text, Len(txtBonus.Text) _
    - 1)) / 100
    End Sub

    Let's test your program to check whether it's correct or not.
  • Click Start button on your VB toolbar
  • Type a number (for example 5) on your textbox with label Your Sales Quantity
  • Type a number (for example 100) on your textbox with label Price Unit (USD)
  • And finally click Calculate Bonus button
  • Notice what happen on your program, what's the result?

    According to the Bonus Table if Sales Quantity = 5, so the Bonus Percentage should equal to 4.5%. So the Bonus Amount = 5 X 100 X 4.5 / 100. And the result is 22.5. So your program should like below screenshot.
    Select Case End Select VB6 Sample Program

    Now I'll explain how the program works.
  • When you type 5 in the Your Purchase Quantity, then type 100 in the Price Unit (USD), and click Calculate Bonus button, so the cmdCalBonus_Click() executed.
  • Then this statement "Val(txtSalQty.Text)" will convert text "5" into number 5
  • Then in Select Case.. defined that txtBonus.Text is "4.5%" according to the Sales Quantity => 5
  • Then program executes below statement:
        txtBonusAmt.Text = Val(txtSalQty.Text) * Val(txtPriceUnit.Text) * _
    Val(Left(txtBonus.Text, Len(txtBonus.Text) _
    - 1)) / 100
    Mybe you think that this is a complex statement. But in fact it's just a simple statement.
    Val(txtSalQty.Text) convert text "5" into number 5
    Val(txtPriceUnit.Text) convert text "100" into number 100


    Because txtBonus.Text = "4.5%" (this is a text) so:
    Len(txtBonus.Text) will return 4, and Len(txtBonus.Text) - 1 will return 3
    Left(txtBonus.Text, Len(txtBonus.Text) - 1) equals to Left("4.5%",4-1) will return "4.5"
    Then Val(Left(txtBonus.Text, Len(txtBonus.Text) - 1)) equal to Val("4.5") will return number 4.5


    So the above formula will equal to:
    txtBonusAmt.Text = Val("5")*Val("100")*Val(Left("4.5%",Len("4.5%")-1))/100
    <=> txtBonusAmt.Text = 5 * 100 * 4.5 / 100
    <=> txtBonusAmt.Text = 22.5



  • Select Case End Select - VB6 Sample Program Part 1

    · 0 comments

    VB Select Case Sample Program
    In this posting I'll write a sample of simple VB6 program that using Select Case..End Select control structure. However this program also using several VB6 functions like Val() (to convert text into number so can be calculated), Len() (to get the length of a text) and Left() (to pick up a part from the left side of a text).

    The scenario of the program is as the following:

  • This program is Bonus Calculation (Sales System).
  • Here it is the bonus percentage table:
      Sales Quantity = 1 - 2 -> Bonus = 2%
    Sales Quantity = 3 - 4 -> Bonus = 3%
    Sales Quantity = 5 - 6 -> Bonus = 4.5%
    Sales Quantity = 7 - 8 -> Bonus = 6.5%
    Sales Quantity = 9 -> Bonus = 10%
    Sales Quantity = 10 or more -> Bonus = 15%
  • Bonus Amount = Sales Quantity X Price Unit X Bonus

    The screen design of the program is like below screenshot.
    Secect Case End Select VB6 Sample Program

    Now, let's design the program first (create screen interface).
  • Open your Visual Basic 6 software
  • Select a standard type project
  • Create 5 Labels
  • Create 4 Textboxes
  • Create a Command button
  • Arrange the controls on your Form like the picture above
  • Click first Label (Label1)
  • Rename the caption of Label1 into Bonus calculation
  • Change the font size into 24
  • Change the caption of Label2, Label3, Label4 and Label5 into Your Sales Quantity, Price Unit (USD), Percentage of Bonus, and Amount of Bonus (USD)

  • Click first Textbox (Text1), clear it's Text, and rename into txtSalQty
  • Click second Textbox (Text2), clear it's Text, and rename into txtPriceUnit
  • Click third Textbox (Text3), clear it's Text, and rename into txtBonus
  • Click fourth Textbox (Text4), clear it's Text, and rename into txtBonusAmt
  • Click Command1 button, change the caption into Calculate Bonus, and rename into cmdCalBonus

  • Click anywhere in Form1 area, and rename into frmCalBonus (look at properties window)
  • Click Project1 file (in Project explorer window)
  • Click cell next to (Name) in Properties Window, and change the Name into prjCalBonus

    Look at image above, your screen design should like that.
    Ok, now the time to save your work (your program) in order you can edit it next time (this program will be used in the next posting). Here it is tips to save your VB6 program:
  • Click File menu on your menu bar
  • Click Save Project As... menu
  • On Save File As window, type frmCalBonus on the cell with label File name:
  • Select the folder you want to save in, then click Save button
  • Then on Save Project As window, Type prjBonus on the cell with label File name:
  • Then click Save button

    Note: The extention .vbp and .frm will automatically given by the system.
    Ok, now your program has been saved. You have 2 files in your project: prjBonus.vbp and frmCalBonus.frm and you can close your VB program. I'll continue to write the program coding in the next posting.


  • If...Then...Else...End If Statement in VB6 - Sample Program 1

    Friday, August 14, 2009 · 0 comments

    Visual Basic program application usually use If..Then..Else..End If statement. In this posting I would like to write a sample of simple program in VB6 which use If..Then..Else..End If statement with 2 conditions or more.
    The syntax of the statement is the following:

  • With 2 conditions:

    If Condition-1 Then
    Statement-1
    Else
    Statement-2
    End If


  • With more than 2 conditions:

    If Condition-1 Then
    Statement-1
    Else
    If Condition-2 Then
    Statement-2
    Else
    If Condition-3 Then
    Statement-3
    Else
    Statement-4
    End If
    End If
    End If


    Note: If the conditions are too much it is not effective if using If..Then..Else..End If statement, however it is better using Select Case..End Select statement.
    The scenario of the program is as below:
  • This is a part of Registration Form that accept the Name and Gender information
  • The first data should be filled in is a Name
  • The next data is a gender code
  • The value that can be filled are just M and F (M for Male, and F for Female)
  • If user input another M and F a message appears on screen
  • When user input M for the Gender cell program will automatically display "Male", and when user input F for the Gender a word "Female" will be displayed automatically
  • After both Name and Gender cell filled with valid data, command button "Register" will Enable
  • When user click command button "Register" a greeting will appear on the screen
    Your program coding will look like the folling list:

    Private Sub cmdRegister_Click()
    'recheck data validity
    If txtName.Text = "" Then
    MsgBox "You must fill in the Name first"
    Exit Sub
    End If
    If txtGender.Text = "" Then
    MsgBox "You must fill in the Gender code"
    Exit Sub
    End If
    If txtGender.Text <> "M" And txtGender.Text <> "F" Then
    MsgBox "Just 'M' or 'F' for the Gender code "
    Exit Sub
    End If
    'display greeting
    lblGreeting.Caption = "Welcome " & IIf(txtGender.Text = "M", "Mr. ", "Mrs. ") & _
    Trim(txtName.Text) & ". Thank you for joining our club."
    End Sub

    Private Sub Form_Load()
    lblGender.Caption = ""
    lblGreeting.Caption = ""
    End Sub

    Private Sub txtGender_Change()
    If txtGender.Text <> "M" And txtGender.Text <> "F" Then
    MsgBox "Invalid value, you should fill in 'M' or 'F'"
    Else
    If txtGender.Text = "M" Then
    lblGender.Caption = "Male"
    Else
    lblGender.Caption = "Female"
    End If
    End If

    If txtName.Text <> "" Then
    cmdRegister.Enabled = True
    Else
    cmdRegister.Enabled = False
    End If
    End Sub

    Private Sub txtName_Change()
    If txtName.Text = "" Then
    cmdRegister.Enabled = False
    Else
    If txtGender.Text = "" Then
    cmdRegister.Enabled = False
    Else
    cmdRegister.Enabled = True
    End If
    End If
    End Sub


    Please look at below screen shot as your illustration:
    Sample VB6 Program If Then Else End If


  • If...Then...Else...End If Statement in VB

    Thursday, August 13, 2009 · 0 comments

    If..Then..Else..End If statement is one of conditional statements in Visual Basic 6 Programming. The statement format is as the following:

  • For 2 conditions
    If Condition1 Then
    Statement1
    Else
    Statement2
    End If
    Statement1 will be executed if Condition1 met (the condition1 result is true value), otherwise the Statement2 will be executed.

  • For 3 conditions or more

    If Condition1 Then
    Statement1
    Else
    If Condition2 Then
    Statement2
    Else
    If Condition3 Then
    Statement3
    Else
    Statement4
    End If
    End If
    End If
    If Condition1 met, the Statement1 will be executed, if Condition2 met, the Statement2 will be executed, and so on.
    Note: that Statement1, Statement2 and so on may be a single statement or a block of statements (one or more statements).

    Example implementation on your program as follow:
  • For 2 conditions
    In an examination if the student get mark more than or equal to 6 he/she pass the exam, however if his/her mark is less than 6 he/she fail.
    So the program coding will be like this:
    If Val(txtMark.Text) >= 6 Then
    lblResult.Caption = "PASS"
    Else
    lblResult.Caption = "FAIL"
    End If
    Look at below image for your illustration:
    Sample Program If Then Else End If Statement VB6

  • For 3 conditions or more
    In an examination the mark will be categorized as below conditions:
    Mark = 10 is Excellent
    Mark >= 9 and <10 is Very Good
    Mark >= 8 and < 9 is Good
    Mark < 8 is Poor
    So the program coding will look like below list:
       If Val(txtMark.Text) < 8 Then
    lblCategory.Caption = "POOR"
    Else
    If Val(txtMark.Text) >= 8 And Val(txtMark.Text) < 9 Then
    lblCategory.Caption = "GOOD"
    Else
    If Val(txtMark.Text) >= 9 And Val(txtMark.Text) < 10 Then
    lblCategory.Caption = "VERY GOOD"
    Else
    lblCategory.Caption = "EXCELLENT"
    End If
    End If
    End If
    Look at below image for your illustration:
    Sample VB Program If Then Else End If Statement


  • Temperature Conversion with Multiple Base in VB6

    Friday, August 7, 2009 · 1 comments

    In the earlier posting you have learnt several simple VB programming tips how to convert temperature with basis Celcius, Fahrenheit, Rheamur and Kelvin. In this posting you will learn how to make a simple application to convert temperature with multiple basis with VB6 programming. You can select the temperature basis when the program's running.

    The scenario of this simple application is as follow:

  • You can select the temperature basis when the program's running
  • Once you select a temperature basis the conversion process will occur when a value of temperature is not empty (contains a number)
  • Also when you typing a temperature on the temperature text box conversion process will automatically occurs
  • When you typing a number in temperature box, if the basis is empty, it will be automatically set to "Celcius" as default

    Now, how to built your simple application? Let's go on to the simple VB programming tips.
    First, you have to create a screen design likes below image:

    Temperature Conversion Sample Program with multiple basis

    How to create the screen design? Follow step by step of below instructions:
  • Open your VB program, create a project (Project1) and a standard form (Form1)
  • Create 7 label controls
  • Change the label captions into Temperature Conversion, Temperature, Celcius, Fahrenheit, Rheamur, Kelvin, and Basis
  • Create 5 text box controls
  • Clear the text of each text box
  • Rename the text box 1,2,3,4 and 5 into TxtTem, TxtCel, TxtFah, TxtRhe, and TxtKel
  • Create a combo box
  • Clear the combo box text
  • Rename the combo box into cboBasis
    Ok, the screen design already finished. Now, what's the program coding like?

    Here it is the program coding. Follow the next simple VB programming tips.
  • Double-click anywhere in form1 area to create Sub Procedure Form_Load()
  • Write down below program coding in Sub Procedure Form_Load() area

    'to add items in combo box
    cboBasis.AddItem "Celcius"
    cboBasis.AddItem "Fahrenheit"
    cboBasis.AddItem "Rheamur"
    cboBasis.AddItem "Kelvin"


  • Double-click TxtTemp text box to create a Sub TxtTemp_Change()
  • Write down below program coding in the Sub TxtTemp_Change() area

    'call procedure ConvPro
    ConvPro


  • Double-click cboBasis object
  • In the program editor window select "Click" event from drop-down list to create Sub cboBasis_Click()
  • Write down below program code in the Sub cboBasis_Click() area

    'call procedure ConvPro
    ConvPro


  • In the program editor window click General from drop-down list
  • Write down below program code in (General) - (Declarations) area to create a Sub ConvPro()


    Private Sub ConvPro()
    If TxtTemp.Text = "" Then
    'clear the text of text boxes
    TxtCel.Text = ""
    TxtFah.Text = ""
    TxtRhe.Text = ""
    TxtKel.Text = ""
    Exit Sub
    End If

    'if Basis is blank then fill in with "Celcius" as default
    If cboBasis.Text = "" Then
    cboBasis.Text = "Celcius"
    End If
    Select Case cboBasis.Text
    Case "Celcius"
    GoTo ConvCel
    Case "Fahrenheit"
    GoTo ConvFah
    Case "Rheamur"
    GoTo ConvRhe
    Case Else
    GoTo ConvKel
    End Select

    'conversion for celcius basis
    ConvCel:
    TxtCel.Text = Val(TxtTemp.Text)
    TxtFah.Text = Val(TxtTemp.Text) * 1.8 + 32
    TxtRhe.Text = Val(TxtTemp.Text) * 0.8
    TxtKel.Text = Val(TxtTemp.Text) + 273.15
    Exit Sub

    'conversion for fahrenheit basis
    ConvFah:
    TxtFah.Text = Val(TxtTemp.Text)
    TxtCel.Text = (Val(TxtTemp.Text) - 32) / 1.8
    TxtRhe.Text = ((Val(TxtTemp.Text) - 32) / 1.8) * 0.8
    TxtKel.Text = ((Val(TxtTemp.Text) - 32) / 1.8) + 273.15
    Exit Sub

    'conversion for rheamur basis
    ConvRhe:
    TxtRhe.Text = Val(TxtTemp.Text)
    TxtCel.Text = Val(TxtTemp.Text) / 0.8
    TxtFah.Text = ((Val(TxtTemp.Text) / 0.8) * 1.8) + 32
    TxtKel.Text = (Val(TxtTemp.Text) / 0.8) + 273.15
    Exit Sub

    'conversion for kelvin basis
    ConvKel:
    TxtKel.Text = Val(TxtTemp.Text)
    TxtCel.Text = Val(TxtTemp.Text) - 273.15
    TxtRhe.Text = (Val(TxtTemp.Text) - 273.15) * 0.8
    TxtFah.Text = ((Val(TxtTemp.Text) - 273.15) * 1.8) + 32
    End Sub


    So your program will look like below listing:

    Private Sub ConvPro()
    If TxtTemp.Text = "" Then
    'clear text of text boxex
    TxtCel.Text = ""
    TxtFah.Text = ""
    TxtRhe.Text = ""
    TxtKel.Text = ""
    Exit Sub
    End If
    'if Basis is blank then fill in with "Celcius"
    If cboBasis.Text = "" Then
    cboBasis.Text = "Celcius"
    End If
    Select Case cboBasis.Text
    Case "Celcius"
    GoTo ConvCel
    Case "Fahrenheit"
    GoTo ConvFah
    Case "Rheamur"
    GoTo ConvRhe
    Case Else
    GoTo ConvKel
    End Select

    'conversion for celcius basis
    ConvCel:
    TxtCel.Text = Val(TxtTemp.Text)
    TxtFah.Text = Val(TxtTemp.Text) * 1.8 + 32
    TxtRhe.Text = Val(TxtTemp.Text) * 0.8
    TxtKel.Text = Val(TxtTemp.Text) + 273.15
    Exit Sub

    'conversion for fahrenheit basis
    ConvFah:
    TxtFah.Text = Val(TxtTemp.Text)
    TxtCel.Text = (Val(TxtTemp.Text) - 32) / 1.8
    TxtRhe.Text = ((Val(TxtTemp.Text) - 32) / 1.8) * 0.8
    TxtKel.Text = ((Val(TxtTemp.Text) - 32) / 1.8) + 273.15
    Exit Sub

    'conversion for rheamur basis
    ConvRhe:
    TxtRhe.Text = Val(TxtTemp.Text)
    TxtCel.Text = Val(TxtTemp.Text) / 0.8
    TxtFah.Text = ((Val(TxtTemp.Text) / 0.8) * 1.8) + 32
    TxtKel.Text = (Val(TxtTemp.Text) / 0.8) + 273.15
    Exit Sub

    'conversion for kelvin basis
    ConvKel:
    TxtKel.Text = Val(TxtTemp.Text)
    TxtCel.Text = Val(TxtTemp.Text) - 273.15
    TxtRhe.Text = (Val(TxtTemp.Text) - 273.15) * 0.8
    TxtFah.Text = ((Val(TxtTemp.Text) - 273.15) * 1.8) + 32

    End Sub



    Private Sub cboBasis_Click()
    'call procedure ConvPro
    ConvPro
    End Sub


    Private Sub Form_Load()
    'to add items in combo box
    cboBasis.AddItem "Celcius"
    cboBasis.AddItem "Fahrenheit"
    cboBasis.AddItem "Rheamur"
    cboBasis.AddItem "Kelvin"
    End Sub


    Private Sub TxtTemp_Change()
    'call procedure ConvPro
    ConvPro
    End Sub


  • Run your program by clicking Start button on your VB Toolbar
  • Type a number in the text box with label Temperature
  • Select and click different Base from the list on the combo box
    What happen? The conversion should automatically occurs, so the results appear on the each text box. Look at below image for your illustration. Your program should look like it.

    Simple VB Program Temperature Conversion with Multiple Basis


  • How to Convert Degree from Kelvin to Another in VB 6 Programming?

    Saturday, August 1, 2009 · 3 comments

    In this posting I will write a simple VB programming tips "How to convert degree from Kelvin into Celcius, Fahrenheit and Rheamur" using VB6 programming. Let's go on to the simple tips.
    We have three previous conversion formulas (Celcius base) as follow in the erlier postings:
    Fahrenheit = ( Celcius X 1.8 ) + 32
    Rheamur = Celcius X 0.8
    Kelvin = Celcius + 273.15


    From previous formulas we got another three formulas with Kelvin degree basis as the following:
    Celcius = Kelvin - 273.15
    Fahrenheit = ( ( Kelvin - 273.15 ) X 1.8 ) + 32
    Rheamur = ( Kelvin - 273.15 ) X 0.8


    Let's implement these formulas in a simple VB6 programming.
    First you should create a screen design like below image (just a simple screen design):
    Design Simple VB6 Program - Degree Conversion


















    How to create this screen design? Follow below instructions for the tips.
  • Open your Visual Basic6 program software
  • Create a project for example Project1
  • Create a standard form for example Form1
  • Create 5 labels for example Label1, Label2, Label3, Label4, Label5
  • Create 4 text boxes for example Text1, Text2, Text3, Text4
  • Click Label1 object so properties of Label1 appears
  • Change its Caption into "Degree Conversion", and change its Font Size into 14
  • Click Label2, and change its Caption into "Kelvin"
  • Like Label2 do with the same way for Label3, Label4, Label5 and change their Captions into "Celius", "Fahrenheit" and "Rheamur"
  • Click Command1, change its Caption into "Convert", and change its Name into "cmdConvert"
  • Click Text1, delete its Text, and change its Name into "txtKelvin"
  • Do with the same way for Text2, Text3, Text4 and change their Names into "txtCelcius", "txtFahrenheit", and "txtRheamur"
  • Double click cmdConvert (the command button with Caption "Convert") to create a Sub cmdConvert_Click()
  • Write down the following program coding in the Sub cmdConvert_Click() area
    'conversion process
    txtCelcius.Text = Val(txtKelvin.Text) - 273.15
    txtRheamur.Text = (Val(txtKelvin.Text) - 273.15) * 0.8
    txtFahrenheit.Text = ((Val(txtKelvin.Text) - 273.15) * 1.8) + 32


    Your program will look like below coding:
    Private Sub cmdConvert_Click()
    'conversion process
    txtCelcius.Text = Val(txtKelvin.Text) - 273.15
    txtRheamur.Text = (Val(txtKelvin.Text) - 273.15) * 0.8
    txtFahrenheit.Text = ((Val(txtKelvin.Text) - 273.15) * 1.8) + 32
    End Sub



    Now the time to test your program.
  • Run your program by clicking Start button on your VB Toolbar
  • Type a number for example 373.15 in "Kelvin" text box
  • Click command Convert
  • Look at the results on Celcius, Fahrenheit and Rheamur text box, they should be 100, 212 and 80

    Look at below image, and your result should look like it.
    Simple VB Program Degree Conversion from Kelvin

    What about your idea? Any comment?


  • How to Convert Degree from Fahrenheit to Another in VB 6 Programming?

    Wednesday, July 29, 2009 · 0 comments

    In the previous posting I've told you a simple VB programming tips "How to convert degree from Celcius into another one". In this posting I'll tell you a tips "How to convert degree from Fahrenheit into another one", so the base degree is Fahrenheit. It will be converted into Celcius, Rheamur and Kelvin. As we know that we have three previous conversion formulas (Celcius base):
    Fahrenheit = ( Celcius X 1.8 ) + 32
    Rheamur = Celcius X 0.8
    Kelvin = Celcius + 273.15


    From above formulas, we are able to generate three other formulas (Fahrenheit base) as below:
    Celcius = ( Fahrenheit - 32 ) / 1.8
    Rheamur = ( ( Fahrenheit - 32 ) / 1.8 ) X 0.8
    Kelvin = ( ( Fahrenheit - 32 ) / 1.8 ) + 273.15


    Now let's implement these formulas in VB6 simple programming. Please follow below steps for your tips!

  • Create a VB project for example Project1
  • Create a VB standard form for example Form1
  • Create 5 labels for example Label1, Label2, Label3, Label4, Label5
  • Go to Label1 properties by clicking Label1 object, and then change Label1 Caption into "Degree Conversion", and change Font Size into 14.
  • Go to Label2 properties, and then change Label2 Caption into "Fahrenheit"
  • Go to Label3 properties, and then change Label3 Caption into "Celcius"
  • Go to Label4 properties, and then change Label4 Caption into "Rheamur"
  • Go to Label5 properties, and then change Label5 Caption into "Kelvin"
  • Create 4 text boxes for example Text1, Text2, Text3, Text4
  • Create a command button for example Command1
  • Go to Command1 properties, and change Command1 caption into "Convert"

    So your design will look like below image (just a simple Screen Design):


    Double click any where in Form1 area to create a Sub Form_Load()
    Write down below program coding in the Sub Form_Load() area

    'to clear the content of text boxes
    Text1.Text = ""
    Text2.Text = ""
    Text3.Text = ""
    Text4.Text = ""


    Double click Command1 command button (with caption "Convert") to create a Sub Command1_Click()
    Write down below program coding in the Sub Command1_Click() area

    'conversion process
    'Text1 represents Fahrenheit
    'Text2 represents Celcius
    'Text3 represents Rheamur
    'Text4 represents Kelvin
    Text2.Text = (Val(Text1.Text) - 32) / 1.8
    Text3.Text = ((Val(Text1.Text) - 32) / 1.8) * 0.8
    Text4.Text = ((Val(Text1.Text) - 32) / 1.8) + 273.15


    So your program should look like below listing:

    Private Sub Command1_Click()
    'conversion process
    'Text1 represents Fahrenheit
    'Text2 represents Celcius
    'Text3 represents Rheamur
    'Text4 represents Kelvin
    Text2.Text = (Val(Text1.Text) - 32) / 1.8
    Text3.Text = ((Val(Text1.Text) - 32) / 1.8) * 0.8
    Text4.Text = ((Val(Text1.Text) - 32) / 1.8) + 273.15
    End Sub


    Private Sub Form_Load()
    'to clear the content of text boxes
    Text1.Text = ""
    Text2.Text = ""
    Text3.Text = ""
    Text4.Text = ""
    End Sub


    Note: In this simple VB program we haven't used variables yet, but we just use controls from Toolbox. Mybe in the next program we will use variables.

    Ok, your program finish. Test your program by clicking Start button on your VB toolbar to know whether your program's working properly or not.
  • Type a number in Text1 for example 212 (in the text box with label "Fahrenheit")
  • Click command button with label "Convert"
    If the results are 100 in Text2 (Celcius), 80 in Text3 (Rheamur), and 373.15 in Text4 (Kelvin), it means that your program is correct and working properly.
    Look at below image for your illustration. Your program should like it.
    A Simple VB Program Degree Conversion from Fahrenheit

    It's an easy simple VB program isn't it? Would you like to try it?


  • Table of Contents

    Saturday, July 25, 2009 · 5 comments




    1. Stop Dreaming Start Action
    2. How to Start Using VB 6 Programming?
    3. How to Save Your VB Program?
    4. What's Visual Basic Development Environment ?
    5. 8 Basic Steps to Create Program in Visual Basic
    6. Visual Basic Toolbox
    7. Form Designer Window in Visual Basic
    8. Visual Basic Properties Window
    9. Project Explorer Window in Visual Basic
    10. Visual Basic Code Editor Window
    11. Visual Basic Standard Toolbar
    12. With..End With Statement to Set Object Properties in VB6
    13. How to Copy an Image or Picture to Clipboard in VB 6 Programming?
    14. How to Convert Numbers into Letters in VB 6 Programming?
    15. How to Automate Conversion Numbers into Letters in VB 6 Programming?
    16. How to Convert Degree from Celcius to Another in VB 6 Programming?
    17. How to Convert Degree from Fahrenheit to Another in VB 6 Programming?
    18. How to Convert Degree from Rheamur to Another in VB 6 Programming?
    19. How to Convert Degree from Kelvin to Another in VB 6 Programming?
    20. Temperature Conversion with Multiple Base in VB6 Programming?
    21. If..Then..Else..End If VB6 Sample Program 1


    How to Automate Conversion Numbers into Letters in VB 6 Programming?

    Wednesday, July 22, 2009 · 0 comments

    How to automate conversion numbers? In the previous posting you have learnt how to convert numbers into letters with Select Case..End Select control structure, If..Then..Else..End If control structure, and command button. The conversion will be processed after you clik command button. In this session you still learn how to convert number into letter with Select Case..End Select and If..Then..Else..End If, however you don't need a command button anymore. The conversion will automatically processed when you typing a number in the text box. How to do this? What's the program like?

    This is just an easy thing to do. You can use the previous program conversion number you have created. You just write down your coding in Sub Text1_Change() and Sub Text2_Change(). This two Subs that make conversion process automatically done. For detail how to do, you can follow below instructions (it's a simple VB programming tips).

    1. Using if..then..else..end if control structure

  • Create a VB project for example Project1
  • Create a VB standard form for example Form1
  • Create a text box for example Text1
  • Create another text box for example Text2
  • Create a label for example Label1
  • Create another label for example Label2
  • Doubleclick Text1 text box to create a Sub Text1_Change()
  • Write down below program coding in the Sub Text1_Change() area

    If Val(Text1.Text) = 0 Then
    Label1.Caption = "zero"
    Else
    If Val(Text1.Text) = 1 Then
    Label1.Caption = "one"
    Else
    If Val(Text1.Text) = 2 Then
    Label1.Caption = "two"
    Else
    If Val(Text1.Text) = 3 Then
    Label1.Caption = "three"
    Else
    If Val(Text1.Text) = 4 Then
    Label1.Caption = "four"
    Else
    If Val(Text1.Text) = 5 Then
    Label1.Caption = "five"
    Else
    If Val(Text1.Text) = 6 Then
    Label1.Caption = "six"
    Else
    If Val(Text1.Text) = 7 Then
    Label1.Caption = "seven"
    Else
    If Val(Text1.Text) = 8 Then
    Label1.Caption = "eight"
    Else
    If Val(Text1.Text) = 9 Then
    Label1.Caption = "nine"
    Else
    If Val(Text1.Text) = 10 Then
    Label1.Caption = "ten"
    Else
    If Val(Text1.Text) = 11 Then
    Label1.Caption = "eleven"
    Else
    If Val(Text1.Text) = 12 Then
    Label1.Caption = "twelve"
    Else
    If Val(Text1.Text) = 13 Then
    Label1.Caption = "thirteen"
    Else
    If Val(Text1.Text) = 14 Then
    Label1.Caption = "forteen"
    Else
    If Val(Text1.Text) = 15 Then
    Label1.Caption = "fifteen"
    Else
    If Val(Text1.Text) = 16 Then
    Label1.Caption = "sixteen"
    Else
    If Val(Text1.Text) = 17 Then
    Label1.Caption = "seventeen"
    Else
    If Val(Text1.Text) = 18 Then
    Label1.Caption = "eighteen"
    Else
    If Val(Text1.Text) = 19 Then
    Label1.Caption = "nineteen"
    Else
    If Val(Text1.Text) = 20 Then
    Label1.Caption = "twenty"
    Else
    Label1.Caption = "unrecognize number"
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If



  • 2. Using Select Case..End Select control structure

  • Doubleclick Text2 text box to create a Sub Text2_Change()
  • Write down below program coding in the Sub Text2_Change() area

    Select Case Val(Text2.Text)
    Case 0
    Label2.Caption = "zero"
    Case 1
    Label2.Caption = "one"
    Case 2
    Label2.Caption = "two"
    Case 3
    Label2.Caption = "three"
    Case 4
    Label2.Caption = "four"
    Case 5
    Label2.Caption = "five"
    Case 6
    Label2.Caption = "six"
    Case 7
    Label2.Caption = "seven"
    Case 8
    Label2.Caption = "eight"
    Case 9
    Label2.Caption = "nine"
    Case 10
    Label2.Caption = "ten"
    Case 11
    Label2.Caption = "eleven"
    Case 12
    Label2.Caption = "twelve"
    Case 13
    Label2.Caption = "thirteen"
    Case 14
    Label2.Caption = "forteen"
    Case 15
    Label2.Caption = "fifteen"
    Case 16
    Label2.Caption = "sixteen"
    Case 17
    Label2.Caption = "seventeen"
    Case 18
    Label2.Caption = "eighteen"
    Case 19
    Label2.Caption = "nineteen"
    Case 20
    Label2.Caption = "twenty"
    Case Else
    Label2.Caption = "unrecognize number"
    End Select



  • You can run your program by clicking Start button on your VB toolbar to check whether your program is correct or not.
  • Type a number in Text1 box for example 15
  • Type a number in Text2 box for example 15

    If letter "fifteen" appears in both Label1 and Label2, it means that your program is correct, and running properly.





  • How to Convert Numbers into Letters in VB 6 Programming?

    Wednesday, July 15, 2009 · 4 comments

    In this posting I will tell you a simple VB programming tips how to convert numbers from 0 until 20 into letters. To the application you can use either If..Then..Else...End If or Select Case..End Select control structure. In this application just demonstrate how to use both control structures. What is the simple program like? Please look at below simple VB programming tips.

    1. Using If..Then..Else..End If control structure

  • Create a VB project for example Project1
  • Create a VB standard form for example Form1
  • Create a command button for example Command1
  • Create another command button for example Command2
  • Create a text box for example Text1
  • Create another text box for example Text2
  • Create a label for example Label1
  • Create another label for example Label2
  • Doubleclick Command1 commandbutton to create a Sub Command1_Click()
  • Write down below simple VB program coding in the Sub Command1_Click() area

    If Val(Text1.Text) = 0 Then
    Label1.Caption = "zero"
    Else
    If Val(Text1.Text) = 1 Then
    Label1.Caption = "one"
    Else
    If Val(Text1.Text) = 2 Then
    Label1.Caption = "two"
    Else
    If Val(Text1.Text) = 3 Then
    Label1.Caption = "three"
    Else
    If Val(Text1.Text) = 4 Then
    Label1.Caption = "four"
    Else
    If Val(Text1.Text) = 5 Then
    Label1.Caption = "five"
    Else
    If Val(Text1.Text) = 6 Then
    Label1.Caption = "six"
    Else
    If Val(Text1.Text) = 7 Then
    Label1.Caption = "seven"
    Else
    If Val(Text1.Text) = 8 Then
    Label1.Caption = "eight"
    Else
    If Val(Text1.Text) = 9 Then
    Label1.Caption = "nine"
    Else
    If Val(Text1.Text) = 10 Then
    Label1.Caption = "ten"
    Else
    If Val(Text1.Text) = 11 Then
    Label1.Caption = "eleven"
    Else
    If Val(Text1.Text) = 12 Then
    Label1.Caption = "twelve"
    Else
    If Val(Text1.Text) = 13 Then
    Label1.Caption = "thirteen"
    Else
    If Val(Text1.Text) = 14 Then
    Label1.Caption = "forteen"
    Else
    If Val(Text1.Text) = 15 Then
    Label1.Caption = "fifteen"
    Else
    If Val(Text1.Text) = 16 Then
    Label1.Caption = "sixteen"
    Else
    If Val(Text1.Text) = 17 Then
    Label1.Caption = "seventeen"
    Else
    If Val(Text1.Text) = 18 Then
    Label1.Caption = "eighteen"
    Else
    If Val(Text1.Text) = 19 Then
    Label1.Caption = "nineteen"
    Else
    If Val(Text1.Text) = 20 Then
    Label1.Caption = "twenty"
    Else
    Label1.Caption = "unrecognize number"
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If


    2. Using select case...end select control structure
  • Doubleclick Command2 command button to create a Sub Command2_Click()
  • Write down below program coding in the Sub Command2_Click() area

    Select Case Val(Text2.Text)
    Case 0
    Label2.Caption = "zero"
    Case 1
    Label2.Caption = "one"
    Case 2
    Label2.Caption = "two"
    Case 3
    Label2.Caption = "three"
    Case 4
    Label2.Caption = "four"
    Case 5
    Label2.Caption = "five"
    Case 6
    Label2.Caption = "six"
    Case 7
    Label2.Caption = "seven"
    Case 8
    Label2.Caption = "eight"
    Case 9
    Label2.Caption = "nine"
    Case 10
    Label2.Caption = "ten"
    Case 11
    Label2.Caption = "eleven"
    Case 12
    Label2.Caption = "twelve"
    Case 13
    Label2.Caption = "thirteen"
    Case 14
    Label2.Caption = "forteen"
    Case 15
    Label2.Caption = "fifteen"
    Case 16
    Label2.Caption = "sixteen"
    Case 17
    Label2.Caption = "seventeen"
    Case 18
    Label2.Caption = "eighteen"
    Case 19
    Label2.Caption = "nineteen"
    Case 20
    Label2.Caption = "twenty"
    Case Else
    Label2.Caption = "unrecognize number"
    End Select


    You can run your program by clicking Start button on your VB toolbar to check whether your program is correct or not.
  • Type a number in Text1 box for example 15
  • Click Command1 commandbutton
  • Type a number in Text2 box for example 15
  • Click Command2 commandbutton
    If letter "fifteen" appears in both Label1 and Label2, it means that your program is correct, and running properly.

    Look at below screen shot for your illustration.
    Sample a Simple VB6 Program Conversion Number to Letter

    What do you think about it? It is an easy simple VB programming tips isn't it? Would you like to try?



  • How to Copy Image or Picture to Clipboard in VB 6 Programming?

    Saturday, July 11, 2009 · 2 comments

    In many VB program applications display images. And maybe you want to copy the image and paste into other office program like MS Excel, MS Word, etc. To do this thing in VB6 programming, please follow below steps of simple VB programming tips:
    First, you should have a picture that will be loaded by the program. For example you have a picture or image file named Adenium.jpg, and you save your picture in a folder with name D:\MyPicture

  • Open your Microsoft VB6 program
  • Create a VB project for example Project1
  • Create a standard form for example Form1
  • Create an image object from the toolbox for example Image1
  • Create a command button for example Command1
    Please look at below screen shot for your illustration.

    How to Copy Image to Clipboard VB Program
  • Double click any where in Form1 area to create a Sub Form_Load()
  • And then type below program coding in the Sub Form_Load() area

    'Load picture into image box
    Image1.Picture = LoadPicture("D:\MyPicture\Adenium.JPG")


  • Double_click Command1 button to create a Sub Command1_Click()
  • Write down below program coding in Sub Command1_Click() area

    'Clear clipboard first
    Clipboard.Clear
    'Load the picture from Image1 into Clipboard
    Clipboard.SetData Image1.Picture


  • So your program will look like the following list:

    Private Sub Command1_Click()
    'Clear clipboard first
    Clipboard.Clear
    'Load the picture from Image1 into Clipboard
    Clipboard.SetData Image1.Picture
    End Sub
    Private Sub Form_Load()
    'Load picture into image box
    Image1.Picture = LoadPicture("D:\MyPicture\Adenium.JPG")
    End Sub


    Please look at below screen shot for your illustration.
    How to Copy Image to Clipboard VB program



    To check whether your program works or not:

  • Click Start panel on your VB design screen
    If your Image appears on your screen it means that your Sub Form_Load() is working.
    How to Copy Image to Clipboard VB Program


  • Click Command1 command button to copy your image into clipboard
  • Open an Office Program like MS Excel
  • Place your pointer in one of MS Excel cell (for example place in cell A1)
  • Right_Click, then click Paste
    If your picture appears on your MS Excel sheet it means that your program is working properly.

  • How to Copy Image to Clipboard VB Program

    How to Copy Image to Clipboard VB Program

    It's just a very easy thing to do, isn't it?


    Archives

    Labels